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.
This commit is contained in:
Luca Barbato
2011-04-04 18:17:12 +02:00
parent 1f6265e011
commit ebba2b3e2a
3 changed files with 34 additions and 52 deletions

View File

@@ -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;
}