aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2011-02-04 19:12:38 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-02-06 20:31:46 +0100
commit6e59474b3093ea0b3193e88bae81ed764683809a (patch)
tree58a4b1281a7fcaad4fa882c6854e57fdebae3f80
parent3ce3b4982447eb557555c444b2e75787de7c3472 (diff)
downloadffmpeg-6e59474b3093ea0b3193e88bae81ed764683809a.tar.gz
Non-blocking protocol: TCP
Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com> (cherry picked from commit ad3cffb68f9c77e140660a8ae7d43c8606208178)
-rw-r--r--libavformat/tcp.c47
1 files changed, 11 insertions, 36 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 564d69f19d..29eb60abe9 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -136,60 +136,35 @@ static int tcp_wait_fd(int fd, int write)
int ret;
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)
{
TCPContext *s = h->priv_data;
- int len, ret;
+ int ret;
- for (;;) {
- if (url_interrupt_cb())
- return AVERROR(EINTR);
+ if (!(h->flags & URL_FLAG_NONBLOCK)) {
ret = tcp_wait_fd(s->fd, 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;
+ if (ret < 0)
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)
{
TCPContext *s = h->priv_data;
- int ret, size1, len;
+ int ret;
- size1 = size;
- while (size > 0) {
- if (url_interrupt_cb())
- return AVERROR(EINTR);
+ if (!(h->flags & URL_FLAG_NONBLOCK)) {
ret = tcp_wait_fd(s->fd, 1);
- 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;
+ if (ret < 0)
return ret;
- }
}
- return size1 - size;
+ ret = send(s->fd, buf, size, 0);
+ return ret < 0 ? ff_neterrno() : ret;
}
static int tcp_close(URLContext *h)