ServerFlags.ReusePort support on POSIX (#95)
This commit is contained in:
parent
ce6e7d17b1
commit
0ad7321aa0
|
@ -1723,13 +1723,19 @@ proc createStreamServer*(host: TransportAddress,
|
||||||
serverSocket = sock
|
serverSocket = sock
|
||||||
|
|
||||||
if host.family in {AddressFamily.IPv4, AddressFamily.IPv6}:
|
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 ServerFlags.ReuseAddr in flags:
|
||||||
if not setSockOpt(serverSocket, SOL_SOCKET, SO_REUSEADDR, 1):
|
if not setSockOpt(serverSocket, SOL_SOCKET, SO_REUSEADDR, 1):
|
||||||
let err = osLastError()
|
let err = osLastError()
|
||||||
if sock == asyncInvalidSocket:
|
if sock == asyncInvalidSocket:
|
||||||
serverSocket.closeSocket()
|
serverSocket.closeSocket()
|
||||||
raiseTransportOsError(err)
|
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.
|
# TCP flags are not useful for Unix domain sockets.
|
||||||
if ServerFlags.TcpNoDelay in flags:
|
if ServerFlags.TcpNoDelay in flags:
|
||||||
if not setSockOpt(serverSocket, handles.IPPROTO_TCP,
|
if not setSockOpt(serverSocket, handles.IPPROTO_TCP,
|
||||||
|
|
Loading…
Reference in New Issue