Fix import poison regression. (#388)

* Initial commit.

* One more linux fix.

* Eliminate posix from asyncloop.

* Fix Linux warnings.

* Fix MacOS issues.

* Fix BSD issues.

* Fix comma.

* Fix Windows issues.
This commit is contained in:
Eugene Kabanov 2023-05-15 19:45:26 +03:00 committed by GitHub
parent 8aa8ee8822
commit 956ae5af55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 279 additions and 234 deletions

View File

@ -16,7 +16,7 @@ else:
from nativesockets import Port from nativesockets import Port
import std/[tables, strutils, heapqueue, options, deques] import std/[tables, strutils, heapqueue, options, deques]
import stew/results import stew/results
import "."/[config, osdefs, osutils, timer] import "."/[config, osdefs, oserrno, osutils, timer]
export Port export Port
export timer, results export timer, results
@ -152,11 +152,6 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
defined(openbsd) or defined(dragonfly) or defined(macos) or defined(openbsd) or defined(dragonfly) or defined(macos) or
defined(linux) or defined(android) or defined(solaris): defined(linux) or defined(android) or defined(solaris):
import "."/selectors2 import "."/selectors2
import "."/oserrno
from posix import MSG_PEEK, MSG_NOSIGNAL,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE
export SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, export SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2, SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE SIGPIPE, SIGALRM, SIGTERM, SIGPIPE
@ -575,7 +570,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
proc globalInit() = proc globalInit() =
# We are ignoring SIGPIPE signal, because we are working with EPIPE. # We are ignoring SIGPIPE signal, because we are working with EPIPE.
posix.signal(cint(SIGPIPE), SIG_IGN) signal(cint(SIGPIPE), SIG_IGN)
proc initAPI(disp: PDispatcher) = proc initAPI(disp: PDispatcher) =
discard discard
@ -635,7 +630,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
if not(isNil(adata.writer.function)): if not(isNil(adata.writer.function)):
newEvents.incl(Event.Write) newEvents.incl(Event.Write)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
loop.selector.updateHandle2(cint(fd), newEvents) loop.selector.updateHandle2(cint(fd), newEvents)
proc removeReader2*(fd: AsyncFD): Result[void, OSErrorCode] = proc removeReader2*(fd: AsyncFD): Result[void, OSErrorCode] =
@ -648,7 +643,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
if not(isNil(adata.writer.function)): if not(isNil(adata.writer.function)):
newEvents.incl(Event.Write) newEvents.incl(Event.Write)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
loop.selector.updateHandle2(cint(fd), newEvents) loop.selector.updateHandle2(cint(fd), newEvents)
proc addWriter2*(fd: AsyncFD, cb: CallbackFunc, proc addWriter2*(fd: AsyncFD, cb: CallbackFunc,
@ -663,7 +658,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
if not(isNil(adata.reader.function)): if not(isNil(adata.reader.function)):
newEvents.incl(Event.Read) newEvents.incl(Event.Read)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
loop.selector.updateHandle2(cint(fd), newEvents) loop.selector.updateHandle2(cint(fd), newEvents)
proc removeWriter2*(fd: AsyncFD): Result[void, OSErrorCode] = proc removeWriter2*(fd: AsyncFD): Result[void, OSErrorCode] =
@ -676,7 +671,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
if not(isNil(adata.reader.function)): if not(isNil(adata.reader.function)):
newEvents.incl(Event.Read) newEvents.incl(Event.Read)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
loop.selector.updateHandle2(cint(fd), newEvents) loop.selector.updateHandle2(cint(fd), newEvents)
proc register*(fd: AsyncFD) {.raises: [Defect, OSError].} = proc register*(fd: AsyncFD) {.raises: [Defect, OSError].} =
@ -743,7 +738,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
else: else:
OSErrorCode(0) OSErrorCode(0)
else: else:
OSErrorCode(osdefs.EBADF) osdefs.EBADF
) )
if not(isNil(aftercb)): aftercb(param) if not(isNil(aftercb)): aftercb(param)
@ -789,7 +784,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
withData(loop.selector, sigfd, adata) do: withData(loop.selector, sigfd, adata) do:
adata.reader = AsyncCallback(function: cb, udata: udata) adata.reader = AsyncCallback(function: cb, udata: udata)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
ok(sigfd) ok(sigfd)
proc addProcess2*(pid: int, cb: CallbackFunc, proc addProcess2*(pid: int, cb: CallbackFunc,
@ -803,7 +798,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
withData(loop.selector, procfd, adata) do: withData(loop.selector, procfd, adata) do:
adata.reader = AsyncCallback(function: cb, udata: udata) adata.reader = AsyncCallback(function: cb, udata: udata)
do: do:
return err(OSErrorCode(osdefs.EBADF)) return err(osdefs.EBADF)
ok(procfd) ok(procfd)
proc removeSignal2*(sigfd: int): Result[void, OSErrorCode] = proc removeSignal2*(sigfd: int): Result[void, OSErrorCode] =

View File

@ -40,7 +40,7 @@ proc getVirtualId[T](s: Selector[T]): SelectResult[int32] =
ok(s.virtualHoles.popLast()) ok(s.virtualHoles.popLast())
else: else:
if s.virtualId == low(int32): if s.virtualId == low(int32):
err(OSErrorCode(EMFILE)) err(EMFILE)
else: else:
dec(s.virtualId) dec(s.virtualId)
ok(s.virtualId) ok(s.virtualId)

View File

@ -10,6 +10,11 @@ import oserrno
export oserrno export oserrno
when defined(windows): when defined(windows):
from std/winlean import Sockaddr_storage, InAddr, In6Addr, Sockaddr_in,
Sockaddr_in6, SockLen, SockAddr, AddrInfo,
SocketHandle
export Sockaddr_storage, InAddr, In6Addr, Sockaddr_in, Sockaddr_in6, SockLen,
SockAddr, AddrInfo, SocketHandle
# Prerequisites for constants # Prerequisites for constants
template WSAIORW*(x, y): untyped = (IOC_INOUT or x or y) template WSAIORW*(x, y): untyped = (IOC_INOUT or x or y)
template WSAIOW*(x, y): untyped = template WSAIOW*(x, y): untyped =
@ -17,49 +22,6 @@ when defined(windows):
((clong(sizeof(int32)) and clong(IOCPARM_MASK)) shl 16) or (x shl 8) or y ((clong(sizeof(int32)) and clong(IOCPARM_MASK)) shl 16) or (x shl 8) or y
type type
Sockaddr_storage* {.final, pure.} = object
ss_family*: uint16
ss_pad1: array[6, byte]
ss_align: int64
ss_pad2: array[112, byte]
InAddr* {.final, pure, union.} = object
s_addr*: uint32
In6Addr* {.final, pure, union.} = object
s_addr*: array[16, byte]
Sockaddr_in* {.final, pure.} = object
sin_family*: uint16
sin_port*: uint16
sin_addr*: InAddr
sin_zero*: array[0..7, char]
Sockaddr_in6* {.final, pure.} = object
sin6_family*: uint16
sin6_port*: uint16
sin6_flowinfo*: uint32
sin6_addr*: In6Addr
sin6_scope_id*: uint32
SockLen* = cuint
SockAddr* {.final, pure.} = object
sa_family*: uint16
sa_data*: array[14, char]
AddrInfo* {.final, pure.} = object
ai_flags*: cint ## Input flags.
ai_family*: cint ## Address family of socket.
ai_socktype*: cint ## Socket type.
ai_protocol*: cint ## Protocol of socket.
ai_addrlen*: csize_t ## Length of socket address.
ai_canonname*: pointer ## Canonical name of service location.
ai_addr*: ptr SockAddr ## Socket address of socket.
ai_next*: ptr AddrInfo ## Pointer to next in list.
SocketHandle* = distinct int
HANDLE* = distinct uint HANDLE* = distinct uint
GUID* {.final, pure.} = object GUID* {.final, pure.} = object
D1*: uint32 D1*: uint32
@ -860,8 +822,43 @@ when defined(windows):
) )
elif defined(macos) or defined(macosx): elif defined(macos) or defined(macosx):
import std/posix from std/posix import close, shutdown, socket, getpeername, getsockname,
export posix recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, getaddrinfo, gai_strerror, getrlimit,
setrlimit, getpid, pthread_sigmask, sigemptyset,
sigaddset, sigismember, fcntl, accept, pipe, write,
signal, read, setsockopt, getsockopt,
Timeval, Timespec, Pid, Mode, Time, Sigset, SockAddr,
SockLen, Sockaddr_storage, Sockaddr_in, Sockaddr_in6,
Sockaddr_un, SocketHandle, AddrInfo, RLimit,
F_GETFL, F_SETFL, F_GETFD, F_SETFD, FD_CLOEXEC,
O_NONBLOCK, SOL_SOCKET, SOCK_RAW, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_ERROR, SO_REUSEADDR,
SO_REUSEPORT, SO_BROADCAST, IPPROTO_IP,
IPV6_MULTICAST_HOPS, SOCK_DGRAM, RLIMIT_NOFILE,
SIG_BLOCK, SIG_UNBLOCK,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
export close, shutdown, socket, getpeername, getsockname,
recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, getaddrinfo, gai_strerror, getrlimit,
setrlimit, getpid, pthread_sigmask, sigemptyset,
sigaddset, sigismember, fcntl, accept, pipe, write,
signal, read, setsockopt, getsockopt,
Timeval, Timespec, Pid, Mode, Time, Sigset, SockAddr,
SockLen, Sockaddr_storage, Sockaddr_in, Sockaddr_in6,
Sockaddr_un, SocketHandle, AddrInfo, RLimit,
F_GETFL, F_SETFL, F_GETFD, F_SETFD, FD_CLOEXEC,
O_NONBLOCK, SOL_SOCKET, SOCK_RAW, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_ERROR, SO_REUSEADDR,
SO_REUSEPORT, SO_BROADCAST, IPPROTO_IP,
IPV6_MULTICAST_HOPS, SOCK_DGRAM, RLIMIT_NOFILE,
SIG_BLOCK, SIG_UNBLOCK,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
type type
MachTimebaseInfo* {.importc: "struct mach_timebase_info", MachTimebaseInfo* {.importc: "struct mach_timebase_info",
@ -879,8 +876,47 @@ elif defined(macos) or defined(macosx):
importc, header: "<mach/mach_time.h>".} importc, header: "<mach/mach_time.h>".}
elif defined(linux): elif defined(linux):
import std/[posix] from std/posix import close, shutdown, sigemptyset, sigaddset, sigismember,
export posix sigdelset, write, read, waitid, getaddrinfo,
gai_strerror, setsockopt, getsockopt, socket,
getrlimit, setrlimit, getpeername, getsockname,
recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, sendmsg, recvmsg, getpid, fcntl,
pthread_sigmask, clock_gettime, signal,
ClockId, Itimerspec, Timespec, Sigset, Time, Pid, Mode,
SigInfo, Id, Tmsghdr, IOVec, RLimit,
SockAddr, SockLen, Sockaddr_storage, Sockaddr_in,
Sockaddr_in6, Sockaddr_un, AddrInfo, SocketHandle,
CLOCK_MONOTONIC, F_GETFL, F_SETFL, F_GETFD, F_SETFD,
FD_CLOEXEC, O_NONBLOCK, SIG_BLOCK, SIG_UNBLOCK,
SOL_SOCKET, SO_ERROR, RLIMIT_NOFILE, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_REUSEADDR, SO_REUSEPORT,
SO_BROADCAST, IPPROTO_IP, IPV6_MULTICAST_HOPS,
SOCK_DGRAM,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
export close, shutdown, sigemptyset, sigaddset, sigismember,
sigdelset, write, read, waitid, getaddrinfo,
gai_strerror, setsockopt, getsockopt, socket,
getrlimit, setrlimit, getpeername, getsockname,
recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, sendmsg, recvmsg, getpid, fcntl,
pthread_sigmask, clock_gettime, signal,
ClockId, Itimerspec, Timespec, Sigset, Time, Pid, Mode,
SigInfo, Id, Tmsghdr, IOVec, RLimit,
SockAddr, SockLen, Sockaddr_storage, Sockaddr_in,
Sockaddr_in6, Sockaddr_un, AddrInfo, SocketHandle,
CLOCK_MONOTONIC, F_GETFL, F_SETFL, F_GETFD, F_SETFD,
FD_CLOEXEC, O_NONBLOCK, SIG_BLOCK, SIG_UNBLOCK,
SOL_SOCKET, SO_ERROR, RLIMIT_NOFILE, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_REUSEADDR, SO_REUSEPORT,
SO_BROADCAST, IPPROTO_IP, IPV6_MULTICAST_HOPS,
SOCK_DGRAM,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
when not defined(android) and defined(amd64): when not defined(android) and defined(amd64):
const IP_MULTICAST_TTL*: cint = 33 const IP_MULTICAST_TTL*: cint = 33
@ -968,9 +1004,45 @@ elif defined(linux):
proc signalfd*(fd: cint, mask: var Sigset, flags: cint): cint {. proc signalfd*(fd: cint, mask: var Sigset, flags: cint): cint {.
cdecl, importc: "signalfd", header: "<sys/signalfd.h>".} cdecl, importc: "signalfd", header: "<sys/signalfd.h>".}
else: elif defined(freebsd) or defined(openbsd) or defined(netbsd) or
import std/posix defined(dragonfly):
export posix from std/posix import close, shutdown, socket, getpeername, getsockname,
recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, getaddrinfo, gai_strerror, getrlimit,
setrlimit, getpid, pthread_sigmask, sigemptyset,
sigaddset, sigismember, fcntl, accept, pipe, write,
signal, read, setsockopt, getsockopt, clock_gettime,
Timeval, Timespec, Pid, Mode, Time, Sigset, SockAddr,
SockLen, Sockaddr_storage, Sockaddr_in, Sockaddr_in6,
Sockaddr_un, SocketHandle, AddrInfo, RLimit,
F_GETFL, F_SETFL, F_GETFD, F_SETFD, FD_CLOEXEC,
O_NONBLOCK, SOL_SOCKET, SOCK_RAW, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_ERROR, SO_REUSEADDR,
SO_REUSEPORT, SO_BROADCAST, IPPROTO_IP,
IPV6_MULTICAST_HOPS, SOCK_DGRAM, RLIMIT_NOFILE,
SIG_BLOCK, SIG_UNBLOCK, CLOCK_MONOTONIC,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
export close, shutdown, socket, getpeername, getsockname,
recvfrom, sendto, send, bindSocket, recv, connect,
unlink, listen, getaddrinfo, gai_strerror, getrlimit,
setrlimit, getpid, pthread_sigmask, sigemptyset,
sigaddset, sigismember, fcntl, accept, pipe, write,
signal, read, setsockopt, getsockopt, clock_gettime,
Timeval, Timespec, Pid, Mode, Time, Sigset, SockAddr,
SockLen, Sockaddr_storage, Sockaddr_in, Sockaddr_in6,
Sockaddr_un, SocketHandle, AddrInfo, RLimit,
F_GETFL, F_SETFL, F_GETFD, F_SETFD, FD_CLOEXEC,
O_NONBLOCK, SOL_SOCKET, SOCK_RAW, MSG_NOSIGNAL,
AF_INET, AF_INET6, SO_ERROR, SO_REUSEADDR,
SO_REUSEPORT, SO_BROADCAST, IPPROTO_IP,
IPV6_MULTICAST_HOPS, SOCK_DGRAM, RLIMIT_NOFILE,
SIG_BLOCK, SIG_UNBLOCK, CLOCK_MONOTONIC,
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE, SIGCHLD
var IP_MULTICAST_TTL* {.importc: "IP_MULTICAST_TTL", var IP_MULTICAST_TTL* {.importc: "IP_MULTICAST_TTL",
header: "<netinet/in.h>".}: cint header: "<netinet/in.h>".}: cint
@ -1021,9 +1093,6 @@ elif defined(dragonfly):
when defined(linux) or defined(macos) or defined(macosx) or defined(freebsd) or when defined(linux) or defined(macos) or defined(macosx) or defined(freebsd) or
defined(openbsd) or defined(netbsd) or defined(dragonfly): defined(openbsd) or defined(netbsd) or defined(dragonfly):
export SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,
SIGPIPE, SIGALRM, SIGTERM, SIGPIPE
const const
POSIX_SPAWN_RESETIDS* = 0x01 POSIX_SPAWN_RESETIDS* = 0x01
@ -1144,13 +1213,12 @@ when defined(linux) or defined(macos) or defined(macosx) or defined(freebsd) or
importc: "posix_spawnattr_setsigmask", header: "<spawn.h>", importc: "posix_spawnattr_setsigmask", header: "<spawn.h>",
sideEffect.} sideEffect.}
when defined(posix):
when defined(linux): when defined(linux):
const const
P_PID* = cint(1) P_PID* = cint(1)
WNOHANG* = cint(1) WNOHANG* = cint(1)
WSTOPPED* = cint(2) WSTOPPED* = cint(2)
WEXITTED* = cint(4) WEXITED* = cint(4)
WNOWAIT* = cint(0x01000000) WNOWAIT* = cint(0x01000000)
template WSTATUS(s: cint): cint = template WSTATUS(s: cint): cint =
s and 0x7F s and 0x7F
@ -1260,7 +1328,7 @@ when defined(posix):
(WSTATUS(s) == 0x7F) and (WAITSTOPSIG(s) != 0x13) (WSTATUS(s) == 0x7F) and (WAITSTOPSIG(s) != 0x13)
template WAITIFCONTINUED*(s: cint): bool = template WAITIFCONTINUED*(s: cint): bool =
(WSTATUS(s) == 0x7F) and (WAITSTOPSIG(s) == 0x13) (WSTATUS(s) == 0x7F) and (WAITSTOPSIG(s) == 0x13)
else: elif defined(posix):
proc WAITEXITSTATUS*(s: cint): cint {. proc WAITEXITSTATUS*(s: cint): cint {.
importc: "WEXITSTATUS", header: "<sys/wait.h>".} importc: "WEXITSTATUS", header: "<sys/wait.h>".}
## Exit code, iff WIFEXITED(s) ## Exit code, iff WIFEXITED(s)
@ -1288,8 +1356,7 @@ when defined(posix):
INVALID_SOCKET* = SocketHandle(-1) INVALID_SOCKET* = SocketHandle(-1)
INVALID_HANDLE_VALUE* = cint(-1) INVALID_HANDLE_VALUE* = cint(-1)
proc `==`*(x: SocketHandle, y: int): bool = proc `==`*(x: SocketHandle, y: int): bool = int(x) == y
x == SocketHandle(y)
when defined(macosx) or defined(macos) or defined(bsd): when defined(macosx) or defined(macos) or defined(bsd):
const const

View File

@ -59,9 +59,9 @@ elif defined(linux) or defined(android):
elif defined(freebsd) or defined(openbsd) or defined(netbsd) or elif defined(freebsd) or defined(openbsd) or defined(netbsd) or
defined(dragonflybsd): defined(dragonflybsd):
import posix, os import oserrno
type type
SendfileHeader* {.importc: "sf_hdtr", SendfileHeader* {.importc: "struct sf_hdtr",
header: """#include <sys/types.h> header: """#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/uio.h>""", #include <sys/uio.h>""",
@ -76,20 +76,21 @@ elif defined(freebsd) or defined(openbsd) or defined(netbsd) or
proc sendfile*(outfd, infd: int, offset: int, count: var int): int = proc sendfile*(outfd, infd: int, offset: int, count: var int): int =
var o = 0'u var o = 0'u
let res = osSendFile(cint(infd), cint(outfd), uint(offset), uint(count), nil, let res = osSendFile(cint(infd), cint(outfd), uint(offset), uint(count),
addr o, 0) nil, addr o, 0)
if res >= 0: if res >= 0:
count = int(o) count = int(o)
0 0
else: else:
let err = osLastError() let err = osLastError()
count = count =
if int(err) == EAGAIN: int(o) if err == EAGAIN: int(o)
else: 0 else: 0
-1 -1
elif defined(macosx): elif defined(macosx):
import posix, os import oserrno
type type
SendfileHeader* {.importc: "struct sf_hdtr", SendfileHeader* {.importc: "struct sf_hdtr",
header: """#include <sys/types.h> header: """#include <sys/types.h>
@ -113,6 +114,6 @@ elif defined(macosx):
else: else:
let err = osLastError() let err = osLastError()
count = count =
if int(err) == EAGAIN: int(o) if err == EAGAIN: int(o)
else: 0 else: 0
-1 -1

View File

@ -454,21 +454,3 @@ func epochNanoSeconds*(moment: Moment): int64 =
proc fromNow*(t: typedesc[Moment], a: Duration): Moment {.inline.} = proc fromNow*(t: typedesc[Moment], a: Duration): Moment {.inline.} =
## Returns moment in time which is equal to current moment + Duration. ## Returns moment in time which is equal to current moment + Duration.
Moment.now() + a Moment.now() + a
when defined(posix):
from posix import Time, Suseconds, Timeval, Timespec
func toTimeval*(a: Duration): Timeval =
## Convert Duration ``a`` to ``Timeval`` object.
let m = a.value mod Second.value
Timeval(
tv_sec: Time(a.value div Second.value),
tv_usec: Suseconds(m div Microsecond.value)
)
func toTimespec*(a: Duration): Timespec =
## Convert Duration ``a`` to ``Timespec`` object.
Timespec(
tv_sec: Time(a.value div Second.value),
tv_nsec: int(a.value mod Second.value)
)

View File

@ -21,7 +21,7 @@ from std/net import Domain, `==`, IpAddress, IpAddressFamily, parseIpAddress,
from std/nativesockets import toInt, `$` from std/nativesockets import toInt, `$`
export Domain, `==`, IpAddress, IpAddressFamily, parseIpAddress, SockType, export Domain, `==`, IpAddress, IpAddressFamily, parseIpAddress, SockType,
Protocol, Port, toInt, `$`, osdefs Protocol, Port, toInt, `$`
const const
DefaultStreamBufferSize* = 4096 ## Default buffer size for stream DefaultStreamBufferSize* = 4096 ## Default buffer size for stream