| @@ -1,60 +1,60 @@ | | | @@ -1,60 +1,60 @@ |
1 | $NetBSD: patch-src_http.c,v 1.5 2016/03/07 19:36:57 nros Exp $ | | 1 | $NetBSD: patch-src_http.c,v 1.6 2018/05/13 09:44:03 maya Exp $ |
2 | | | 2 | |
3 | * Avoid using the obsolete ftime() function. | | 3 | * Avoid using the obsolete ftime() function. |
4 | https://trac.xiph.org/ticket/2014 | | 4 | https://trac.xiph.org/ticket/2014 |
5 | | | 5 | |
6 | * Need sys/filio.h on SunOS for FIONREAD. | | 6 | * Need sys/filio.h on SunOS for FIONREAD. |
7 | | | 7 | |
8 | --- src/http.c.orig 2015-12-31 18:29:53.000000000 +0000 | | 8 | --- src/http.c.orig 2017-08-03 00:27:06.000000000 +0000 |
9 | +++ src/http.c | | 9 | +++ src/http.c |
10 | @@ -14,6 +14,9 @@ | | 10 | @@ -14,6 +14,9 @@ |
11 | #endif | | 11 | #endif |
12 | | | 12 | |
13 | #include "internal.h" | | 13 | #include "internal.h" |
14 | +#ifdef __sun | | 14 | +#ifdef __sun |
15 | +#include <sys/filio.h> | | 15 | +#include <sys/filio.h> |
16 | +#endif | | 16 | +#endif |
17 | #include <ctype.h> | | 17 | #include <ctype.h> |
18 | #include <errno.h> | | 18 | #include <errno.h> |
19 | #include <limits.h> | | 19 | #include <limits.h> |
20 | @@ -347,7 +350,7 @@ typedef int op_sock; | | 20 | @@ -355,7 +358,7 @@ typedef int op_sock; |
21 | # define op_reset_errno() (errno=0) | | 21 | # define op_reset_errno() (errno=0) |
22 | | | 22 | |
23 | # endif | | 23 | # endif |
24 | -# include <sys/timeb.h> | | 24 | -# include <sys/timeb.h> |
25 | +# include <sys/time.h> | | 25 | +# include <sys/time.h> |
26 | # include <openssl/x509v3.h> | | 26 | # include <openssl/x509v3.h> |
27 | | | 27 | |
28 | /*The maximum number of simultaneous connections. | | 28 | /*The maximum number of simultaneous connections. |
29 | @@ -788,7 +791,7 @@ struct OpusHTTPConn{ | | 29 | @@ -799,7 +802,7 @@ struct OpusHTTPConn{ |
30 | /*The next connection in either the LRU or free list.*/ | | 30 | /*The next connection in either the LRU or free list.*/ |
31 | OpusHTTPConn *next; | | 31 | OpusHTTPConn *next; |
32 | /*The last time we blocked for reading from this connection.*/ | | 32 | /*The last time we blocked for reading from this connection.*/ |
33 | - struct timeb read_time; | | 33 | - struct timeb read_time; |
34 | + struct timeval read_time; | | 34 | + struct timeval read_time; |
35 | /*The number of bytes we've read since the last time we blocked.*/ | | 35 | /*The number of bytes we've read since the last time we blocked.*/ |
36 | opus_int64 read_bytes; | | 36 | opus_int64 read_bytes; |
37 | /*The estimated throughput of this connection, in bytes/s.*/ | | 37 | /*The estimated throughput of this connection, in bytes/s.*/ |
38 | @@ -838,7 +841,7 @@ struct OpusHTTPStream{ | | 38 | @@ -849,7 +852,7 @@ struct OpusHTTPStream{ |
39 | struct sockaddr_in6 v6; | | 39 | struct sockaddr_in6 v6; |
40 | } addr; | | 40 | } addr; |
41 | /*The last time we re-resolved the host.*/ | | 41 | /*The last time we re-resolved the host.*/ |
42 | - struct timeb resolve_time; | | 42 | - struct timeb resolve_time; |
43 | + struct timeval resolve_time; | | 43 | + struct timeval resolve_time; |
44 | /*A buffer used to build HTTP requests.*/ | | 44 | /*A buffer used to build HTTP requests.*/ |
45 | OpusStringBuf request; | | 45 | OpusStringBuf request; |
46 | /*A buffer used to build proxy CONNECT requests.*/ | | 46 | /*A buffer used to build proxy CONNECT requests.*/ |
47 | @@ -992,26 +995,26 @@ static int op_http_conn_estimate_availab | | 47 | @@ -1004,26 +1007,26 @@ static int op_http_conn_estimate_availab |
48 | return available; | | 48 | return available; |
49 | } | | 49 | } |
50 | | | 50 | |
51 | -static opus_int32 op_time_diff_ms(const struct timeb *_end, | | 51 | -static opus_int32 op_time_diff_ms(const struct timeb *_end, |
52 | - const struct timeb *_start){ | | 52 | - const struct timeb *_start){ |
53 | +static opus_int32 op_time_diff_ms(const struct timeval *_end, | | 53 | +static opus_int32 op_time_diff_ms(const struct timeval *_end, |
54 | + const struct timeval *_start){ | | 54 | + const struct timeval *_start){ |
55 | opus_int64 dtime; | | 55 | opus_int64 dtime; |
56 | - dtime=_end->time-(opus_int64)_start->time; | | 56 | - dtime=_end->time-(opus_int64)_start->time; |
57 | - OP_ASSERT(_end->millitm<1000); | | 57 | - OP_ASSERT(_end->millitm<1000); |
58 | - OP_ASSERT(_start->millitm<1000); | | 58 | - OP_ASSERT(_start->millitm<1000); |
59 | + dtime=_end->tv_sec-(opus_int64)_start->tv_sec; | | 59 | + dtime=_end->tv_sec-(opus_int64)_start->tv_sec; |
60 | + OP_ASSERT(_end->tv_usec<1000000); | | 60 | + OP_ASSERT(_end->tv_usec<1000000); |
| @@ -69,107 +69,107 @@ https://trac.xiph.org/ticket/2014 | | | @@ -69,107 +69,107 @@ https://trac.xiph.org/ticket/2014 |
69 | static void op_http_conn_read_rate_update(OpusHTTPConn *_conn){ | | 69 | static void op_http_conn_read_rate_update(OpusHTTPConn *_conn){ |
70 | - struct timeb read_time; | | 70 | - struct timeb read_time; |
71 | + struct timeval read_time; | | 71 | + struct timeval read_time; |
72 | opus_int32 read_delta_ms; | | 72 | opus_int32 read_delta_ms; |
73 | opus_int64 read_delta_bytes; | | 73 | opus_int64 read_delta_bytes; |
74 | opus_int64 read_rate; | | 74 | opus_int64 read_rate; |
75 | read_delta_bytes=_conn->read_bytes; | | 75 | read_delta_bytes=_conn->read_bytes; |
76 | if(read_delta_bytes<=0)return; | | 76 | if(read_delta_bytes<=0)return; |
77 | - ftime(&read_time); | | 77 | - ftime(&read_time); |
78 | + gettimeofday(&read_time, NULL); | | 78 | + gettimeofday(&read_time, NULL); |
79 | read_delta_ms=op_time_diff_ms(&read_time,&_conn->read_time); | | 79 | read_delta_ms=op_time_diff_ms(&read_time,&_conn->read_time); |
80 | read_rate=_conn->read_rate; | | 80 | read_rate=_conn->read_rate; |
81 | read_delta_ms=OP_MAX(read_delta_ms,1); | | 81 | read_delta_ms=OP_MAX(read_delta_ms,1); |
82 | @@ -1902,7 +1905,7 @@ static int op_sock_connect_next(op_sock | | 82 | @@ -2015,7 +2018,7 @@ static int op_sock_connect_next(op_sock |
83 | # define OP_NPROTOS (2) | | 83 | # define OP_NPROTOS (2) |
84 | | | 84 | |
85 | static int op_http_connect_impl(OpusHTTPStream *_stream,OpusHTTPConn *_conn, | | 85 | static int op_http_connect_impl(OpusHTTPStream *_stream,OpusHTTPConn *_conn, |
86 | - const struct addrinfo *_addrs,struct timeb *_start_time){ | | 86 | - struct addrinfo *_addrs,struct timeb *_start_time){ |
87 | + const struct addrinfo *_addrs,struct timeval *_start_time){ | | 87 | + struct addrinfo *_addrs,struct timeval *_start_time){ |
88 | const struct addrinfo *addr; | | 88 | struct addrinfo *addr; |
89 | const struct addrinfo *addrs[OP_NPROTOS]; | | 89 | struct addrinfo *addrs[OP_NPROTOS]; |
90 | struct pollfd fds[OP_NPROTOS]; | | 90 | struct pollfd fds[OP_NPROTOS]; |
91 | @@ -1932,7 +1935,7 @@ static int op_http_connect_impl(OpusHTTP | | 91 | @@ -2045,7 +2048,7 @@ static int op_http_connect_impl(OpusHTTP |
92 | _stream->free_head=_conn->next; | | 92 | _stream->free_head=_conn->next; |
93 | _conn->next=_stream->lru_head; | | 93 | _conn->next=_stream->lru_head; |
94 | _stream->lru_head=_conn; | | 94 | _stream->lru_head=_conn; |
95 | - ftime(_start_time); | | 95 | - ftime(_start_time); |
96 | + gettimeofday(_start_time, NULL); | | 96 | + gettimeofday(_start_time, NULL); |
97 | *&_conn->read_time=*_start_time; | | 97 | *&_conn->read_time=*_start_time; |
98 | _conn->read_bytes=0; | | 98 | _conn->read_bytes=0; |
99 | _conn->read_rate=0; | | 99 | _conn->read_rate=0; |
100 | @@ -2034,14 +2037,14 @@ static int op_http_connect_impl(OpusHTTP | | 100 | @@ -2147,14 +2150,14 @@ static int op_http_connect_impl(OpusHTTP |
101 | } | | 101 | } |
102 | | | 102 | |
103 | static int op_http_connect(OpusHTTPStream *_stream,OpusHTTPConn *_conn, | | 103 | static int op_http_connect(OpusHTTPStream *_stream,OpusHTTPConn *_conn, |
104 | - const struct addrinfo *_addrs,struct timeb *_start_time){ | | 104 | - struct addrinfo *_addrs,struct timeb *_start_time){ |
105 | - struct timeb resolve_time; | | 105 | - struct timeb resolve_time; |
106 | + const struct addrinfo *_addrs,struct timeval *_start_time){ | | 106 | + struct addrinfo *_addrs,struct timeval *_start_time){ |
107 | + struct timeval resolve_time; | | 107 | + struct timeval resolve_time; |
108 | struct addrinfo *new_addrs; | | 108 | struct addrinfo *new_addrs; |
109 | int ret; | | 109 | int ret; |
110 | /*Re-resolve the host if we need to (RFC 6555 says we MUST do so | | 110 | /*Re-resolve the host if we need to (RFC 6555 says we MUST do so |
111 | occasionally).*/ | | 111 | occasionally).*/ |
112 | new_addrs=NULL; | | 112 | new_addrs=NULL; |
113 | - ftime(&resolve_time); | | 113 | - ftime(&resolve_time); |
114 | + gettimeofday(&resolve_time, NULL); | | 114 | + gettimeofday(&resolve_time, NULL); |
115 | if(_addrs!=&_stream->addr_info||op_time_diff_ms(&resolve_time, | | 115 | if(_addrs!=&_stream->addr_info||op_time_diff_ms(&resolve_time, |
116 | &_stream->resolve_time)>=OP_RESOLVE_CACHE_TIMEOUT_MS){ | | 116 | &_stream->resolve_time)>=OP_RESOLVE_CACHE_TIMEOUT_MS){ |
117 | new_addrs=op_resolve(_stream->connect_host,_stream->connect_port); | | 117 | new_addrs=op_resolve(_stream->connect_host,_stream->connect_port); |
118 | @@ -2191,8 +2194,8 @@ static int op_http_stream_open(OpusHTTPS | | 118 | @@ -2305,8 +2308,8 @@ static int op_http_stream_open(OpusHTTPS |
119 | addrs=NULL; | | 119 | addrs=NULL; |
120 | for(nredirs=0;nredirs<OP_REDIRECT_LIMIT;nredirs++){ | | 120 | for(nredirs=0;nredirs<OP_REDIRECT_LIMIT;nredirs++){ |
121 | OpusParsedURL next_url; | | 121 | OpusParsedURL next_url; |
122 | - struct timeb start_time; | | 122 | - struct timeb start_time; |
123 | - struct timeb end_time; | | 123 | - struct timeb end_time; |
124 | + struct timeval start_time; | | 124 | + struct timeval start_time; |
125 | + struct timeval end_time; | | 125 | + struct timeval end_time; |
126 | char *next; | | 126 | char *next; |
127 | char *status_code; | | 127 | char *status_code; |
128 | int minor_version_pos; | | 128 | int minor_version_pos; |
129 | @@ -2321,7 +2324,7 @@ static int op_http_stream_open(OpusHTTPS | | 129 | @@ -2440,7 +2443,7 @@ static int op_http_stream_open(OpusHTTPS |
130 | if(OP_UNLIKELY(ret<0))return ret; | | 130 | if(OP_UNLIKELY(ret<0))return ret; |
131 | ret=op_http_conn_read_response(_stream->conns+0,&_stream->response); | | 131 | ret=op_http_conn_read_response(_stream->conns+0,&_stream->response); |
132 | if(OP_UNLIKELY(ret<0))return ret; | | 132 | if(OP_UNLIKELY(ret<0))return ret; |
133 | - ftime(&end_time); | | 133 | - ftime(&end_time); |
134 | + gettimeofday(&end_time, NULL); | | 134 | + gettimeofday(&end_time, NULL); |
135 | next=op_http_parse_status_line(&v1_1_compat,&status_code, | | 135 | next=op_http_parse_status_line(&v1_1_compat,&status_code, |
136 | _stream->response.buf); | | 136 | _stream->response.buf); |
137 | if(OP_UNLIKELY(next==NULL))return OP_FALSE; | | 137 | if(OP_UNLIKELY(next==NULL))return OP_FALSE; |
138 | @@ -2733,8 +2736,8 @@ static int op_http_conn_handle_response( | | 138 | @@ -2852,8 +2855,8 @@ static int op_http_conn_handle_response( |
139 | converted into a request for the rest.*/ | | 139 | converted into a request for the rest.*/ |
140 | static int op_http_conn_open_pos(OpusHTTPStream *_stream, | | 140 | static int op_http_conn_open_pos(OpusHTTPStream *_stream, |
141 | OpusHTTPConn *_conn,opus_int64 _pos,opus_int32 _chunk_size){ | | 141 | OpusHTTPConn *_conn,opus_int64 _pos,opus_int32 _chunk_size){ |
142 | - struct timeb start_time; | | 142 | - struct timeb start_time; |
143 | - struct timeb end_time; | | 143 | - struct timeb end_time; |
144 | + struct timeval start_time; | | 144 | + struct timeval start_time; |
145 | + struct timeval end_time; | | 145 | + struct timeval end_time; |
146 | opus_int32 connect_rate; | | 146 | opus_int32 connect_rate; |
147 | opus_int32 connect_time; | | 147 | opus_int32 connect_time; |
148 | int ret; | | 148 | int ret; |
149 | @@ -2744,7 +2747,7 @@ static int op_http_conn_open_pos(OpusHTT | | 149 | @@ -2863,7 +2866,7 @@ static int op_http_conn_open_pos(OpusHTT |
150 | if(OP_UNLIKELY(ret<0))return ret; | | 150 | if(OP_UNLIKELY(ret<0))return ret; |
151 | ret=op_http_conn_handle_response(_stream,_conn); | | 151 | ret=op_http_conn_handle_response(_stream,_conn); |
152 | if(OP_UNLIKELY(ret!=0))return OP_FALSE; | | 152 | if(OP_UNLIKELY(ret!=0))return OP_FALSE; |
153 | - ftime(&end_time); | | 153 | - ftime(&end_time); |
154 | + gettimeofday(&end_time, NULL); | | 154 | + gettimeofday(&end_time, NULL); |
155 | _stream->cur_conni=_conn-_stream->conns; | | 155 | _stream->cur_conni=(int)(_conn-_stream->conns); |
156 | OP_ASSERT(_stream->cur_conni>=0&&_stream->cur_conni<OP_NCONNS_MAX); | | 156 | OP_ASSERT(_stream->cur_conni>=0&&_stream->cur_conni<OP_NCONNS_MAX); |
157 | /*The connection has been successfully opened. | | 157 | /*The connection has been successfully opened. |
158 | @@ -2996,7 +2999,7 @@ static int op_http_conn_read_ahead(OpusH | | 158 | @@ -3115,7 +3118,7 @@ static int op_http_conn_read_ahead(OpusH |
159 | } | | 159 | } |
160 | | | 160 | |
161 | static int op_http_stream_seek(void *_stream,opus_int64 _offset,int _whence){ | | 161 | static int op_http_stream_seek(void *_stream,opus_int64 _offset,int _whence){ |
162 | - struct timeb seek_time; | | 162 | - struct timeb seek_time; |
163 | + struct timeval seek_time; | | 163 | + struct timeval seek_time; |
164 | OpusHTTPStream *stream; | | 164 | OpusHTTPStream *stream; |
165 | OpusHTTPConn *conn; | | 165 | OpusHTTPConn *conn; |
166 | OpusHTTPConn **pnext; | | 166 | OpusHTTPConn **pnext; |
167 | @@ -3037,7 +3040,7 @@ static int op_http_stream_seek(void *_st | | 167 | @@ -3156,7 +3159,7 @@ static int op_http_stream_seek(void *_st |
168 | op_http_conn_read_rate_update(stream->conns+ci); | | 168 | op_http_conn_read_rate_update(stream->conns+ci); |
169 | *&seek_time=*&stream->conns[ci].read_time; | | 169 | *&seek_time=*&stream->conns[ci].read_time; |
170 | } | | 170 | } |
171 | - else ftime(&seek_time); | | 171 | - else ftime(&seek_time); |
172 | + else gettimeofday(&seek_time, NULL); | | 172 | + else gettimeofday(&seek_time, NULL); |
173 | /*If we seeked past the end of the stream, just disable the active | | 173 | /*If we seeked past the end of the stream, just disable the active |
174 | connection.*/ | | 174 | connection.*/ |
175 | if(pos>=content_length){ | | 175 | if(pos>=content_length){ |