From 629556ad307f7beed2781e3b7eef4d983743a30f Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Tue, 7 Jul 2020 19:36:44 +0200 Subject: [PATCH] add fromFd to asyncutils --- asyncutils.nim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/asyncutils.nim b/asyncutils.nim index 394c776..f00fbe7 100644 --- a/asyncutils.nim +++ b/asyncutils.nim @@ -18,6 +18,8 @@ from posix import CMSG_NXTHDR, CMSG_LEN, CMSG_DATA, + SOL_SOCKET, + SCM_RIGHTS, sendmsg, recvmsg @@ -39,6 +41,12 @@ type ControlMessage* = object msgType*: int data*: string +proc fromFd*(fd: AsyncFD): ControlMessage = + result = ControlMessage(level: SOL_SOCKET, + msgType: SCM_RIGHTS, + data: newString(sizeof(AsyncFD))) + cast[ptr AsyncFD](result.data.cstring)[] = fd + proc asyncSendMsg*(fd: AsyncFD, data: string, cmsgs: seq[ControlMessage] = @[]): Future[void] = var retFuture = newFuture[void]("asyncSendMsg")