Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions asynctools/asyncdns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#

## This module implements asynchronous DNS resolve mechanism.
##
##
## asyncGetAddrInfo() don't have support for `flags` argument.
##
##
## Supported platforms: Linux, Windows, MacOS, FreeBSD, NetBSD, OpenBSD(*),
## Solaris.
##
Expand Down Expand Up @@ -297,7 +297,7 @@ when defined(windows):
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in)
addrArr[ai].ai_addr = addr sockArr[ai]
var addrp = cast[ptr Sockaddr_in](addr sockArr[ai])
addrp.sin_family = toInt(domain).int16
addrp.sin_family = toInt(domain).uint16
addrp.sin_port = nativesockets.ntohs(cast[uint16](port))
copyMem(addr addrp.sin_addr, addr rec.data, 4)
if k + 1 < count:
Expand All @@ -310,7 +310,7 @@ when defined(windows):
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in6)
addrArr[ai].ai_addr = addr sockArr[ai]
var addrp = cast[ptr Sockaddr_in6](addr sockArr[ai])
addrp.sin6_family = toInt(domain).int16
addrp.sin6_family = toInt(domain).uint16
addrp.sin6_port = nativesockets.ntohs(cast[uint16](port))
copyMem(addr addrp.sin6_addr, addr rec.data, 4 * 4)
if k + 1 < count:
Expand Down Expand Up @@ -658,7 +658,7 @@ else:
psin_len[] = cast[uint8](sizeof(Sockaddr_in))

var addrp = cast[ptr Sockaddr_in](addr sockArr[ai])
addrp.sin_family = toInt(domain)
addrp.sin_family = toInt(domain).uint16
addrp.sin_port = nativesockets.ntohs(cast[uint16](port))
copyMem(addr addrp.sin_addr, record.rdata, 4)
if k + 1 < count:
Expand All @@ -678,7 +678,7 @@ else:
psin_len[] = cast[uint8](sizeof(Sockaddr_in6))

var addrp = cast[ptr Sockaddr_in6](addr sockArr[ai])
addrp.sin6_family = toInt(domain)
addrp.sin6_family = toInt(domain).uint16
addrp.sin6_port = nativesockets.ntohs(cast[uint16](port))
copyMem(addr addrp.sin6_addr, record.rdata, 4 * 4)
if k + 1 < count:
Expand Down
19 changes: 19 additions & 0 deletions asynctools/asyncpipe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,24 @@ else:
addRead(AsyncFD(pipe.readPipe), cb)
return retFuture

# high level methods that wrap both win and linux low level methods

proc write*(pipe: AsyncPipe, data: string): Future[int] =
## This procedure writes an string ``data``to the
## pipe ``pipe``.
pipe.write(unsafeAddr data[0], data.len)

proc read*(pipe: AsyncPipe): Future[string] {.async.} =
## This procedure reads an string out of the ``pipe``.
## Returns when pipe closes.
var buffer = newString(1024*4)
while true:
var bytesReady = await pipe.readInto(unsafeAddr buffer[0], buffer.len)
if bytesReady <= 0:
break
buffer.setLen(bytesReady)
result.add buffer

when isMainModule:

when not defined(windows):
Expand Down Expand Up @@ -530,3 +548,4 @@ when isMainModule:
doAssert(res.count == testsCount)
doAssert(res.sum == testsCount * (1 + testsCount) div 2)