From c84b8cb143e3d6f0ab03fafd41a59cb61bde40ad Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 27 Aug 2018 21:41:11 +0300 Subject: [PATCH] Add support of TCP_NODELAY option for TCP transport. Bump version to 2.1.0. --- asyncdispatch2.nimble | 2 +- asyncdispatch2/handles.nim | 4 ++++ asyncdispatch2/transports/common.nim | 2 +- asyncdispatch2/transports/stream.nim | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/asyncdispatch2.nimble b/asyncdispatch2.nimble index edaf5cb5..4f2d9690 100644 --- a/asyncdispatch2.nimble +++ b/asyncdispatch2.nimble @@ -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" diff --git a/asyncdispatch2/handles.nim b/asyncdispatch2/handles.nim index 19f0649b..84c1c7c9 100644 --- a/asyncdispatch2/handles.nim +++ b/asyncdispatch2/handles.nim @@ -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. diff --git a/asyncdispatch2/transports/common.nim b/asyncdispatch2/transports/common.nim index c3ee4d59..794716e6 100644 --- a/asyncdispatch2/transports/common.nim +++ b/asyncdispatch2/transports/common.nim @@ -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 diff --git a/asyncdispatch2/transports/stream.nim b/asyncdispatch2/transports/stream.nim index f4cc9d2b..c0268d70 100644 --- a/asyncdispatch2/transports/stream.nim +++ b/asyncdispatch2/transports/stream.nim @@ -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: