about summary refs log tree commit diff stats
path: root/src/ips
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-31 14:24:57 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-31 14:24:57 +0100
commit1c61efbcba2e4d28f92ad82c1eb0bb09a4cfcf5b (patch)
tree63f4f12d2fe9204c60f19e07a2b6e41de8bc18a6 /src/ips
parentdef9c92cc0ed2cf06684b19e779e54eef9fa502e (diff)
downloadchawan-1c61efbcba2e4d28f92ad82c1eb0bb09a4cfcf5b.tar.gz
NOW it should work
Diffstat (limited to 'src/ips')
-rw-r--r--src/ips/socketstream.nim13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ips/socketstream.nim b/src/ips/socketstream.nim
index a2f80f01..5a030427 100644
--- a/src/ips/socketstream.nim
+++ b/src/ips/socketstream.nim
@@ -58,8 +58,11 @@ proc sockClose(s: Stream) = {.cast(tags: []).}: #...sigh
 proc sendFileHandle*(s: SocketStream, fd: FileHandle) =
   var hdr: Tmsghdr
   var iov: IOVec
-  let space = CMSG_SPACE(csize_t(sizeof(FileHandle)))
-  var cmsgbuf = alloc(space)
+  var space: csize_t
+  {.emit: [
+  space, """ = CMSG_SPACE(sizeof(int));""",
+  ].}
+  var cmsgbuf = alloc(cast[int](space))
   var buf = char(0)
   iov.iov_base = addr buf
   iov.iov_len = csize_t(1)
@@ -67,13 +70,15 @@ proc sendFileHandle*(s: SocketStream, fd: FileHandle) =
   hdr.msg_iov = addr iov
   hdr.msg_iovlen = 1
   hdr.msg_control = cmsgbuf
-  let cmsg = CMSG_FIRSTHDR(addr hdr)
   # ...sigh
+  {.emit: [
+  hdr.msg_controllen, """ = CMSG_LEN(sizeof(int));""",
+  ].}
+  let cmsg = CMSG_FIRSTHDR(addr hdr)
   # 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