Merge branch 'devel' into async-improvements
This commit is contained in:
commit
5e43e0d789
95 changed files with 9598 additions and 948 deletions
|
|
@ -145,7 +145,7 @@ type
|
|||
|
||||
SOBool* = enum ## Boolean socket options.
|
||||
OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
|
||||
OptOOBInline, OptReuseAddr, OptReusePort
|
||||
OptOOBInline, OptReuseAddr, OptReusePort, OptNoDelay
|
||||
|
||||
ReadLineResult* = enum ## result for readLineAsync
|
||||
ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone
|
||||
|
|
@ -865,6 +865,11 @@ proc close*(socket: Socket) =
|
|||
|
||||
socket.fd.close()
|
||||
|
||||
when defined(posix):
|
||||
from posix import TCP_NODELAY
|
||||
else:
|
||||
from winlean import TCP_NODELAY
|
||||
|
||||
proc toCInt*(opt: SOBool): cint =
|
||||
## Converts a ``SOBool`` into its Socket Option cint representation.
|
||||
case opt
|
||||
|
|
@ -876,6 +881,7 @@ proc toCInt*(opt: SOBool): cint =
|
|||
of OptOOBInline: SO_OOBINLINE
|
||||
of OptReuseAddr: SO_REUSEADDR
|
||||
of OptReusePort: SO_REUSEPORT
|
||||
of OptNoDelay: TCP_NODELAY
|
||||
|
||||
proc getSockOpt*(socket: Socket, opt: SOBool, level = SOL_SOCKET): bool {.
|
||||
tags: [ReadIOEffect].} =
|
||||
|
|
@ -898,6 +904,12 @@ proc getPeerAddr*(socket: Socket): (string, Port) =
|
|||
proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {.
|
||||
tags: [WriteIOEffect].} =
|
||||
## 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)
|
||||
setSockOptInt(socket.fd, cint(level), toCInt(opt), valuei)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue