summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2007-04-27 00:41:50 +0000
committerAlex Beregszaszi <alex@rtfs.hu>2007-04-27 00:41:50 +0000
commitba472aaf010e69661866decbd3cfde177d8c0ee9 (patch)
treee5a955ea482a37f9c2651cd195f59072ca8291b3 /libavformat
parent8da4034f529f3c5dcc3f95a7d81032cc9be543fb (diff)
implement ff_socket_nonblock and use it in networking code
Originally committed as revision 8846 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/network.h2
-rw-r--r--libavformat/os_support.c8
-rw-r--r--libavformat/tcp.c3
3 files changed, 11 insertions, 2 deletions
diff --git a/libavformat/network.h b/libavformat/network.h
index 7dcbfe244c..6ceba41902 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -32,6 +32,8 @@
#define ff_neterrno() errno
#define FF_NETERROR(err) err
+int ff_socket_nonblock(int socket, int enable);
+
#if !defined(HAVE_INET_ATON)
/* in os_support.c */
int inet_aton (const char * str, struct in_addr * add);
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index da303be49c..abee749aac 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -114,6 +114,14 @@ int resolve_host(struct in_addr *sin_addr, const char *hostname)
}
return 0;
}
+
+int ff_socket_nonblock(int socket, int enable)
+{
+ if (enable)
+ return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
+ else
+ return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
+}
#endif /* CONFIG_NETWORK */
#ifdef CONFIG_FFSERVER
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index b2f6d37a76..36b67076af 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -22,7 +22,6 @@
#include <unistd.h>
#include "network.h"
#include <sys/time.h>
-#include <fcntl.h>
typedef struct TCPContext {
int fd;
@@ -62,7 +61,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
goto fail;
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ ff_socket_nonblock(fd, 1);
redo:
ret = connect(fd, (struct sockaddr *)&dest_addr,