diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-06-02 12:52:48 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-06-02 13:02:02 +0400 |
commit | 54ddbb477b786be1b90f54bc9aab36cd5babdf7d (patch) | |
tree | 6396225eedd6179882e50cd4aa82d877eeb53da0 /libavformat/tcp.c | |
parent | 4d4f5911d3121133929da7b859755860f93684fd (diff) | |
parent | f849a77e67959eb6a83eb59b784aeefdb98cb80a (diff) |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
network: factor out connect-listening code
Conflicts:
libavformat/network.h
libavformat/tcp.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r-- | libavformat/tcp.c | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c index d06c18aa50..1442f90477 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -64,7 +64,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags) const char *p; char buf[256]; int ret; - socklen_t optlen; char hostname[1024],proto[1024],path[1024]; char portstr[10]; h->rw_timeout = 5000000; @@ -121,55 +120,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, + h->rw_timeout, h)) < 0) { - if (ret < 0) { - struct pollfd p = {fd, POLLOUT, 0}; - int64_t wait_started; - ret = ff_neterrno(); - if (ret == AVERROR(EINTR)) { - if (ff_check_interrupt(&h->interrupt_callback)) { - ret = AVERROR_EXIT; + if (ret == AVERROR_EXIT) goto fail1; - } - goto redo; - } - if (ret != AVERROR(EINPROGRESS) && - ret != AVERROR(EAGAIN)) - goto fail; - - /* wait until we are connected or until abort */ - wait_started = av_gettime(); - do { - if (ff_check_interrupt(&h->interrupt_callback)) { - ret = AVERROR_EXIT; - goto fail1; - } - ret = poll(&p, 1, 100); - if (ret > 0) - break; - } while (!h->rw_timeout || (av_gettime() - wait_started < h->rw_timeout)); - 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); |