ServerFlags.ReusePort support on POSIX (#95)

This commit is contained in:
Ștefan Talpalaru 2020-07-12 18:13:22 +02:00 committed by GitHub
parent ce6e7d17b1
commit 0ad7321aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -1723,13 +1723,19 @@ proc createStreamServer*(host: TransportAddress,
serverSocket = sock
if host.family in {AddressFamily.IPv4, AddressFamily.IPv6}:
# SO_REUSEADDR is not useful for Unix domain sockets.
# SO_REUSEADDR and SO_REUSEPORT are not useful for Unix domain sockets.
if ServerFlags.ReuseAddr in flags:
if not setSockOpt(serverSocket, SOL_SOCKET, SO_REUSEADDR, 1):
let err = osLastError()
if sock == asyncInvalidSocket:
serverSocket.closeSocket()
raiseTransportOsError(err)
if ServerFlags.ReusePort in flags:
if not setSockOpt(serverSocket, SOL_SOCKET, SO_REUSEPORT, 1):
let err = osLastError()
if sock == asyncInvalidSocket:
serverSocket.closeSocket()
raiseTransportOsError(err)
# TCP flags are not useful for Unix domain sockets.
if ServerFlags.TcpNoDelay in flags:
if not setSockOpt(serverSocket, handles.IPPROTO_TCP,