Add support of TCP_NODELAY option for TCP transport.
Bump version to 2.1.0.
This commit is contained in:
parent
530905f276
commit
c84b8cb143
|
@ -1,5 +1,5 @@
|
|||
packageName = "asyncdispatch2"
|
||||
version = "2.0.9"
|
||||
version = "2.1.0"
|
||||
author = "Status Research & Development GmbH"
|
||||
description = "Asyncdispatch2"
|
||||
license = "Apache License 2.0 or MIT"
|
||||
|
|
|
@ -13,10 +13,14 @@ when defined(windows):
|
|||
import winlean
|
||||
const
|
||||
asyncInvalidSocket* = AsyncFD(-1)
|
||||
TCP_NODELAY* = 1
|
||||
IPPROTO_TCP* = 6
|
||||
else:
|
||||
import posix
|
||||
const
|
||||
asyncInvalidSocket* = AsyncFD(posix.INVALID_SOCKET)
|
||||
TCP_NODELAY* = 1
|
||||
IPPROTO_TCP* = 6
|
||||
|
||||
proc setSocketBlocking*(s: SocketHandle, blocking: bool): bool =
|
||||
## Sets blocking mode on socket.
|
||||
|
|
|
@ -25,7 +25,7 @@ const
|
|||
type
|
||||
ServerFlags* = enum
|
||||
## Server's flags
|
||||
ReuseAddr, ReusePort, NoAutoRead, GCUserData
|
||||
ReuseAddr, ReusePort, TcpNoDelay, NoAutoRead, GCUserData
|
||||
|
||||
TransportAddress* = object
|
||||
## Transport network address
|
||||
|
|
|
@ -853,6 +853,14 @@ proc createStreamServer*(host: TransportAddress,
|
|||
serverSocket.closeSocket()
|
||||
raiseTransportOsError(err)
|
||||
|
||||
if ServerFlags.TcpNoDelay in flags:
|
||||
if not setSockOpt(serverSocket, handles.IPPROTO_TCP,
|
||||
handles.TCP_NODELAY, 1):
|
||||
let err = osLastError()
|
||||
if sock == asyncInvalidSocket:
|
||||
serverSocket.closeSocket()
|
||||
raiseTransportOsError(err)
|
||||
|
||||
toSockAddr(host.address, host.port, saddr, slen)
|
||||
if bindAddr(SocketHandle(serverSocket), cast[ptr SockAddr](addr saddr),
|
||||
slen) != 0:
|
||||
|
|
Loading…
Reference in New Issue