optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22491 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
nicodvb 2007-03-08 20:47:10 +00:00
parent 195ebfbef8
commit 2cefb53a76
2 changed files with 9 additions and 0 deletions

View File

@ -58,6 +58,8 @@
{"cookies-file", &cookies_file, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"cookies-file", &cookies_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"prefer-ipv4", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"prefer-ipv4", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"ipv4-only-proxy", &network_ipv4_only_proxy, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"ipv4-only-proxy", &network_ipv4_only_proxy, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"reuse-socket", &reuse_socket, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"noreuse-socket", &reuse_socket, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
#ifdef HAVE_AF_INET6 #ifdef HAVE_AF_INET6
{"prefer-ipv6", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 1, 0, NULL}, {"prefer-ipv6", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 1, 0, NULL},
#else #else
@ -368,6 +370,7 @@ extern char *cookies_file;
extern int network_prefer_ipv4; extern int network_prefer_ipv4;
extern int network_ipv4_only_proxy; extern int network_ipv4_only_proxy;
extern int reuse_socket;
#endif #endif

View File

@ -43,6 +43,8 @@
#include "url.h" #include "url.h"
#include "udp.h" #include "udp.h"
int reuse_socket=0;
/* Start listening on a UDP port. If multicast, join the group. */ /* Start listening on a UDP port. If multicast, join the group. */
int int
udp_open_socket (URL_t *url) udp_open_socket (URL_t *url)
@ -55,6 +57,7 @@ udp_open_socket (URL_t *url)
struct ip_mreq mcast; struct ip_mreq mcast;
struct timeval tv; struct timeval tv;
struct hostent *hp; struct hostent *hp;
int reuse=reuse_socket;
mp_msg (MSGT_NETWORK, MSGL_V, mp_msg (MSGT_NETWORK, MSGL_V,
"Listening for traffic on %s:%d ...\n", url->hostname, url->port); "Listening for traffic on %s:%d ...\n", url->hostname, url->port);
@ -98,6 +101,9 @@ udp_open_socket (URL_t *url)
server_address.sin_family = AF_INET; server_address.sin_family = AF_INET;
server_address.sin_port = htons (url->port); server_address.sin_port = htons (url->port);
if(reuse_socket && setsockopt(socket_server_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)))
mp_msg(MSGT_NETWORK, MSGL_ERR, "SO_REUSEADDR failed! ignore.\n");
if (bind (socket_server_fd, (struct sockaddr *) &server_address, if (bind (socket_server_fd, (struct sockaddr *) &server_address,
sizeof (server_address)) == -1) sizeof (server_address)) == -1)
{ {