Provide access to getsockname()/getpeername()

Port of #3323 with added tests
This commit is contained in:
Federico Ceratto 2019-02-13 19:57:25 +00:00 • committed by Dominik Picheta
commit d8ff25f032
2 changed files with 16 additions and 0 deletions

View file

@ -26,6 +26,10 @@ proc launchSwarm(port: Port) {.async.} =
proc readMessages(client: AsyncFD) {.async.} =
# wrapping the AsyncFd into a AsyncSocket object
var sockObj = newAsyncSocket(client)
var (ipaddr, port) = sockObj.getPeerAddr()
doAssert ipaddr == "127.0.0.1"
(ipaddr, port) = sockObj.getLocalAddr()
doAssert ipaddr == "127.0.0.1"
while true:
var line = await recvLine(sockObj)
if line == "":