diff --git a/asyncutils.nim b/asyncutils.nim index 51baf95..e051f8b 100644 --- a/asyncutils.nim +++ b/asyncutils.nim @@ -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: diff --git a/examples/app/app.nim b/examples/app/app.nim index 049e02d..08f8cac 100644 --- a/examples/app/app.nim +++ b/examples/app/app.nim @@ -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) diff --git a/punchd.nim b/punchd.nim index 9944819..8da9654 100644 --- a/punchd.nim +++ b/punchd.nim @@ -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()