diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2017-01-18 17:49:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 17:49:49 +0100 |
commit | bde768cb091bcba57c07cf6d73080fca8c2c36f9 (patch) | |
tree | c54aae56897f78c1020002887b4b0d3c91a06315 /lib | |
parent | 61937974e2a7fcf3ff6427510f793c4b580f1b62 (diff) | |
parent | 9b0b079634a642bf9cc71c0966862c3fc93bedc0 (diff) | |
download | Nim-bde768cb091bcba57c07cf6d73080fca8c2c36f9.tar.gz |
Merge pull request #5239 from illogica/patch-2
Fix nativesockets.select()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/nativesockets.nim | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim index 4526afa49..534a66449 100644 --- a/lib/pure/nativesockets.nim +++ b/lib/pure/nativesockets.nim @@ -548,14 +548,37 @@ proc pruneSocketSet(s: var seq[SocketHandle], fd: var TFdSet) = inc(i) setLen(s, L) -proc select*(readfds: var seq[SocketHandle], timeout = 500): int = - ## Traditional select function. This function will return the number of - ## sockets that are ready to be read from, written to, or which have errors. - ## If there are none; 0 is returned. - ## ``Timeout`` is in milliseconds and -1 can be specified for no timeout. +proc select*(readfds: var seq[SocketHandle], timeout = 500): int {.deprecated.} = + ## When a socket in ``readfds`` is ready to be read from then a non-zero + ## value will be returned specifying the count of the sockets which can be + ## read from. The sockets which can be read from will also be removed + ## from ``readfds``. ## - ## A socket is removed from the specific ``seq`` when it has data waiting to - ## be read/written to or has errors (``exceptfds``). + ## ``timeout`` is specified in milliseconds and ``-1`` can be specified for + ## an unlimited time. + ## **Warning:** This is deprecated since version 0.16.2. + ## Use the ``selectRead`` procedure instead. + var tv {.noInit.}: Timeval = timeValFromMilliseconds(timeout) + + var rd: TFdSet + var m = 0 + createFdSet((rd), readfds, m) + + if timeout != -1: + result = int(select(cint(m+1), addr(rd), nil, nil, addr(tv))) + else: + result = int(select(cint(m+1), addr(rd), nil, nil, nil)) + + pruneSocketSet(readfds, (rd)) + +proc selectRead*(readfds: var seq[SocketHandle], timeout = 500): int = + ## When a socket in ``readfds`` is ready to be read from then a non-zero + ## value will be returned specifying the count of the sockets which can be + ## read from. The sockets which can be read from will also be removed + ## from ``readfds``. + ## + ## ``timeout`` is specified in milliseconds and ``-1`` can be specified for + ## an unlimited time. var tv {.noInit.}: Timeval = timeValFromMilliseconds(timeout) var rd: TFdSet |