diff --git a/ffserver.c b/ffserver.c index 9f5502b22853acf2a61a0c21a021ef7d09c1392c..8f9bba6b49c9cc610ab4519eed21d2948d4a9591 100644 --- a/ffserver.c +++ b/ffserver.c @@ -440,7 +440,7 @@ static int socket_open_listen(struct sockaddr_in *my_addr) closesocket(server_fd); return -1; } - fcntl(server_fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(server_fd, 1); return server_fd; } @@ -649,7 +649,7 @@ static void new_connection(int server_fd, int is_rtsp) &len); if (fd < 0) return; - fcntl(fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(fd, 1); /* XXX: should output a warning page when coming close to the connection limit */ diff --git a/libavformat/network.h b/libavformat/network.h index 7dcbfe244c0acc225812d8704dacced97335ac4e..6ceba419026d58f89e236ad088ac12ccf3042527 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 da303be49cbdb8687590f332be52fd8eec80fefd..abee749aacb78847818a0a04a691cf820b362cf0 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 b2f6d37a763f6e00a8ffe032f457cfe7d7cf5bdc..36b67076af8dac8509b6b4048b8a72b9e25be420 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,