Add support of TCP_NODELAY option for TCP transport.

Bump version to 2.1.0.
This commit is contained in:
cheatfate 2018-08-27 21:41:11 +03:00
parent 530905f276
commit c84b8cb143
4 changed files with 14 additions and 2 deletions

View File

@ -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"

View File

@ -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.

View File

@ -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

View File

@ -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: