Provide access to getsockname()/getpeername()
Port of #3323 with added tests
This commit is contained in:
parent
a0fb77dfd5
commit
d8ff25f032
2 changed files with 16 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue