diff --git a/examples/app/app.nim b/examples/app/app.nim index 08f8cac..2967f86 100644 --- a/examples/app/app.nim +++ b/examples/app/app.nim @@ -1,6 +1,7 @@ import asyncdispatch, asyncnet, os, strformat, strutils, tables from nativeSockets import Domain, SockType, Protocol from net import IpAddress, Port, isIpAddress, `$` +from posix import CMSG_SPACE import asyncutils import ../../message import random @@ -77,7 +78,8 @@ proc handleServerMessages(conn: ServerConnection) {.async.} = proc handlePunchdMessages(conn: PunchdConnection) {.async.} = while true: let fd = conn.sock.getFd.AsyncFD - let resp = await fd.asyncRecvMsg(size = 400, cmsgSize = sizeof(AsyncFD)) + let cmsgSize = CMSG_SPACE(sizeof(AsyncFD).csize_t) + let resp = await fd.asyncRecvMsg(400, cmsgSize) let line = resp.data.strip(leading = false, trailing = true, chars = {'\n'}) echo "received punchd message: ", line let args = line.parseArgs(3, 1) diff --git a/examples/app/asyncutils.nim b/examples/app/asyncutils.nim index 1f3d3e8..793d540 100644 --- a/examples/app/asyncutils.nim +++ b/examples/app/asyncutils.nim @@ -34,7 +34,7 @@ proc getFd*(cmsg: ControlMessage): AsyncFD = result = cast[ptr AsyncFD](cmsg.data.cstring)[] proc asyncRecvMsg*(fd: AsyncFD, size: int = BufferSize, - cmsgSize: int = BufferSize): + cmsgSize: csize_t = BufferSize.csize_t): Future[tuple[data: string, cmsgs: seq[ControlMessage]]] = var retFuture = newFuture[tuple[data: string, cmsgs: seq[ControlMessage]]]("asyncRecvMsg") @@ -55,7 +55,7 @@ proc asyncRecvMsg*(fd: AsyncFD, size: int = BufferSize, var msg = Tmsghdr(msg_iov: addr iovec, msg_iovlen: 1, msg_control: addr cmsgBuffer[0], - msg_controllen: cmsgSize.SockLen) + msg_controllen: cmsgBuffer.len.SockLen) let res = recvmsg(sock.SocketHandle, addr msg, 0) if res < 0: