diff --git a/cfg-common.h b/cfg-common.h index e313d62c46..3262490ec8 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -58,6 +58,8 @@ {"cookies-file", &cookies_file, CONF_TYPE_STRING, 0, 0, 0, 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}, + {"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 {"prefer-ipv6", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 1, 0, NULL}, #else @@ -368,6 +370,7 @@ extern char *cookies_file; extern int network_prefer_ipv4; extern int network_ipv4_only_proxy; +extern int reuse_socket; #endif diff --git a/stream/udp.c b/stream/udp.c index 889c23826d..67e8f04f98 100644 --- a/stream/udp.c +++ b/stream/udp.c @@ -43,6 +43,8 @@ #include "url.h" #include "udp.h" +int reuse_socket=0; + /* Start listening on a UDP port. If multicast, join the group. */ int udp_open_socket (URL_t *url) @@ -55,6 +57,7 @@ udp_open_socket (URL_t *url) struct ip_mreq mcast; struct timeval tv; struct hostent *hp; + int reuse=reuse_socket; mp_msg (MSGT_NETWORK, MSGL_V, "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_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, sizeof (server_address)) == -1) {