workaround segfault (need to investigate later)

This commit is contained in:
Christian Ulrich 2020-08-22 13:11:55 +02:00
parent e23457a647
commit 6f75ffb35c
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
3 changed files with 6 additions and 1 deletions

View File

@ -91,6 +91,7 @@ proc asyncSendMsg*(fd: AsyncFD, data: string,
cmsgHeader.cmsg_type = cmsg.msgType.int32 cmsgHeader.cmsg_type = cmsg.msgType.int32
copyMem(CMSG_DATA(cmsgHeader), cmsg.data.cstring, cmsg.data.len) copyMem(CMSG_DATA(cmsgHeader), cmsg.data.cstring, cmsg.data.len)
cmsgHeader = CMSG_NXTHDR(addr msg, cmsgHeader) cmsgHeader = CMSG_NXTHDR(addr msg, cmsgHeader)
echo "cmsgHeader = ", cast[int](cmsgHeader)
let res = sendmsg(sock.SocketHandle, addr msg, 0) let res = sendmsg(sock.SocketHandle, addr msg, 0)
if res < 0: if res < 0:

View File

@ -79,12 +79,14 @@ proc handlePunchdMessages(conn: PunchdConnection) {.async.} =
let fd = conn.sock.getFd.AsyncFD let fd = conn.sock.getFd.AsyncFD
let resp = await fd.asyncRecvMsg(size = 400, cmsgSize = sizeof(AsyncFD)) let resp = await fd.asyncRecvMsg(size = 400, cmsgSize = sizeof(AsyncFD))
let line = resp.data.strip(leading = false, trailing = true, chars = {'\n'}) let line = resp.data.strip(leading = false, trailing = true, chars = {'\n'})
echo "received punchd message: ", line
let args = line.parseArgs(3, 1) let args = line.parseArgs(3, 1)
case args[0]: case args[0]:
of "ok": of "ok":
let outMsg = conn.outMessages[args[1]] let outMsg = conn.outMessages[args[1]]
conn.outMessages.del(args[1]) conn.outMessages.del(args[1])
if resp.cmsgs.len != 1: if resp.cmsgs.len < 1:
echo "no cmsg"
raise newException(ValueError, "invalid punchd message") raise newException(ValueError, "invalid punchd message")
let sock = newAsyncSocket(resp.cmsgs[0].getFd) let sock = newAsyncSocket(resp.cmsgs[0].getFd)
register(sock.getFd.AsyncFD) register(sock.getFd.AsyncFD)

View File

@ -104,7 +104,9 @@ proc main() =
except Sigint: except Sigint:
for puncher in punchd.punchers: for puncher in punchd.punchers:
waitFor puncher.cleanup() waitFor puncher.cleanup()
punchd.unixSocket.close()
removeFile(PunchdSocket) removeFile(PunchdSocket)
quit(0)
when isMainModule: when isMainModule:
main() main()