| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), | 48 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), |
| 49 &port, path, sizeof(path), uri); | 49 &port, path, sizeof(path), uri); |
| 50 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) | 50 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) |
| 51 return AVERROR(EINVAL); | 51 return AVERROR(EINVAL); |
| 52 | 52 |
| 53 memset(&hints, 0, sizeof(hints)); | 53 memset(&hints, 0, sizeof(hints)); |
| 54 hints.ai_family = AF_UNSPEC; | 54 hints.ai_family = AF_UNSPEC; |
| 55 hints.ai_socktype = SOCK_STREAM; | 55 hints.ai_socktype = SOCK_STREAM; |
| 56 snprintf(portstr, sizeof(portstr), "%d", port); | 56 snprintf(portstr, sizeof(portstr), "%d", port); |
| 57 if (getaddrinfo(hostname, portstr, &hints, &ai)) | 57 ret = getaddrinfo(hostname, portstr, &hints, &ai); |
| 58 if (ret) { |
| 59 av_log(NULL, AV_LOG_ERROR, |
| 60 "Failed to resolve hostname %s: %s\n", |
| 61 hostname, gai_strerror(ret)); |
| 58 return AVERROR(EIO); | 62 return AVERROR(EIO); |
| 63 } |
| 59 | 64 |
| 60 cur_ai = ai; | 65 cur_ai = ai; |
| 61 | 66 |
| 62 restart: | 67 restart: |
| 63 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); | 68 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); |
| 64 if (fd < 0) | 69 if (fd < 0) |
| 65 goto fail; | 70 goto fail; |
| 66 ff_socket_nonblock(fd, 1); | 71 ff_socket_nonblock(fd, 1); |
| 67 | 72 |
| 68 redo: | 73 redo: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 tv.tv_sec = 0; | 91 tv.tv_sec = 0; |
| 87 tv.tv_usec = 100 * 1000; | 92 tv.tv_usec = 100 * 1000; |
| 88 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv); | 93 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv); |
| 89 if (ret > 0 && FD_ISSET(fd, &wfds)) | 94 if (ret > 0 && FD_ISSET(fd, &wfds)) |
| 90 break; | 95 break; |
| 91 } | 96 } |
| 92 | 97 |
| 93 /* test error */ | 98 /* test error */ |
| 94 optlen = sizeof(ret); | 99 optlen = sizeof(ret); |
| 95 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); | 100 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); |
| 96 if (ret != 0) | 101 if (ret != 0) { |
| 102 av_log(NULL, AV_LOG_ERROR, |
| 103 "TCP connection to %s:%d failed: %s\n", |
| 104 hostname, port, strerror(ret)); |
| 97 goto fail; | 105 goto fail; |
| 106 } |
| 98 } | 107 } |
| 99 s = av_malloc(sizeof(TCPContext)); | 108 s = av_malloc(sizeof(TCPContext)); |
| 100 if (!s) { | 109 if (!s) { |
| 101 freeaddrinfo(ai); | 110 freeaddrinfo(ai); |
| 102 return AVERROR(ENOMEM); | 111 return AVERROR(ENOMEM); |
| 103 } | 112 } |
| 104 h->priv_data = s; | 113 h->priv_data = s; |
| 105 h->is_streamed = 1; | 114 h->is_streamed = 1; |
| 106 s->fd = fd; | 115 s->fd = fd; |
| 107 freeaddrinfo(ai); | 116 freeaddrinfo(ai); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 215 |
| 207 URLProtocol tcp_protocol = { | 216 URLProtocol tcp_protocol = { |
| 208 "tcp", | 217 "tcp", |
| 209 tcp_open, | 218 tcp_open, |
| 210 tcp_read, | 219 tcp_read, |
| 211 tcp_write, | 220 tcp_write, |
| 212 NULL, /* seek */ | 221 NULL, /* seek */ |
| 213 tcp_close, | 222 tcp_close, |
| 214 .url_get_file_handle = tcp_get_file_handle, | 223 .url_get_file_handle = tcp_get_file_handle, |
| 215 }; | 224 }; |
| OLD | NEW |