1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

implement ff_socket_nonblock and use it in networking code

Originally committed as revision 8846 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Alex Beregszaszi 2007-04-27 00:41:50 +00:00
parent 8da4034f52
commit ba472aaf01
4 changed files with 13 additions and 4 deletions

View File

@ -440,7 +440,7 @@ static int socket_open_listen(struct sockaddr_in *my_addr)
closesocket(server_fd); closesocket(server_fd);
return -1; return -1;
} }
fcntl(server_fd, F_SETFL, O_NONBLOCK); ff_socket_nonblock(server_fd, 1);
return server_fd; return server_fd;
} }
@ -649,7 +649,7 @@ static void new_connection(int server_fd, int is_rtsp)
&len); &len);
if (fd < 0) if (fd < 0)
return; return;
fcntl(fd, F_SETFL, O_NONBLOCK); ff_socket_nonblock(fd, 1);
/* XXX: should output a warning page when coming /* XXX: should output a warning page when coming
close to the connection limit */ close to the connection limit */

View File

@ -32,6 +32,8 @@
#define ff_neterrno() errno #define ff_neterrno() errno
#define FF_NETERROR(err) err #define FF_NETERROR(err) err
int ff_socket_nonblock(int socket, int enable);
#if !defined(HAVE_INET_ATON) #if !defined(HAVE_INET_ATON)
/* in os_support.c */ /* in os_support.c */
int inet_aton (const char * str, struct in_addr * add); int inet_aton (const char * str, struct in_addr * add);

View File

@ -114,6 +114,14 @@ int resolve_host(struct in_addr *sin_addr, const char *hostname)
} }
return 0; 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 */ #endif /* CONFIG_NETWORK */
#ifdef CONFIG_FFSERVER #ifdef CONFIG_FFSERVER

View File

@ -22,7 +22,6 @@
#include <unistd.h> #include <unistd.h>
#include "network.h" #include "network.h"
#include <sys/time.h> #include <sys/time.h>
#include <fcntl.h>
typedef struct TCPContext { typedef struct TCPContext {
int fd; int fd;
@ -62,7 +61,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
fd = socket(AF_INET, SOCK_STREAM, 0); fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0)
goto fail; goto fail;
fcntl(fd, F_SETFL, O_NONBLOCK); ff_socket_nonblock(fd, 1);
redo: redo:
ret = connect(fd, (struct sockaddr *)&dest_addr, ret = connect(fd, (struct sockaddr *)&dest_addr,