Mercurial > libavformat.hg
changeset 2057:857fbfeb2fa0 libavformat
implement ff_socket_nonblock and use it in networking code
author | alex |
---|---|
date | Fri, 27 Apr 2007 00:41:50 +0000 |
parents | eeea52739ff3 |
children | 47bb66436d52 |
files | network.h os_support.c tcp.c |
diffstat | 3 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/network.h Fri Apr 27 00:35:54 2007 +0000 +++ b/network.h Fri Apr 27 00:41:50 2007 +0000 @@ -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);
--- a/os_support.c Fri Apr 27 00:35:54 2007 +0000 +++ b/os_support.c Fri Apr 27 00:41:50 2007 +0000 @@ -114,6 +114,14 @@ } 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
--- a/tcp.c Fri Apr 27 00:35:54 2007 +0000 +++ b/tcp.c Fri Apr 27 00:41:50 2007 +0000 @@ -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 @@ 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,