Commit af9809f0 authored by Laurent Aimar's avatar Laurent Aimar

Fixed socket setup in net_ListenSingle.

(it was used by net_OpenDgram when no server is specified).
parent 3228d8b3
...@@ -97,6 +97,47 @@ ...@@ -97,6 +97,47 @@
extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype, extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
int i_protocol ); int i_protocol );
/* */
static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addrinfo *ptr )
{
#ifdef SO_REUSEPORT
setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof (int));
#endif
#ifdef SO_RCVBUF
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
* to avoid packet loss caused in case of scheduling hiccups */
setsockopt (fd, SOL_SOCKET, SO_RCVBUF,
(void *)&(int){ 0x80000 }, sizeof (int));
setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
(void *)&(int){ 0x80000 }, sizeof (int));
#endif
#if defined (WIN32) || defined (UNDER_CE)
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
&& (sizeof (struct sockaddr_storage) >= ptr->ai_addrlen))
{
// This works for IPv4 too - don't worry!
struct sockaddr_in6 dumb =
{
.sin6_family = ptr->ai_addr->sa_family,
.sin6_port = ((struct sockaddr_in *)(ptr->ai_addr))->sin_port
};
bind (fd, (struct sockaddr *)&dumb, ptr->ai_addrlen);
}
else
#endif
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
{
msg_Err( p_obj, "socket bind error (%m)" );
net_Close (fd);
return -1;
}
return fd;
}
/* */
static int net_ListenSingle (vlc_object_t *obj, const char *host, int port, static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
int family, int protocol) int family, int protocol)
{ {
...@@ -145,26 +186,9 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port, ...@@ -145,26 +186,9 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
} }
} }
/* Bind the socket */ fd = net_SetupDgramSocket( obj, fd, ptr );
#if defined (WIN32) || defined (UNDER_CE) if( fd == -1 )
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
&& (sizeof (struct sockaddr_storage) >= ptr->ai_addrlen))
{
struct sockaddr_in6 dumb =
{
.sin6_family = ptr->ai_addr->sa_family,
.sin6_port = ((struct sockaddr_in *)(ptr->ai_addr))->sin_port
};
bind (fd, (struct sockaddr *)&dumb, ptr->ai_addrlen);
}
else
#endif
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
{
msg_Err (obj, "socket bind error (%m)");
net_Close (fd);
continue; continue;
}
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen) if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
&& net_Subscribe (obj, fd, ptr->ai_addr, ptr->ai_addrlen)) && net_Subscribe (obj, fd, ptr->ai_addr, ptr->ai_addrlen))
...@@ -753,39 +777,9 @@ int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind, ...@@ -753,39 +777,9 @@ int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
if (fd == -1) if (fd == -1)
continue; // usually, address family not supported continue; // usually, address family not supported
#ifdef SO_REUSEPORT fd = net_SetupDgramSocket( obj, fd, ptr );
setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof (int)); if( fd == -1 )
#endif
#ifdef SO_RCVBUF
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
* to avoid packet loss caused in case of scheduling hiccups */
setsockopt (fd, SOL_SOCKET, SO_RCVBUF,
(void *)&(int){ 0x80000 }, sizeof (int));
setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
(void *)&(int){ 0x80000 }, sizeof (int));
#endif
#if defined (WIN32) || defined (UNDER_CE)
if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
&& (sizeof (struct sockaddr_storage) >= ptr->ai_addrlen))
{
// This works for IPv4 too - don't worry!
struct sockaddr_in6 dumb =
{
.sin6_family = ptr->ai_addr->sa_family,
.sin6_port = ((struct sockaddr_in *)(ptr->ai_addr))->sin_port
};
bind (fd, (struct sockaddr *)&dumb, ptr->ai_addrlen);
}
else
#endif
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
{
net_Close (fd);
continue; continue;
}
val = -1; val = -1;
for (struct addrinfo *ptr2 = rem; ptr2 != NULL; ptr2 = ptr2->ai_next) for (struct addrinfo *ptr2 = rem; ptr2 != NULL; ptr2 = ptr2->ai_next)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment