aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJindřich Makovička <makovick@gmail.com>2008-11-14 19:33:22 +0000
committerJindřich Makovička <makovick@gmail.com>2008-11-14 19:33:22 +0000
commit7d0842992a92a81adbe67843145c7e4249a99ead (patch)
tree8ba20981e56d8a18c83c6d369862c5c58ef8b604
parent9e164392875484daf5dd1a4a63fc3d90cba02760 (diff)
downloadffmpeg-7d0842992a92a81adbe67843145c7e4249a99ead.tar.gz
check for interrupt when receiving from socket
Originally committed as revision 15824 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/udp.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index bdd66152fe..a8e8cd8bce 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -29,6 +29,9 @@
#include <unistd.h>
#include "network.h"
#include "os_support.h"
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
#ifndef IPV6_ADD_MEMBERSHIP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
@@ -449,9 +452,23 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
{
UDPContext *s = h->priv_data;
int len;
+ fd_set rfds;
+ int ret;
+ struct timeval tv;
for(;;) {
- len = recv(s->udp_fd, buf, size, 0);
+ if (url_interrupt_cb())
+ return AVERROR(EINTR);
+ FD_ZERO(&rfds);
+ FD_SET(s->udp_fd, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 100 * 1000;
+ ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
+ if (ret < 0)
+ return AVERROR(EIO);
+ if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds)))
+ continue;
+ len = recv(s->udp_fd, buf, size, MSG_DONTWAIT);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))