From ebba2b3e2a551ce638d17332761431ba748f178f Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 4 Apr 2011 18:17:12 +0200 Subject: proto: factor ff_network_wait_fd and use it on udp Support the URL_FLAG_NONBLOCK semantic and uniform the protocol. The quick retry loop is already part of retry_transfer_wrapper. The polling routine is common to the network protocols: udp, tcp and, once merged, sctp. --- libavformat/tcp.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'libavformat/tcp.c') diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 37e6d6f10e..cf294dc4b9 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -131,23 +131,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags) return ret; } -static int tcp_wait_fd(int fd, int write) -{ - int ev = write ? POLLOUT : POLLIN; - struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; - int ret; - - ret = poll(&p, 1, 100); - return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN); -} - static int tcp_read(URLContext *h, uint8_t *buf, int size) { TCPContext *s = h->priv_data; int ret; if (!(h->flags & URL_FLAG_NONBLOCK)) { - ret = tcp_wait_fd(s->fd, 0); + ret = ff_network_wait_fd(s->fd, 0); if (ret < 0) return ret; } @@ -161,7 +151,7 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int size) int ret; if (!(h->flags & URL_FLAG_NONBLOCK)) { - ret = tcp_wait_fd(s->fd, 1); + ret = ff_network_wait_fd(s->fd, 1); if (ret < 0) return ret; } -- cgit v1.2.3