workaround segfault (need to investigate later)
This commit is contained in:
parent
e23457a647
commit
6f75ffb35c
|
@ -91,6 +91,7 @@ proc asyncSendMsg*(fd: AsyncFD, data: string,
|
|||
cmsgHeader.cmsg_type = cmsg.msgType.int32
|
||||
copyMem(CMSG_DATA(cmsgHeader), cmsg.data.cstring, cmsg.data.len)
|
||||
cmsgHeader = CMSG_NXTHDR(addr msg, cmsgHeader)
|
||||
echo "cmsgHeader = ", cast[int](cmsgHeader)
|
||||
|
||||
let res = sendmsg(sock.SocketHandle, addr msg, 0)
|
||||
if res < 0:
|
||||
|
|
|
@ -79,12 +79,14 @@ proc handlePunchdMessages(conn: PunchdConnection) {.async.} =
|
|||
let fd = conn.sock.getFd.AsyncFD
|
||||
let resp = await fd.asyncRecvMsg(size = 400, cmsgSize = sizeof(AsyncFD))
|
||||
let line = resp.data.strip(leading = false, trailing = true, chars = {'\n'})
|
||||
echo "received punchd message: ", line
|
||||
let args = line.parseArgs(3, 1)
|
||||
case args[0]:
|
||||
of "ok":
|
||||
let outMsg = conn.outMessages[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")
|
||||
let sock = newAsyncSocket(resp.cmsgs[0].getFd)
|
||||
register(sock.getFd.AsyncFD)
|
||||
|
|
|
@ -104,7 +104,9 @@ proc main() =
|
|||
except Sigint:
|
||||
for puncher in punchd.punchers:
|
||||
waitFor puncher.cleanup()
|
||||
punchd.unixSocket.close()
|
||||
removeFile(PunchdSocket)
|
||||
quit(0)
|
||||
|
||||
when isMainModule:
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue