Provide access to getsockname()/getpeername().
This patch implements procedures getLocalAddr() and getPeerAddr() that return the results of getsockname() and getpeername(), respectively, as pairs (string, Port) for both Socket and SockedHandle.
This commit is contained in:
parent
148bbee05f
commit
b9df1323f7
2 changed files with 74 additions and 0 deletions
|
|
@ -533,6 +533,14 @@ proc getSockOpt*(socket: Socket, opt: SOBool, level = SOL_SOCKET): bool {.
|
|||
var res = getSockOptInt(socket.fd, cint(level), toCInt(opt))
|
||||
result = res != 0
|
||||
|
||||
proc getLocalAddr*(socket: Socket): (string, Port) =
|
||||
## Get the socket's local address and port number
|
||||
getLocalAddr(socket.fd, socket.domain)
|
||||
|
||||
proc getPeerAddr*(socket: Socket): (string, Port) =
|
||||
## Get the socket's peer address and port number
|
||||
getPeerAddr(socket.fd, socket.domain)
|
||||
|
||||
proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {.
|
||||
tags: [WriteIOEffect].} =
|
||||
## Sets option ``opt`` to a boolean value specified by ``value``.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue