diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-31 14:05:41 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-31 14:05:41 +0100 |
commit | 7b6a2c6d4d1d055953d1e72ca6096490f368f922 (patch) | |
tree | b62a763e349df0e77b2ed508bcc50b4c08036518 /src/ips | |
parent | e9cc4edbb3695651b0abd7e33e40d942ad98ab2a (diff) | |
download | chawan-7b6a2c6d4d1d055953d1e72ca6096490f368f922.tar.gz |
posixstream/socketstream: fix cross-platform compilation
Diffstat (limited to 'src/ips')
-rw-r--r-- | src/ips/socketstream.nim | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/ips/socketstream.nim b/src/ips/socketstream.nim index e934e7fc..87fcb4e4 100644 --- a/src/ips/socketstream.nim +++ b/src/ips/socketstream.nim @@ -34,14 +34,7 @@ proc sockReadData(s: Stream, buffer: pointer, len: int): int = s.isend = true raise newException(EOFError, "eof") if result < 0: - if errno == EAGAIN: - raise newException(ErrorAgain, "eagain") - case errno - of EWOULDBLOCK: raise newException(ErrorWouldBlock, "would block") - of EBADF: raise newException(ErrorBadFD, "bad fd") - of EFAULT: raise newException(ErrorFault, "fault") - of EINVAL: raise newException(ErrorInvalid, "invalid") - else: raise newException(IOError, $strerror(errno)) + raisePosixIOError() elif result == 0: s.isend = true @@ -73,10 +66,13 @@ proc sendFileHandle*(s: SocketStream, fd: FileHandle) = hdr.msg_iov = addr iov hdr.msg_iovlen = 1 hdr.msg_control = cmsgbuf - hdr.msg_controllen = CMSG_LEN(csize_t(sizeof(FileHandle))) let cmsg = CMSG_FIRSTHDR(addr hdr) # ...sigh + # FileHandle is cint, so sizeof(FileHandle) in c is sizeof(int). + when sizeof(FileHandle) != sizeof(cint): + error("Or not...") {.emit: [ + hdr.msg_controllen, """ = CMSG_LEN(sizeof(int));""", cmsg.cmsg_len, """ = CMSG_LEN(sizeof(int));""" ].} cmsg.cmsg_level = SOL_SOCKET @@ -89,16 +85,17 @@ proc sendFileHandle*(s: SocketStream, fd: FileHandle) = proc recvFileHandle*(s: SocketStream): FileHandle = var iov: IOVec var hdr: Tmsghdr - let space = CMSG_SPACE(csize_t(sizeof(FileHandle))) var buf: char - var cmsgbuf = alloc(space) + var cmsgbuf = alloc(CMSG_SPACE(csize_t(sizeof(FileHandle)))) iov.iov_base = addr buf iov.iov_len = 1 zeroMem(addr hdr, sizeof(hdr)) hdr.msg_iov = addr iov hdr.msg_iovlen = 1 hdr.msg_control = cmsgbuf - hdr.msg_controllen = space + {.emit: [ + hdr.msg_controllen, """ = CMSG_SPACE(sizeof(int));""" + ].} let n = recvmsg(s.source.getFd(), addr hdr, 0) assert n != 0, "Unexpected EOF" #TODO remove this assert n > 0, "Failed to receive message " & $osLastError() #TODO remove this |