fix compilation on arm64
This commit is contained in:
parent
a6d14a3b06
commit
a1fbc27c54
|
@ -13,6 +13,7 @@ from posix import
|
|||
Tmsghdr,
|
||||
Tcmsghdr,
|
||||
SocketHandle,
|
||||
SockLen,
|
||||
CMSG_SPACE,
|
||||
CMSG_FIRSTHDR,
|
||||
CMSG_NXTHDR,
|
||||
|
@ -67,8 +68,13 @@ proc asyncSendMsg*(fd: AsyncFD, data: string,
|
|||
# sendmsg needs an array of iovec structs as described in the writev(2) man
|
||||
# page. The message is passed as a msghdr struct which may contain ancillary
|
||||
# data, see sendmsg(2) man page.
|
||||
# TODO: remove the when clause once issue https://github.com/nim-lang/Nim/issues/15197 is solved.
|
||||
when (defined(linux) and not defined(android)) and defined(amd64):
|
||||
var iovec = IOVec(iov_base: data.cstring,
|
||||
iov_len: data.len.csize_t)
|
||||
else:
|
||||
var iovec = IOVec(iov_base: data.cstring,
|
||||
iov_len: data.len)
|
||||
var msg = Tmsghdr(msg_iov: addr iovec,
|
||||
msg_iovlen: 1)
|
||||
var cmsgBuf: string
|
||||
|
@ -77,10 +83,10 @@ proc asyncSendMsg*(fd: AsyncFD, data: string,
|
|||
let cmsgBufLen = cmsgs.map(space).foldl(a + b, 0.csize_t)
|
||||
cmsgBuf = newString(cmsgBufLen)
|
||||
msg.msg_control = cmsgBuf.cstring
|
||||
msg.msg_controllen = cmsgBufLen
|
||||
msg.msg_controllen = cmsgBufLen.SockLen
|
||||
var cmsgHeader = CMSG_FIRSTHDR(addr msg)
|
||||
for cmsg in cmsgs:
|
||||
cmsgHeader.cmsg_len = CMSG_LEN(cmsg.data.len.csize_t)
|
||||
cmsgHeader.cmsg_len = CMSG_LEN(cmsg.data.len.csize_t).SockLen
|
||||
cmsgHeader.cmsg_level = cmsg.level.int32
|
||||
cmsgHeader.cmsg_type = cmsg.msgType.int32
|
||||
copyMem(CMSG_DATA(cmsgHeader), cmsg.data.cstring, cmsg.data.len)
|
||||
|
|
|
@ -12,6 +12,7 @@ from posix import
|
|||
Tmsghdr,
|
||||
Tcmsghdr,
|
||||
SocketHandle,
|
||||
SockLen,
|
||||
CMSG_FIRSTHDR,
|
||||
CMSG_NXTHDR,
|
||||
CMSG_DATA,
|
||||
|
@ -42,14 +43,19 @@ proc asyncRecvMsg*(fd: AsyncFD, size: int = BufferSize,
|
|||
result = true
|
||||
|
||||
var dataBuffer = newString(size)
|
||||
# TODO: remove the when clause once issue https://github.com/nim-lang/Nim/issues/15197 is solved.
|
||||
when (defined(linux) and not defined(android)) and defined(amd64):
|
||||
var iovec = IOVec(iov_base: dataBuffer.cstring,
|
||||
iov_len: dataBuffer.len.csize_t)
|
||||
else:
|
||||
var iovec = IOVec(iov_base: dataBuffer.cstring,
|
||||
iov_len: dataBuffer.len)
|
||||
var cmsgBuffer = newString(cmsgSize)
|
||||
zeroMem(cmsgBuffer.cstring, cmsgBuffer.len)
|
||||
var msg = Tmsghdr(msg_iov: addr iovec,
|
||||
msg_iovlen: 1,
|
||||
msg_control: addr cmsgBuffer[0],
|
||||
msg_controllen: cmsgSize.csize_t)
|
||||
msg_controllen: cmsgSize.SockLen)
|
||||
|
||||
let res = recvmsg(sock.SocketHandle, addr msg, 0)
|
||||
if res < 0:
|
||||
|
|
Loading…
Reference in New Issue