OLD | NEW |
1 /* | 1 /* |
2 * TCP protocol | 2 * TCP protocol |
3 * Copyright (c) 2002 Fabrice Bellard | 3 * Copyright (c) 2002 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 26 matching lines...) Expand all Loading... |
37 struct addrinfo hints, *ai, *cur_ai; | 37 struct addrinfo hints, *ai, *cur_ai; |
38 int port, fd = -1; | 38 int port, fd = -1; |
39 TCPContext *s = NULL; | 39 TCPContext *s = NULL; |
40 fd_set wfds; | 40 fd_set wfds; |
41 int fd_max, ret; | 41 int fd_max, ret; |
42 struct timeval tv; | 42 struct timeval tv; |
43 socklen_t optlen; | 43 socklen_t optlen; |
44 char hostname[1024],proto[1024],path[1024]; | 44 char hostname[1024],proto[1024],path[1024]; |
45 char portstr[10]; | 45 char portstr[10]; |
46 | 46 |
47 if(!ff_network_init()) | 47 ff_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), |
48 return AVERROR(EIO); | |
49 | |
50 url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), | |
51 &port, path, sizeof(path), uri); | 48 &port, path, sizeof(path), uri); |
52 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) | 49 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) |
53 return AVERROR(EINVAL); | 50 return AVERROR(EINVAL); |
54 | 51 |
55 memset(&hints, 0, sizeof(hints)); | 52 memset(&hints, 0, sizeof(hints)); |
56 hints.ai_family = AF_UNSPEC; | 53 hints.ai_family = AF_UNSPEC; |
57 hints.ai_socktype = SOCK_STREAM; | 54 hints.ai_socktype = SOCK_STREAM; |
58 snprintf(portstr, sizeof(portstr), "%d", port); | 55 snprintf(portstr, sizeof(portstr), "%d", port); |
59 if (getaddrinfo(hostname, portstr, &hints, &ai)) | 56 if (getaddrinfo(hostname, portstr, &hints, &ai)) |
60 return AVERROR(EIO); | 57 return AVERROR(EIO); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return -1; | 182 return -1; |
186 } | 183 } |
187 } | 184 } |
188 return size1 - size; | 185 return size1 - size; |
189 } | 186 } |
190 | 187 |
191 static int tcp_close(URLContext *h) | 188 static int tcp_close(URLContext *h) |
192 { | 189 { |
193 TCPContext *s = h->priv_data; | 190 TCPContext *s = h->priv_data; |
194 closesocket(s->fd); | 191 closesocket(s->fd); |
195 ff_network_close(); | |
196 av_free(s); | 192 av_free(s); |
197 return 0; | 193 return 0; |
198 } | 194 } |
199 | 195 |
200 static int tcp_get_file_handle(URLContext *h) | 196 static int tcp_get_file_handle(URLContext *h) |
201 { | 197 { |
202 TCPContext *s = h->priv_data; | 198 TCPContext *s = h->priv_data; |
203 return s->fd; | 199 return s->fd; |
204 } | 200 } |
205 | 201 |
206 URLProtocol tcp_protocol = { | 202 URLProtocol tcp_protocol = { |
207 "tcp", | 203 "tcp", |
208 tcp_open, | 204 tcp_open, |
209 tcp_read, | 205 tcp_read, |
210 tcp_write, | 206 tcp_write, |
211 NULL, /* seek */ | 207 NULL, /* seek */ |
212 tcp_close, | 208 tcp_close, |
213 .url_get_file_handle = tcp_get_file_handle, | 209 .url_get_file_handle = tcp_get_file_handle, |
214 }; | 210 }; |
OLD | NEW |