summaryrefslogtreecommitdiff
path: root/libavformat/tcp.c
diff options
context:
space:
mode:
authorLeon van Stuivenberg <leonvs@iae.nl>2004-03-14 19:40:43 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-03-14 19:40:43 +0000
commitb51469a0c54b30079eecc4891cc050778f343683 (patch)
treeab4c2260b0b8dab865ceccb4a0e49d575e8606b6 /libavformat/tcp.c
parent35fe5cc53ff1b2a23e01557cad19ffdbe14cad6f (diff)
tcp select() check and enables pressing 'q' when reading/(writing) from
tcp/http in ffmpeg.c patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>) Originally committed as revision 2891 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r--libavformat/tcp.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index b49e78ff24..212e43b7f1 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -141,7 +141,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
static int tcp_read(URLContext *h, uint8_t *buf, int size)
{
TCPContext *s = h->priv_data;
- int len, fd_max;
+ int len, fd_max, ret;
fd_set rfds;
struct timeval tv;
@@ -153,28 +153,31 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
FD_SET(s->fd, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 100 * 1000;
- select(fd_max + 1, &rfds, NULL, NULL, &tv);
+ ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
+ if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
#ifdef __BEOS__
- len = recv(s->fd, buf, size, 0);
+ len = recv(s->fd, buf, size, 0);
#else
- len = read(s->fd, buf, size);
+ len = read(s->fd, buf, size);
#endif
- if (len < 0) {
- if (errno != EINTR && errno != EAGAIN)
+ if (len < 0) {
+ if (errno != EINTR && errno != EAGAIN)
#ifdef __BEOS__
- return errno;
+ return errno;
#else
- return -errno;
+ return -errno;
#endif
- } else break;
+ } else return len;
+ } else if (ret < 0) {
+ return -1;
+ }
}
- return len;
}
static int tcp_write(URLContext *h, uint8_t *buf, int size)
{
TCPContext *s = h->priv_data;
- int ret, size1, fd_max;
+ int ret, size1, fd_max, len;
fd_set wfds;
struct timeval tv;
@@ -187,24 +190,28 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size)
FD_SET(s->fd, &wfds);
tv.tv_sec = 0;
tv.tv_usec = 100 * 1000;
- select(fd_max + 1, NULL, &wfds, NULL, &tv);
+ ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
+ if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
#ifdef __BEOS__
- ret = send(s->fd, buf, size, 0);
+ len = send(s->fd, buf, size, 0);
#else
- ret = write(s->fd, buf, size);
+ len = write(s->fd, buf, size);
#endif
- if (ret < 0) {
- if (errno != EINTR && errno != EAGAIN) {
+ if (len < 0) {
+ if (errno != EINTR && errno != EAGAIN) {
#ifdef __BEOS__
- return errno;
+ return errno;
#else
- return -errno;
+ return -errno;
#endif
+ }
+ continue;
}
- continue;
+ size -= len;
+ buf += len;
+ } else if (ret < 0) {
+ return -1;
}
- size -= ret;
- buf += ret;
}
return size1 - size;
}