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")