Skip to content

Commit

Permalink
compatibility improvements (#34)
Browse files Browse the repository at this point in the history
* compatibility improvements
* fixed asyncpipe on Windows
* fixes asyncproc for --gc:orc on Windows
  • Loading branch information
Araq committed Jul 6, 2021
1 parent 130cad6 commit 84ced6d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
17 changes: 11 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 @@ -177,6 +177,11 @@ when defined(windows):
((number shr 16) and 0xFFFF).Word xor
(number and 0xFFFF).Word

when declared(system.csize_t):
type SizeAlias = system.csize_t
else:
type SizeAlias = system.int

proc asyncGetAddrInfo*(address: string, port: Port,
domain: Domain = nativesockets.AF_INET,
sockType: SockType = nativesockets.SOCK_STREAM,
Expand Down Expand Up @@ -294,10 +299,10 @@ when defined(windows):
addrArr[ai].ai_family = toInt(domain)
addrArr[ai].ai_socktype = toInt(sockType)
addrArr[ai].ai_protocol = toInt(protocol)
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in)
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in).SizeAlias
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 @@ -307,10 +312,10 @@ when defined(windows):
addrArr[ai].ai_family = toInt(domain)
addrArr[ai].ai_socktype = toInt(sockType)
addrArr[ai].ai_protocol = toInt(protocol)
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in6)
addrArr[ai].ai_addrlen = sizeof(Sockaddr_in6).SizeAlias
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
11 changes: 10 additions & 1 deletion asynctools/asyncipc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ elif defined(windows):
import winlean
import sets, hashes # this import only for HackDispatcher

when not declared(PCustomOverlapped):
type
PCustomOverlapped = CustomRef

const
mapHeaderName = "asyncipc_"
eventHeaderName = "asyncpipc_"
Expand Down Expand Up @@ -245,7 +249,12 @@ elif defined(windows):
discard closeHandle(eventChange)
raiseOSError(err)

data = mapViewOfFileEx(handleMap, FILE_MAP_WRITE, 0, 0, size, nil)
when declared(WinSizeT):
let sizeB = size.WinSizeT
else:
let sizeB = size

data = mapViewOfFileEx(handleMap, FILE_MAP_WRITE, 0, 0, sizeB, nil)
if data == nil:
let err = osLastError()
discard closeHandle(handleMap)
Expand Down
4 changes: 4 additions & 0 deletions asynctools/asyncpipe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ else:
proc connectNamedPipe(hNamedPipe: Handle, lpOverlapped: pointer): WINBOOL
{.importc: "ConnectNamedPipe", stdcall, dynlib: "kernel32".}

when not declared(PCustomOverlapped):
type
PCustomOverlapped = CustomRef

const
pipeHeaderName = r"\\.\pipe\asyncpipe_"

Expand Down
2 changes: 1 addition & 1 deletion asynctools/asyncproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ when defined(windows):

var tmp = newWideCString(cmdl)
var ee =
if e.str.isNil: nil
if e.str.isNil: newWideCString(cstring(nil))
else: newWideCString(e.str, e.len)
var wwd = newWideCString(wd)
var flags = NORMAL_PRIORITY_CLASS or CREATE_UNICODE_ENVIRONMENT
Expand Down
6 changes: 3 additions & 3 deletions asynctools/asyncsync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ type
queue: Deque[T]
maxsize: int

AsyncQueueEmptyError* = object of Exception
AsyncQueueEmptyError* = object of CatchableError
## ``AsyncQueue`` is empty.
AsyncQueueFullError* = object of Exception
AsyncQueueFullError* = object of CatchableError
## ``AsyncQueue`` is full.
AsyncLockError* = object of Exception
AsyncLockError* = object of CatchableError
## ``AsyncLock`` is either locked or unlocked.

proc newAsyncLock*(): AsyncLock =
Expand Down

0 comments on commit 84ced6d

Please sign in to comment.