diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2013-05-31 05:05:13 +0400 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2013-06-01 17:29:53 +0400 |
commit | f849a77e67959eb6a83eb59b784aeefdb98cb80a (patch) | |
tree | 8c3ac49ace6c1e03463206860b1484332818108d /libavformat/tcp.c | |
parent | 28306e6d620c109ddd672f7243adfbc2bbb3b18f (diff) |
network: factor out connect-listening code
Introduce ff_listen_connect, to be shared with the other
non-tcp network protocols.
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r-- | libavformat/tcp.c | 50 |
1 files changed, 6 insertions, 44 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 6e4de0db6b..fff9e1fcd4 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -42,7 +42,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags) const char *p; char buf[256]; int ret; - socklen_t optlen; int timeout = 100, listen_timeout = -1; char hostname[1024],proto[1024],path[1024]; char portstr[10]; @@ -98,53 +97,16 @@ static int tcp_open(URLContext *h, const char *uri, int flags) goto fail1; } } else { - redo: - ff_socket_nonblock(fd, 1); - ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); - } + if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, + timeout, h)) < 0) { - if (ret < 0) { - struct pollfd p = {fd, POLLOUT, 0}; - ret = ff_neterrno(); - if (ret == AVERROR(EINTR)) { - if (ff_check_interrupt(&h->interrupt_callback)) { - ret = AVERROR_EXIT; - goto fail1; - } - goto redo; - } - if (ret != AVERROR(EINPROGRESS) && - ret != AVERROR(EAGAIN)) - goto fail; - - /* wait until we are connected or until abort */ - while(timeout--) { - if (ff_check_interrupt(&h->interrupt_callback)) { - ret = AVERROR_EXIT; + if (ret == AVERROR_EXIT) goto fail1; - } - ret = poll(&p, 1, 100); - if (ret > 0) - break; - } - if (ret <= 0) { - ret = AVERROR(ETIMEDOUT); - goto fail; - } - /* test error */ - optlen = sizeof(ret); - if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen)) - ret = AVUNERROR(ff_neterrno()); - if (ret != 0) { - char errbuf[100]; - ret = AVERROR(ret); - av_strerror(ret, errbuf, sizeof(errbuf)); - av_log(h, AV_LOG_ERROR, - "TCP connection to %s:%d failed: %s\n", - hostname, port, errbuf); - goto fail; + else + goto fail; } } + h->is_streamed = 1; s->fd = fd; freeaddrinfo(ai); |