From d8ff25f03250556c3ed99dbb7ad65d1cc627e1d3 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Wed, 13 Feb 2019 19:57:25 +0000 Subject: Provide access to getsockname()/getpeername() Port of #3323 with added tests --- lib/pure/asyncnet.nim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/pure') diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index 1c0681fad..56bda737a 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -166,6 +166,18 @@ proc newAsyncSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM, raiseOSError(osLastError()) result = newAsyncSocket(fd, domain, sockType, protocol, buffered) +proc getLocalAddr*(socket: AsyncSocket): (string, Port) = + ## Get the socket's local address and port number. + ## + ## This is high-level interface for `getsockname`:idx:. + getLocalAddr(socket.fd, socket.domain) + +proc getPeerAddr*(socket: AsyncSocket): (string, Port) = + ## Get the socket's peer address and port number. + ## + ## This is high-level interface for `getpeername`:idx:. + getPeerAddr(socket.fd, socket.domain) + proc newAsyncSocket*(domain, sockType, protocol: cint, buffered = true): AsyncSocket = ## Creates a new asynchronous socket. -- cgit 1.4.1-2-gfad0