Added basic AF_UNIX support to asyncnet.

Unfortunately this required some code duplication because the
doConnect() from asynccommon.nim only works with addrInfo which does not
make sense for AF_UNIX.

makeUnixAddr() was moved to nativesocket.nim and exported
This commit is contained in:
Ico Doornekamp 2018-12-05 09:52:57 +01:00
commit 71e9fff364
3 changed files with 66 additions and 7 deletions

View file

@ -947,13 +947,6 @@ proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {
var valuei = cint(if value: 1 else: 0)
setSockOptInt(socket.fd, cint(level), toCInt(opt), valuei)
when defined(posix) and not defined(nimdoc):
proc makeUnixAddr(path: string): Sockaddr_un =
result.sun_family = AF_UNIX.uint16
if path.len >= Sockaddr_un_path_length:
raise newException(ValueError, "socket path too long")
copyMem(addr result.sun_path, path.cstring, path.len + 1)
when defined(posix) or defined(nimdoc):
proc connectUnix*(socket: Socket, path: string) =
## Connects to Unix socket on `path`.