diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-03-30 11:14:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 20:14:39 +0200 |
commit | 72988509ba0859a5bdfb43a78273c2de26c3d6dc (patch) | |
tree | a996b9afc2120a0d63cae92b0106cb1176c546d9 /testament | |
parent | 5ecbe6737110bd3fb9a85c2582409483fb5494b0 (diff) | |
download | Nim-72988509ba0859a5bdfb43a78273c2de26c3d6dc.tar.gz |
add getPort to resolve Port(0) (#17559)
* add getPort to resolve Port(0) * fixup * use getPort in examples + tests * address comments: do not re-export Port
Diffstat (limited to 'testament')
-rw-r--r-- | testament/lib/stdtest/netutils.nim | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/testament/lib/stdtest/netutils.nim b/testament/lib/stdtest/netutils.nim index eb913a56a..5115390e0 100644 --- a/testament/lib/stdtest/netutils.nim +++ b/testament/lib/stdtest/netutils.nim @@ -1,6 +1,7 @@ import std/[nativesockets, asyncdispatch, os] proc bindAvailablePort*(handle: SocketHandle, port = Port(0)): Port = + ## See also `asynchttpserver.getPort`. block: var name: Sockaddr_in name.sin_family = typeof(name.sin_family)(toInt(AF_INET)) @@ -8,5 +9,5 @@ proc bindAvailablePort*(handle: SocketHandle, port = Port(0)): Port = name.sin_addr.s_addr = htonl(INADDR_ANY) if bindAddr(handle, cast[ptr SockAddr](addr(name)), sizeof(name).Socklen) < 0'i32: - raiseOSError(osLastError()) + raiseOSError(osLastError(), $port) result = getLocalAddr(handle, AF_INET)[1] |