Fixes for nimdoc (#252)
This commit is contained in:
parent
0fc82049ac
commit
d926415f42
|
@ -286,7 +286,7 @@ proc raiseAsDefect*(exc: ref Exception, msg: string) {.
|
|||
raise (ref Defect)(
|
||||
msg: msg & "\n" & exc.msg & "\n" & exc.getStackTrace(), parent: exc)
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
when defined(windows):
|
||||
type
|
||||
WSAPROC_TRANSMITFILE = proc(hSocket: SocketHandle, hFile: Handle,
|
||||
nNumberOfBytesToWrite: DWORD,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
import std/[net, nativesockets]
|
||||
import ./asyncloop
|
||||
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import os, winlean
|
||||
const
|
||||
asyncInvalidSocket* = AsyncFD(-1)
|
||||
|
@ -40,7 +40,7 @@ const
|
|||
|
||||
proc setSocketBlocking*(s: SocketHandle, blocking: bool): bool =
|
||||
## Sets blocking mode on socket.
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
var mode = clong(ord(not blocking))
|
||||
if ioctlsocket(s, FIONBIO, addr(mode)) == -1:
|
||||
false
|
||||
|
@ -124,7 +124,7 @@ proc getMaxOpenFiles*(): int {.raises: [Defect, OSError].} =
|
|||
## Note: On Windows its impossible to obtain such number, so getMaxOpenFiles()
|
||||
## will return constant value of 16384. You can get more information on this
|
||||
## link https://docs.microsoft.com/en-us/archive/blogs/markrussinovich/pushing-the-limits-of-windows-handles
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
16384
|
||||
else:
|
||||
var limits: RLimit
|
||||
|
@ -136,7 +136,7 @@ proc setMaxOpenFiles*(count: int) {.raises: [Defect, OSError].} =
|
|||
## Set maximum file descriptor number that can be opened by this process.
|
||||
##
|
||||
## Note: On Windows its impossible to set this value, so it just a nop call.
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
discard
|
||||
else:
|
||||
var limits: RLimit
|
||||
|
@ -201,6 +201,7 @@ proc createAsyncPipe*(): tuple[read: AsyncFD, write: AsyncFD] =
|
|||
return (read: asyncInvalidPipe, write: asyncInvalidPipe)
|
||||
|
||||
(read: AsyncFD(pipeIn), write: AsyncFD(pipeOut))
|
||||
elif defined(nimdoc): discard
|
||||
else:
|
||||
var fds: array[2, cint]
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ when defined(nimdoc):
|
|||
VnodeRename, ## NOTE_RENAME (BSD specific, file renamed)
|
||||
VnodeRevoke ## NOTE_REVOKE (BSD specific, file revoke occurred)
|
||||
|
||||
IOSelectorsException* = object of CatchableError
|
||||
|
||||
ReadyKey* = object
|
||||
## An object which holds result for descriptor
|
||||
fd* : int ## file/socket descriptor
|
||||
|
|
|
@ -39,7 +39,7 @@ when defined(nimdoc):
|
|||
##
|
||||
## On error, ``-1`` is returned.
|
||||
|
||||
when defined(linux) or defined(android):
|
||||
elif defined(linux) or defined(android):
|
||||
|
||||
proc osSendFile*(outfd, infd: cint, offset: ptr int, count: int): int
|
||||
{.importc: "sendfile", header: "<sys/sendfile.h>".}
|
||||
|
|
|
@ -14,7 +14,7 @@ import stew/base10
|
|||
import ../asyncloop
|
||||
export net
|
||||
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import winlean
|
||||
else:
|
||||
import posix
|
||||
|
@ -59,7 +59,7 @@ type
|
|||
Running, # Server running
|
||||
Closed # Server closed
|
||||
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
type
|
||||
SocketServer* = ref object of RootRef
|
||||
## Socket server object
|
||||
|
@ -75,7 +75,8 @@ when defined(windows):
|
|||
asock*: AsyncFD # Current AcceptEx() socket
|
||||
errorCode*: OSErrorCode # Current error code
|
||||
abuffer*: array[128, byte] # Windows AcceptEx() buffer
|
||||
aovl*: CustomOverlapped # AcceptEx OVERLAPPED structure
|
||||
when defined(windows):
|
||||
aovl*: CustomOverlapped # AcceptEx OVERLAPPED structure
|
||||
else:
|
||||
type
|
||||
SocketServer* = ref object of RootRef
|
||||
|
@ -295,7 +296,7 @@ proc getAddrInfo(address: string, port: Port, domain: Domain,
|
|||
var gaiRes = getaddrinfo(address, Base10.toString(uint16(port)),
|
||||
addr(hints), res)
|
||||
if gaiRes != 0'i32:
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
raise newException(TransportAddressError, osErrorMsg(osLastError()))
|
||||
else:
|
||||
raise newException(TransportAddressError, $gai_strerror(gaiRes))
|
||||
|
@ -320,7 +321,7 @@ proc fromSAddr*(sa: ptr Sockaddr_storage, sl: SockLen,
|
|||
sizeof(address.address_v6))
|
||||
address.port = Port(nativesockets.ntohs(s.sin6_port))
|
||||
elif int(sa.ss_family) == toInt(Domain.AF_UNIX):
|
||||
when not defined(windows):
|
||||
when not defined(windows) and not defined(nimdoc):
|
||||
address = TransportAddress(family: AddressFamily.Unix)
|
||||
if int(sl) > sizeof(sa.ss_family):
|
||||
var length = int(sl) - sizeof(sa.ss_family)
|
||||
|
@ -352,7 +353,7 @@ proc toSAddr*(address: TransportAddress, sa: var Sockaddr_storage,
|
|||
copyMem(addr s.sin6_addr, unsafeAddr address.address_v6[0],
|
||||
sizeof(s.sin6_addr))
|
||||
of AddressFamily.Unix:
|
||||
when not defined(windows):
|
||||
when not defined(windows) and not defined(nimdoc):
|
||||
if address.port == Port(0):
|
||||
sl = SockLen(sizeof(sa.ss_family))
|
||||
else:
|
||||
|
|
|
@ -13,7 +13,7 @@ import std/[net, nativesockets, os, deques]
|
|||
import ".."/[selectors2, asyncloop, handles]
|
||||
import ./common
|
||||
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import winlean
|
||||
else:
|
||||
import posix
|
||||
|
@ -130,8 +130,26 @@ proc setupDgramTransportTracker(): DgramTransportTracker {.gcsafe.} =
|
|||
result.isLeaked = leakTransport
|
||||
addTracker(DgramTransportTrackerName, result)
|
||||
|
||||
when defined(windows):
|
||||
when defined(nimdoc):
|
||||
proc newDatagramTransportCommon(cbproc: DatagramCallback,
|
||||
remote: TransportAddress,
|
||||
local: TransportAddress,
|
||||
sock: AsyncFD,
|
||||
flags: set[ServerFlags],
|
||||
udata: pointer,
|
||||
child: DatagramTransport,
|
||||
bufferSize: int,
|
||||
ttl: int): DatagramTransport {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
discard
|
||||
|
||||
proc resumeRead(transp: DatagramTransport) {.inline.} =
|
||||
discard
|
||||
|
||||
proc resumeWrite(transp: DatagramTransport) {.inline.} =
|
||||
discard
|
||||
|
||||
elif defined(windows):
|
||||
template setWriterWSABuffer(t, v: untyped) =
|
||||
(t).wwsabuf.buf = cast[cstring](v.buf)
|
||||
(t).wwsabuf.len = cast[int32](v.buflen)
|
||||
|
|
|
@ -13,7 +13,7 @@ import std/[net, nativesockets, os, deques]
|
|||
import ".."/[asyncloop, handles, selectors2]
|
||||
import common
|
||||
|
||||
when defined(windows):
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import winlean
|
||||
else:
|
||||
import posix
|
||||
|
@ -292,7 +292,17 @@ proc clean(transp: StreamTransport) {.inline.} =
|
|||
transp.future.complete()
|
||||
GC_unref(transp)
|
||||
|
||||
when defined(windows):
|
||||
when defined(nimdoc):
|
||||
proc pauseAccept(server: StreamServer) {.inline.} = discard
|
||||
proc resumeAccept(server: StreamServer) {.inline.} = discard
|
||||
proc resumeRead(transp: StreamTransport) {.inline.} = discard
|
||||
proc accept*(server: StreamServer): Future[StreamTransport] = discard
|
||||
proc resumeWrite(transp: StreamTransport) {.inline.} = discard
|
||||
proc newStreamPipeTransport(fd: AsyncFD, bufsize: int,
|
||||
child: StreamTransport,
|
||||
flags: set[TransportFlags] = {}): StreamTransport =
|
||||
discard
|
||||
elif defined(windows):
|
||||
|
||||
template zeroOvelappedOffset(t: untyped) =
|
||||
(t).offset = 0
|
||||
|
@ -1827,7 +1837,9 @@ proc createStreamServer*(host: TransportAddress,
|
|||
serverSocket: AsyncFD
|
||||
localAddress: TransportAddress
|
||||
|
||||
when defined(windows):
|
||||
when defined(nimdoc):
|
||||
discard
|
||||
elif defined(windows):
|
||||
# Windows
|
||||
if host.family in {AddressFamily.IPv4, AddressFamily.IPv6}:
|
||||
if sock == asyncInvalidSocket:
|
||||
|
@ -2040,7 +2052,7 @@ template fastWrite(fd: auto, pbytes: var ptr byte, rbytes: var int, nbytes: int)
|
|||
# On windows, the write could be initiated here if there is no other write
|
||||
# ongoing, but the queue is still needed due to the mechanics of iocp
|
||||
|
||||
when not defined(windows):
|
||||
when not defined(windows) and not defined(nimdoc):
|
||||
if transp.queue.len == 0:
|
||||
while rbytes > 0:
|
||||
let res = posix.send(SocketHandle(fd), pbytes, rbytes, MSG_NOSIGNAL)
|
||||
|
|
Loading…
Reference in New Issue