Merge pull request #6802 from FedericoCeratto/nodelay
Add TCP_NODELAY support #6795
This commit is contained in:
commit
073c2ddd4b
2 changed files with 14 additions and 1 deletions
|
|
@ -145,7 +145,7 @@ type
|
||||||
|
|
||||||
SOBool* = enum ## Boolean socket options.
|
SOBool* = enum ## Boolean socket options.
|
||||||
OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
|
OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
|
||||||
OptOOBInline, OptReuseAddr, OptReusePort
|
OptOOBInline, OptReuseAddr, OptReusePort, OptNoDelay
|
||||||
|
|
||||||
ReadLineResult* = enum ## result for readLineAsync
|
ReadLineResult* = enum ## result for readLineAsync
|
||||||
ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone
|
ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone
|
||||||
|
|
@ -869,6 +869,11 @@ proc close*(socket: Socket) =
|
||||||
|
|
||||||
socket.fd.close()
|
socket.fd.close()
|
||||||
|
|
||||||
|
when defined(posix):
|
||||||
|
from posix import TCP_NODELAY
|
||||||
|
else:
|
||||||
|
from winlean import TCP_NODELAY
|
||||||
|
|
||||||
proc toCInt*(opt: SOBool): cint =
|
proc toCInt*(opt: SOBool): cint =
|
||||||
## Converts a ``SOBool`` into its Socket Option cint representation.
|
## Converts a ``SOBool`` into its Socket Option cint representation.
|
||||||
case opt
|
case opt
|
||||||
|
|
@ -880,6 +885,7 @@ proc toCInt*(opt: SOBool): cint =
|
||||||
of OptOOBInline: SO_OOBINLINE
|
of OptOOBInline: SO_OOBINLINE
|
||||||
of OptReuseAddr: SO_REUSEADDR
|
of OptReuseAddr: SO_REUSEADDR
|
||||||
of OptReusePort: SO_REUSEPORT
|
of OptReusePort: SO_REUSEPORT
|
||||||
|
of OptNoDelay: TCP_NODELAY
|
||||||
|
|
||||||
proc getSockOpt*(socket: Socket, opt: SOBool, level = SOL_SOCKET): bool {.
|
proc getSockOpt*(socket: Socket, opt: SOBool, level = SOL_SOCKET): bool {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
|
|
@ -902,6 +908,12 @@ proc getPeerAddr*(socket: Socket): (string, Port) =
|
||||||
proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {.
|
proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {.
|
||||||
tags: [WriteIOEffect].} =
|
tags: [WriteIOEffect].} =
|
||||||
## Sets option ``opt`` to a boolean value specified by ``value``.
|
## Sets option ``opt`` to a boolean value specified by ``value``.
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## var socket = newSocket()
|
||||||
|
## socket.setSockOpt(OptReusePort, true)
|
||||||
|
## socket.setSockOpt(OptNoDelay, true, level=IPPROTO_TCP.toInt)
|
||||||
|
##
|
||||||
var valuei = cint(if value: 1 else: 0)
|
var valuei = cint(if value: 1 else: 0)
|
||||||
setSockOptInt(socket.fd, cint(level), toCInt(opt), valuei)
|
setSockOptInt(socket.fd, cint(level), toCInt(opt), valuei)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,7 @@ var
|
||||||
SO_DONTLINGER* {.importc, header: "winsock2.h".}: cint
|
SO_DONTLINGER* {.importc, header: "winsock2.h".}: cint
|
||||||
SO_EXCLUSIVEADDRUSE* {.importc, header: "winsock2.h".}: cint # disallow local address reuse
|
SO_EXCLUSIVEADDRUSE* {.importc, header: "winsock2.h".}: cint # disallow local address reuse
|
||||||
SO_ERROR* {.importc, header: "winsock2.h".}: cint
|
SO_ERROR* {.importc, header: "winsock2.h".}: cint
|
||||||
|
TCP_NODELAY* {.importc, header: "winsock2.h".}: cint
|
||||||
|
|
||||||
proc `==`*(x, y: SocketHandle): bool {.borrow.}
|
proc `==`*(x, y: SocketHandle): bool {.borrow.}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue