mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Enable SO_REUSEADDR on TCP server socket.
This commit is contained in:
parent
11b750c745
commit
405558258d
|
@ -925,6 +925,10 @@ static sock_t new_listening_TCP_socket(int family, uint16_t port)
|
|||
ok = set_socket_dualstack(sock);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = set_socket_reuseaddr(sock);
|
||||
}
|
||||
|
||||
ok = ok && bind_to_port(sock, family, port) && (listen(sock, TCP_MAX_BACKLOG) == 0);
|
||||
|
||||
if (!ok) {
|
||||
|
|
|
@ -172,6 +172,17 @@ int set_socket_nosigpipe(sock_t sock)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Enable SO_REUSEADDR on socket.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int set_socket_reuseaddr(sock_t sock)
|
||||
{
|
||||
int set = 1;
|
||||
return (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)) == 0);
|
||||
}
|
||||
|
||||
/* Set socket to dual (IPv4 + IPv6 socket)
|
||||
*
|
||||
* return 1 on success
|
||||
|
|
|
@ -334,6 +334,13 @@ int set_socket_nonblock(sock_t sock);
|
|||
*/
|
||||
int set_socket_nosigpipe(sock_t sock);
|
||||
|
||||
/* Enable SO_REUSEADDR on socket.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int set_socket_reuseaddr(sock_t sock);
|
||||
|
||||
/* Set socket to dual (IPv4 + IPv6 socket)
|
||||
*
|
||||
* return 1 on success
|
||||
|
|
Loading…
Reference in New Issue
Block a user