remove unneeded procs

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

View File

@ -1,6 +1,4 @@
import asyncdispatch, threadpool, osproc
from net import
BufferSize
from os import
osLastError,
newOsError
@ -23,20 +21,6 @@ from posix import
sendmsg,
recvmsg
## asyncReadline as discussed at https://github.com/nim-lang/Nim/issues/11564
proc asyncReadline*(): Future[string] =
let event = newAsyncEvent()
let future = newFuture[string]("asyncReadline")
proc readlineBackground(event: AsyncEvent): string =
result = stdin.readline()
event.trigger()
let flowVar = spawn readlineBackground(event)
proc callback(fd: AsyncFD): bool =
future.complete(^flowVar)
true
addEvent(event, callback)
return future
proc asyncExecCmd*(command: string): Future[int] =
let event = newAsyncEvent()
let future = newFuture[int]("asyncExecCmd")
@ -98,50 +82,3 @@ proc asyncSendMsg*(fd: AsyncFD, data: string,
addWrite(fd, cb)
return retFuture
proc asyncRecvMsg*(fd: AsyncFD, size: int = BufferSize,
cmsgSize: int = BufferSize):
Future[tuple[data: string, cmsgs: seq[ControlMessage]]] =
var retFuture = newFuture[tuple[data: string,
cmsgs: seq[ControlMessage]]]("asyncRecvMsg")
proc cb(sock: AsyncFD): bool =
result = true
var dataBuffer = newString(size)
var iovec = IOVec(iov_base: dataBuffer.cstring,
iov_len: dataBuffer.len.csize_t)
var cmsgBuffer = newString(cmsgSize)
zeroMem(cmsgBuffer.cstring, cmsgBuffer.len)
var msg = Tmsghdr(msg_iov: addr iovec,
msg_iovlen: 1,
msg_control: addr cmsgBuffer[0],
msg_controllen: cmsgSize.csize_t)
let res = recvmsg(sock.SocketHandle, addr msg, 0)
if res < 0:
let lastError = osLastError()
if lastError.int32 != EINTR and
lastError.int32 != EWOULDBLOCK and
lastError.int32 != EAGAIN:
retFuture.fail(newOSError(lastError))
else:
result = false
return
var cmsgs = newSeq[ControlMessage]()
var cmsgHeader = CMSG_FIRSTHDR(addr msg)
while cmsgHeader != nil:
let dataLen = cmsgHeader.cmsg_len - sizeof(Tcmsghdr).csize_t
var cmsg = ControlMessage(level: cmsgHeader.cmsg_level,
msgType: cmsgHeader.cmsg_type,
data: newString(dataLen))
copyMem(cmsg.data.cstring, CMSG_DATA(cmsgHeader), cmsgHeader.cmsg_len)
cmsgs.add(cmsg)
cmsgHeader = CMSG_NXTHDR(addr msg, cmsgHeader)
dataBuffer.setLen(res)
retFuture.complete((dataBuffer, cmsgs))
addRead(fd, cb)
return retFuture