add fromFd to asyncutils

This commit is contained in:
Christian Ulrich 2020-07-07 19:36:44 +02:00
parent b6f28037a0
commit 629556ad30
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 8 additions and 0 deletions

View File

@ -18,6 +18,8 @@ from posix import
CMSG_NXTHDR, CMSG_NXTHDR,
CMSG_LEN, CMSG_LEN,
CMSG_DATA, CMSG_DATA,
SOL_SOCKET,
SCM_RIGHTS,
sendmsg, sendmsg,
recvmsg recvmsg
@ -39,6 +41,12 @@ type ControlMessage* = object
msgType*: int msgType*: int
data*: string 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, proc asyncSendMsg*(fd: AsyncFD, data: string,
cmsgs: seq[ControlMessage] = @[]): Future[void] = cmsgs: seq[ControlMessage] = @[]): Future[void] =
var retFuture = newFuture[void]("asyncSendMsg") var retFuture = newFuture[void]("asyncSendMsg")