Commit ad3cffb6 authored by Nicolas George's avatar Nicolas George Committed by Ronald S. Bultje

Non-blocking protocol: TCP

Signed-off-by: 's avatarNicolas George <nicolas.george@normalesup.org>
Signed-off-by: 's avatarRonald S. Bultje <rsbultje@gmail.com>
parent 90441276
...@@ -136,60 +136,35 @@ static int tcp_wait_fd(int fd, int write) ...@@ -136,60 +136,35 @@ static int tcp_wait_fd(int fd, int write)
int ret; int ret;
ret = poll(&p, 1, 100); ret = poll(&p, 1, 100);
return ret < 0 ? ff_neterrno() : !!(p.revents & ev); return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : FF_NETERROR(EAGAIN);
} }
static int tcp_read(URLContext *h, uint8_t *buf, int size) static int tcp_read(URLContext *h, uint8_t *buf, int size)
{ {
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
int len, ret; int ret;
for (;;) { if (!(h->flags & URL_FLAG_NONBLOCK)) {
if (url_interrupt_cb())
return AVERROR(EINTR);
ret = tcp_wait_fd(s->fd, 0); ret = tcp_wait_fd(s->fd, 0);
if (ret > 0) { if (ret < 0)
len = recv(s->fd, buf, size, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return ff_neterrno();
} else return len;
} else if (ret < 0) {
if (ret == FF_NETERROR(EINTR))
continue;
return ret; return ret;
}
} }
ret = recv(s->fd, buf, size, 0);
return ret < 0 ? ff_neterrno() : ret;
} }
static int tcp_write(URLContext *h, const uint8_t *buf, int size) static int tcp_write(URLContext *h, const uint8_t *buf, int size)
{ {
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
int ret, size1, len; int ret;
size1 = size; if (!(h->flags & URL_FLAG_NONBLOCK)) {
while (size > 0) {
if (url_interrupt_cb())
return AVERROR(EINTR);
ret = tcp_wait_fd(s->fd, 1); ret = tcp_wait_fd(s->fd, 1);
if (ret > 0) { if (ret < 0)
len = send(s->fd, buf, size, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return ff_neterrno();
continue;
}
size -= len;
buf += len;
} else if (ret < 0) {
if (ret == FF_NETERROR(EINTR))
continue;
return ret; return ret;
}
} }
return size1 - size; ret = send(s->fd, buf, size, 0);
return ret < 0 ? ff_neterrno() : ret;
} }
static int tcp_close(URLContext *h) static int tcp_close(URLContext *h)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment