summaryrefslogtreecommitdiff
path: root/libavformat/tcp.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2018-08-10 10:39:41 +0300
committerMartin Storsjö <martin@martin.st>2018-08-31 12:26:52 +0300
commit8c76bfacf663ff71cee5264a74d0f9c86addd325 (patch)
tree5cddbb37f43d4706f967eecd62dc06f67ae04a0d /libavformat/tcp.c
parent9b4c3f5aadf54ffd2a6e15746b1fd736379883c4 (diff)
downloadffmpeg-8c76bfacf663ff71cee5264a74d0f9c86addd325.tar.gz
tcp: Use ff_connect_parallel for RFC 8305 style connecting
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r--libavformat/tcp.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 1498c26fbe..7044d44f06 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -108,30 +108,28 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
cur_ai = ai;
- restart:
- fd = ff_socket(cur_ai->ai_family,
- cur_ai->ai_socktype,
- cur_ai->ai_protocol);
- if (fd < 0) {
- ret = ff_neterrno();
- goto fail;
- }
-
if (s->listen) {
+ while (cur_ai && fd < 0) {
+ fd = ff_socket(cur_ai->ai_family,
+ cur_ai->ai_socktype,
+ cur_ai->ai_protocol);
+ if (fd < 0) {
+ ret = ff_neterrno();
+ cur_ai = cur_ai->ai_next;
+ }
+ }
+ if (fd < 0)
+ goto fail1;
+
if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
s->listen_timeout, h)) < 0) {
goto fail1;
}
fd = ret;
} else {
- if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
- s->timeout, h, !!cur_ai->ai_next)) < 0) {
-
- if (ret == AVERROR_EXIT)
- goto fail1;
- else
- goto fail;
- }
+ ret = ff_connect_parallel(ai, s->timeout, 3, h, &fd, NULL, NULL);
+ if (ret < 0)
+ goto fail1;
}
h->is_streamed = 1;
@@ -139,15 +137,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
freeaddrinfo(ai);
return 0;
- fail:
- if (cur_ai->ai_next) {
- /* Retry with the next sockaddr */
- cur_ai = cur_ai->ai_next;
- if (fd >= 0)
- closesocket(fd);
- ret = 0;
- goto restart;
- }
fail1:
if (fd >= 0)
closesocket(fd);