mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
make more parts of the stdlib compile with --styleCheck:error
(cherry picked from commit bc7733827d)
This commit is contained in:
@@ -880,21 +880,21 @@ const
|
||||
|
||||
proc `==`*(x, y: SocketHandle): bool {.borrow.}
|
||||
|
||||
proc accept*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr Socklen): SocketHandle {.
|
||||
proc accept*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): SocketHandle {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
|
||||
proc bindSocket*(a1: SocketHandle, a2: ptr SockAddr, a3: Socklen): cint {.
|
||||
proc bindSocket*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
|
||||
importc: "bind", header: "<sys/socket.h>".}
|
||||
## is Posix's ``bind``, because ``bind`` is a reserved word
|
||||
|
||||
proc connect*(a1: SocketHandle, a2: ptr SockAddr, a3: Socklen): cint {.
|
||||
proc connect*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc getpeername*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr Socklen): cint {.
|
||||
proc getpeername*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc getsockname*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr Socklen): cint {.
|
||||
proc getsockname*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
|
||||
proc getsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: ptr Socklen): cint {.
|
||||
proc getsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: ptr SockLen): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
|
||||
proc listen*(a1: SocketHandle, a2: cint): cint {.
|
||||
@@ -902,7 +902,7 @@ proc listen*(a1: SocketHandle, a2: cint): cint {.
|
||||
proc recv*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc recvfrom*(a1: SocketHandle, a2: pointer, a3: int, a4: cint,
|
||||
a5: ptr SockAddr, a6: ptr Socklen): int {.
|
||||
a5: ptr SockAddr, a6: ptr SockLen): int {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc recvmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
@@ -911,9 +911,9 @@ proc send*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
|
||||
proc sendmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc sendto*(a1: SocketHandle, a2: pointer, a3: int, a4: cint, a5: ptr SockAddr,
|
||||
a6: Socklen): int {.
|
||||
a6: SockLen): int {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc setsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: Socklen): cint {.
|
||||
proc setsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: SockLen): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
proc shutdown*(a1: SocketHandle, a2: cint): cint {.
|
||||
importc, header: "<sys/socket.h>".}
|
||||
@@ -979,7 +979,7 @@ proc getaddrinfo*(a1, a2: cstring, a3: ptr AddrInfo,
|
||||
a4: var ptr AddrInfo): cint {.importc, header: "<netdb.h>".}
|
||||
|
||||
when not defined(android4):
|
||||
proc gethostbyaddr*(a1: pointer, a2: Socklen, a3: cint): ptr Hostent {.
|
||||
proc gethostbyaddr*(a1: pointer, a2: SockLen, a3: cint): ptr Hostent {.
|
||||
importc, header: "<netdb.h>".}
|
||||
else:
|
||||
proc gethostbyaddr*(a1: cstring, a2: cint, a3: cint): ptr Hostent {.
|
||||
@@ -987,9 +987,9 @@ else:
|
||||
proc gethostbyname*(a1: cstring): ptr Hostent {.importc, header: "<netdb.h>".}
|
||||
proc gethostent*(): ptr Hostent {.importc, header: "<netdb.h>".}
|
||||
|
||||
proc getnameinfo*(a1: ptr SockAddr, a2: Socklen,
|
||||
a3: cstring, a4: Socklen, a5: cstring,
|
||||
a6: Socklen, a7: cint): cint {.importc, header: "<netdb.h>".}
|
||||
proc getnameinfo*(a1: ptr SockAddr, a2: SockLen,
|
||||
a3: cstring, a4: SockLen, a5: cstring,
|
||||
a6: SockLen, a7: cint): cint {.importc, header: "<netdb.h>".}
|
||||
|
||||
proc getnetbyaddr*(a1: int32, a2: cint): ptr Tnetent {.importc, header: "<netdb.h>".}
|
||||
proc getnetbyname*(a1: cstring): ptr Tnetent {.importc, header: "<netdb.h>".}
|
||||
|
||||
@@ -416,7 +416,7 @@ when hasSpawnH:
|
||||
const Sockaddr_un_path_length* = 108
|
||||
|
||||
type
|
||||
Socklen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cushort
|
||||
|
||||
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
|
||||
@@ -450,7 +450,7 @@ type
|
||||
Tmsghdr* {.importc: "struct msghdr", pure, final,
|
||||
header: "<sys/socket.h>".} = object ## struct msghdr
|
||||
msg_name*: pointer ## Optional address.
|
||||
msg_namelen*: Socklen ## Size of address.
|
||||
msg_namelen*: SockLen ## Size of address.
|
||||
msg_iov*: ptr IOVec ## Scatter/gather array.
|
||||
msg_iovlen*: csize ## Members in msg_iov.
|
||||
msg_control*: pointer ## Ancillary data; see below.
|
||||
@@ -551,7 +551,7 @@ type
|
||||
ai_family*: cint ## Address family of socket.
|
||||
ai_socktype*: cint ## Socket type.
|
||||
ai_protocol*: cint ## Protocol of socket.
|
||||
ai_addrlen*: Socklen ## Length of socket address.
|
||||
ai_addrlen*: SockLen ## Length of socket address.
|
||||
ai_addr*: ptr SockAddr ## Socket address of socket.
|
||||
ai_canonname*: cstring ## Canonical name of service location.
|
||||
ai_next*: ptr AddrInfo ## Pointer to next in list.
|
||||
|
||||
@@ -376,7 +376,7 @@ else:
|
||||
const Sockaddr_un_path_length* = 92
|
||||
|
||||
type
|
||||
Socklen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
|
||||
|
||||
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
|
||||
@@ -408,17 +408,17 @@ type
|
||||
Tmsghdr* {.importc: "struct msghdr", pure, final,
|
||||
header: "<sys/socket.h>".} = object ## struct msghdr
|
||||
msg_name*: pointer ## Optional address.
|
||||
msg_namelen*: Socklen ## Size of address.
|
||||
msg_namelen*: SockLen ## Size of address.
|
||||
msg_iov*: ptr IOVec ## Scatter/gather array.
|
||||
msg_iovlen*: cint ## Members in msg_iov.
|
||||
msg_control*: pointer ## Ancillary data; see below.
|
||||
msg_controllen*: Socklen ## Ancillary data buffer len.
|
||||
msg_controllen*: SockLen ## Ancillary data buffer len.
|
||||
msg_flags*: cint ## Flags on received message.
|
||||
|
||||
|
||||
Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
|
||||
header: "<sys/socket.h>".} = object ## struct cmsghdr
|
||||
cmsg_len*: Socklen ## Data byte count, including the cmsghdr.
|
||||
cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
|
||||
cmsg_level*: cint ## Originating protocol.
|
||||
cmsg_type*: cint ## Protocol-specific type.
|
||||
|
||||
@@ -507,7 +507,7 @@ type
|
||||
ai_family*: cint ## Address family of socket.
|
||||
ai_socktype*: cint ## Socket type.
|
||||
ai_protocol*: cint ## Protocol of socket.
|
||||
ai_addrlen*: Socklen ## Length of socket address.
|
||||
ai_addrlen*: SockLen ## Length of socket address.
|
||||
ai_addr*: ptr SockAddr ## Socket address of socket.
|
||||
ai_canonname*: cstring ## Canonical name of service location.
|
||||
ai_next*: ptr AddrInfo ## Pointer to next in list.
|
||||
|
||||
@@ -385,7 +385,7 @@ else:
|
||||
const Sockaddr_un_path_length* = 92
|
||||
|
||||
type
|
||||
Socklen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
|
||||
TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cushort
|
||||
|
||||
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
|
||||
@@ -417,17 +417,17 @@ type
|
||||
Tmsghdr* {.importc: "struct msghdr", pure, final,
|
||||
header: "<sys/socket.h>".} = object ## struct msghdr
|
||||
msg_name*: pointer ## Optional address.
|
||||
msg_namelen*: Socklen ## Size of address.
|
||||
msg_namelen*: SockLen ## Size of address.
|
||||
msg_iov*: ptr IOVec ## Scatter/gather array.
|
||||
msg_iovlen*: cint ## Members in msg_iov.
|
||||
msg_control*: pointer ## Ancillary data; see below.
|
||||
msg_controllen*: Socklen ## Ancillary data buffer len.
|
||||
msg_controllen*: SockLen ## Ancillary data buffer len.
|
||||
msg_flags*: cint ## Flags on received message.
|
||||
|
||||
|
||||
Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
|
||||
header: "<sys/socket.h>".} = object ## struct cmsghdr
|
||||
cmsg_len*: Socklen ## Data byte count, including the cmsghdr.
|
||||
cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
|
||||
cmsg_level*: cint ## Originating protocol.
|
||||
cmsg_type*: cint ## Protocol-specific type.
|
||||
|
||||
@@ -516,7 +516,7 @@ type
|
||||
ai_family*: cint ## Address family of socket.
|
||||
ai_socktype*: cint ## Socket type.
|
||||
ai_protocol*: cint ## Protocol of socket.
|
||||
ai_addrlen*: Socklen ## Length of socket address.
|
||||
ai_addrlen*: SockLen ## Length of socket address.
|
||||
ai_addr*: ptr SockAddr ## Socket address of socket.
|
||||
ai_canonname*: cstring ## Canonical name of service location.
|
||||
ai_next*: ptr AddrInfo ## Pointer to next in list.
|
||||
|
||||
@@ -1140,7 +1140,7 @@ else:
|
||||
proc unregister*(ev: AsyncEvent) =
|
||||
getGlobalDispatcher().selector.unregister(SelectEvent(ev))
|
||||
|
||||
proc contains*(disp: PDispatcher, fd: AsyncFd): bool =
|
||||
proc contains*(disp: PDispatcher, fd: AsyncFD): bool =
|
||||
return fd.SocketHandle in disp.selector
|
||||
|
||||
proc addRead*(fd: AsyncFD, cb: Callback) =
|
||||
@@ -1474,7 +1474,7 @@ else:
|
||||
proc cb(sock: AsyncFD): bool =
|
||||
result = true
|
||||
var sockAddress: Sockaddr_storage
|
||||
var addrLen = sizeof(sockAddress).Socklen
|
||||
var addrLen = sizeof(sockAddress).SockLen
|
||||
var client = accept(sock.SocketHandle,
|
||||
cast[ptr SockAddr](addr(sockAddress)), addr(addrLen))
|
||||
if client == osInvalidSocket:
|
||||
@@ -1660,7 +1660,7 @@ else:
|
||||
|
||||
let ret = connect(socket.SocketHandle,
|
||||
addrInfo.ai_addr,
|
||||
addrInfo.ai_addrlen.Socklen)
|
||||
addrInfo.ai_addrlen.SockLen)
|
||||
if ret == 0:
|
||||
# Request to connect completed immediately.
|
||||
retFuture.complete()
|
||||
|
||||
@@ -33,7 +33,7 @@ else:
|
||||
|
||||
type
|
||||
AsyncFile* = ref object
|
||||
fd: AsyncFd
|
||||
fd: AsyncFD
|
||||
offset: int64
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
@@ -72,7 +72,7 @@ else:
|
||||
proc getFileSize*(f: AsyncFile): int64 =
|
||||
## Retrieves the specified file's size.
|
||||
when defined(windows) or defined(nimdoc):
|
||||
var high: DWord
|
||||
var high: DWORD
|
||||
let low = getFileSize(f.fd.Handle, addr high)
|
||||
if low == INVALID_FILE_SIZE:
|
||||
raiseOSError(osLastError())
|
||||
@@ -83,7 +83,7 @@ proc getFileSize*(f: AsyncFile): int64 =
|
||||
f.offset = lseek(f.fd.cint, curPos, SEEK_SET)
|
||||
assert(f.offset == curPos)
|
||||
|
||||
proc newAsyncFile*(fd: AsyncFd): AsyncFile =
|
||||
proc newAsyncFile*(fd: AsyncFD): AsyncFile =
|
||||
## Creates `AsyncFile` with a previously opened file descriptor `fd`.
|
||||
new result
|
||||
result.fd = fd
|
||||
@@ -108,7 +108,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
||||
if fd == INVALID_HANDLE_VALUE:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
result = newAsyncFile(fd.AsyncFd)
|
||||
result = newAsyncFile(fd.AsyncFD)
|
||||
|
||||
if mode == fmAppend:
|
||||
result.offset = getFileSize(result)
|
||||
@@ -121,7 +121,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
||||
if fd == -1:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
result = newAsyncFile(fd.AsyncFd)
|
||||
result = newAsyncFile(fd.AsyncFD)
|
||||
|
||||
proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
## Read ``size`` bytes from the specified file asynchronously starting at
|
||||
@@ -135,7 +135,7 @@ proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
var ol = PCustomOverlapped()
|
||||
GC_ref(ol)
|
||||
ol.data = CompletionData(fd: f.fd, cb:
|
||||
proc (fd: AsyncFD, bytesCount: Dword, errcode: OSErrorCode) =
|
||||
proc (fd: AsyncFD, bytesCount: DWORD, errcode: OSErrorCode) =
|
||||
if not retFuture.finished:
|
||||
if errcode == OSErrorCode(-1):
|
||||
assert bytesCount > 0
|
||||
@@ -148,8 +148,8 @@ proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
else:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(errcode)))
|
||||
)
|
||||
ol.offset = DWord(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWord(f.offset shr 32)
|
||||
ol.offset = DWORD(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWORD(f.offset shr 32)
|
||||
|
||||
# According to MSDN we're supposed to pass nil to lpNumberOfBytesRead.
|
||||
let ret = readFile(f.fd.Handle, buf, size.int32, nil,
|
||||
@@ -165,9 +165,9 @@ proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||
else:
|
||||
# Request completed immediately.
|
||||
var bytesRead: DWord
|
||||
var bytesRead: DWORD
|
||||
let overlappedRes = getOverlappedResult(f.fd.Handle,
|
||||
cast[POverlapped](ol), bytesRead, false.WinBool)
|
||||
cast[POVERLAPPED](ol), bytesRead, false.WINBOOL)
|
||||
if not overlappedRes.bool:
|
||||
let err = osLastError()
|
||||
if err.int32 == ERROR_HANDLE_EOF:
|
||||
@@ -215,7 +215,7 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||
var ol = PCustomOverlapped()
|
||||
GC_ref(ol)
|
||||
ol.data = CompletionData(fd: f.fd, cb:
|
||||
proc (fd: AsyncFD, bytesCount: Dword, errcode: OSErrorCode) =
|
||||
proc (fd: AsyncFD, bytesCount: DWORD, errcode: OSErrorCode) =
|
||||
if not retFuture.finished:
|
||||
if errcode == OSErrorCode(-1):
|
||||
assert bytesCount > 0
|
||||
@@ -233,8 +233,8 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||
dealloc buffer
|
||||
buffer = nil
|
||||
)
|
||||
ol.offset = DWord(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWord(f.offset shr 32)
|
||||
ol.offset = DWORD(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWORD(f.offset shr 32)
|
||||
|
||||
# According to MSDN we're supposed to pass nil to lpNumberOfBytesRead.
|
||||
let ret = readFile(f.fd.Handle, buffer, size.int32, nil,
|
||||
@@ -254,9 +254,9 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||
else:
|
||||
# Request completed immediately.
|
||||
var bytesRead: DWord
|
||||
var bytesRead: DWORD
|
||||
let overlappedRes = getOverlappedResult(f.fd.Handle,
|
||||
cast[POverlapped](ol), bytesRead, false.WinBool)
|
||||
cast[POVERLAPPED](ol), bytesRead, false.WINBOOL)
|
||||
if not overlappedRes.bool:
|
||||
let err = osLastError()
|
||||
if err.int32 == ERROR_HANDLE_EOF:
|
||||
@@ -343,7 +343,7 @@ proc writeBuffer*(f: AsyncFile, buf: pointer, size: int): Future[void] =
|
||||
var ol = PCustomOverlapped()
|
||||
GC_ref(ol)
|
||||
ol.data = CompletionData(fd: f.fd, cb:
|
||||
proc (fd: AsyncFD, bytesCount: DWord, errcode: OSErrorCode) =
|
||||
proc (fd: AsyncFD, bytesCount: DWORD, errcode: OSErrorCode) =
|
||||
if not retFuture.finished:
|
||||
if errcode == OSErrorCode(-1):
|
||||
assert bytesCount == size.int32
|
||||
@@ -355,8 +355,8 @@ proc writeBuffer*(f: AsyncFile, buf: pointer, size: int): Future[void] =
|
||||
# information see
|
||||
# http://stackoverflow.com/questions/33650899/does-asynchronous-file-
|
||||
# appending-in-windows-preserve-order
|
||||
ol.offset = DWord(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWord(f.offset shr 32)
|
||||
ol.offset = DWORD(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWORD(f.offset shr 32)
|
||||
f.offset.inc(size)
|
||||
|
||||
# According to MSDN we're supposed to pass nil to lpNumberOfBytesWritten.
|
||||
@@ -369,9 +369,9 @@ proc writeBuffer*(f: AsyncFile, buf: pointer, size: int): Future[void] =
|
||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||
else:
|
||||
# Request completed immediately.
|
||||
var bytesWritten: DWord
|
||||
var bytesWritten: DWORD
|
||||
let overlappedRes = getOverlappedResult(f.fd.Handle,
|
||||
cast[POverlapped](ol), bytesWritten, false.WinBool)
|
||||
cast[POVERLAPPED](ol), bytesWritten, false.WINBOOL)
|
||||
if not overlappedRes.bool:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(osLastError())))
|
||||
else:
|
||||
@@ -417,7 +417,7 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
||||
var ol = PCustomOverlapped()
|
||||
GC_ref(ol)
|
||||
ol.data = CompletionData(fd: f.fd, cb:
|
||||
proc (fd: AsyncFD, bytesCount: DWord, errcode: OSErrorCode) =
|
||||
proc (fd: AsyncFD, bytesCount: DWORD, errcode: OSErrorCode) =
|
||||
if not retFuture.finished:
|
||||
if errcode == OSErrorCode(-1):
|
||||
assert bytesCount == data.len.int32
|
||||
@@ -428,8 +428,8 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
||||
dealloc buffer
|
||||
buffer = nil
|
||||
)
|
||||
ol.offset = DWord(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWord(f.offset shr 32)
|
||||
ol.offset = DWORD(f.offset and 0xffffffff)
|
||||
ol.offsetHigh = DWORD(f.offset shr 32)
|
||||
f.offset.inc(data.len)
|
||||
|
||||
# According to MSDN we're supposed to pass nil to lpNumberOfBytesWritten.
|
||||
@@ -445,9 +445,9 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||
else:
|
||||
# Request completed immediately.
|
||||
var bytesWritten: DWord
|
||||
var bytesWritten: DWORD
|
||||
let overlappedRes = getOverlappedResult(f.fd.Handle,
|
||||
cast[POverlapped](ol), bytesWritten, false.WinBool)
|
||||
cast[POVERLAPPED](ol), bytesWritten, false.WINBOOL)
|
||||
if not overlappedRes.bool:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(osLastError())))
|
||||
else:
|
||||
@@ -482,9 +482,9 @@ proc setFileSize*(f: AsyncFile, length: int64) =
|
||||
## Set a file length.
|
||||
when defined(windows) or defined(nimdoc):
|
||||
var
|
||||
high = (length shr 32).Dword
|
||||
high = (length shr 32).DWORD
|
||||
let
|
||||
low = (length and 0xffffffff).Dword
|
||||
low = (length and 0xffffffff).DWORD
|
||||
status = setFilePointer(f.fd.Handle, low, addr high, 0)
|
||||
lastErr = osLastError()
|
||||
if (status == INVALID_SET_FILE_POINTER and lastErr.int32 != NO_ERROR) or
|
||||
|
||||
@@ -86,15 +86,15 @@ type
|
||||
address*: string
|
||||
port*: Port
|
||||
jobInProgress*: bool
|
||||
job*: FTPJob
|
||||
job*: FtpJob
|
||||
dsockConnected*: bool
|
||||
|
||||
FTPJobType* = enum
|
||||
FtpJobType* = enum
|
||||
JRetrText, JRetr, JStore
|
||||
|
||||
FtpJob = ref object
|
||||
prc: proc (ftp: AsyncFtpClient, async: bool): bool {.nimcall, gcsafe.}
|
||||
case typ*: FTPJobType
|
||||
case typ*: FtpJobType
|
||||
of JRetrText:
|
||||
lines: string
|
||||
of JRetr, JStore:
|
||||
@@ -106,12 +106,12 @@ type
|
||||
lastProgressReport: float # Time
|
||||
toStore: string # Data left to upload (Only used with async)
|
||||
|
||||
FTPEventType* = enum
|
||||
FtpEventType* = enum
|
||||
EvTransferProgress, EvLines, EvRetr, EvStore
|
||||
|
||||
FTPEvent* = object ## Event
|
||||
FtpEvent* = object ## Event
|
||||
filename*: string
|
||||
case typ*: FTPEventType
|
||||
case typ*: FtpEventType
|
||||
of EvLines:
|
||||
lines*: string ## Lines that have been transferred.
|
||||
of EvRetr, EvStore: ## Retr/Store operation finished.
|
||||
@@ -120,7 +120,7 @@ type
|
||||
bytesTotal*: BiggestInt ## Bytes total.
|
||||
bytesFinished*: BiggestInt ## Bytes transferred.
|
||||
speed*: BiggestInt ## Speed in bytes/s
|
||||
currentJob*: FTPJobType ## The current job being performed.
|
||||
currentJob*: FtpJobType ## The current job being performed.
|
||||
|
||||
ReplyError* = object of IOError
|
||||
|
||||
@@ -398,8 +398,8 @@ proc store*(ftp: AsyncFtpClient, file, dest: string,
|
||||
proc rename*(ftp: AsyncFtpClient, nameFrom: string, nameTo: string) {.async.} =
|
||||
## Rename a file or directory on the remote FTP Server from current name
|
||||
## ``name_from`` to new name ``name_to``
|
||||
assertReply(await ftp.send("RNFR " & name_from), "350")
|
||||
assertReply(await ftp.send("RNTO " & name_to), "250")
|
||||
assertReply(await ftp.send("RNFR " & nameFrom), "350")
|
||||
assertReply(await ftp.send("RNTO " & nameTo), "250")
|
||||
|
||||
proc removeFile*(ftp: AsyncFtpClient, filename: string) {.async.} =
|
||||
## Delete a file ``filename`` on the remote FTP server
|
||||
|
||||
@@ -310,7 +310,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||
# -> createCb(retFuture)
|
||||
# NOTE: The "_continue" suffix is checked for in asyncfutures.nim to produce
|
||||
# friendlier stack traces:
|
||||
var cbName = genSym(nskProc, prcName & "_continue")
|
||||
var cbName = genSym(nskProc, prcName & "Continue")
|
||||
var procCb = getAst createCb(retFutureSym, iteratorNameSym,
|
||||
newStrLitNode(prcName),
|
||||
cbName,
|
||||
|
||||
@@ -625,10 +625,10 @@ proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.
|
||||
"Unknown socket address family and no address specified to bindAddr")
|
||||
|
||||
var aiList = getAddrInfo(realaddr, port, socket.domain)
|
||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
|
||||
freeAddrInfo(aiList)
|
||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.SockLen) < 0'i32:
|
||||
freeaddrinfo(aiList)
|
||||
raiseOSError(osLastError())
|
||||
freeAddrInfo(aiList)
|
||||
freeaddrinfo(aiList)
|
||||
|
||||
when defined(posix):
|
||||
|
||||
@@ -652,7 +652,7 @@ when defined(posix):
|
||||
|
||||
var socketAddr = makeUnixAddr(path)
|
||||
let ret = socket.fd.connect(cast[ptr SockAddr](addr socketAddr),
|
||||
(sizeof(socketAddr.sun_family) + path.len).Socklen)
|
||||
(sizeof(socketAddr.sun_family) + path.len).SockLen)
|
||||
if ret == 0:
|
||||
# Request to connect completed immediately.
|
||||
retFuture.complete()
|
||||
@@ -670,7 +670,7 @@ when defined(posix):
|
||||
when not defined(nimdoc):
|
||||
var socketAddr = makeUnixAddr(path)
|
||||
if socket.fd.bindAddr(cast[ptr SockAddr](addr socketAddr),
|
||||
(sizeof(socketAddr.sun_family) + path.len).Socklen) != 0'i32:
|
||||
(sizeof(socketAddr.sun_family) + path.len).SockLen) != 0'i32:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
elif defined(nimdoc):
|
||||
|
||||
@@ -110,7 +110,7 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped =
|
||||
#assert(r == result.len)
|
||||
discard
|
||||
|
||||
proc encode*[T:SomeInteger|char](s: openarray[T], lineLen = 75, newLine=""): string =
|
||||
proc encode*[T:SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string =
|
||||
## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a
|
||||
## ``newline`` is added.
|
||||
##
|
||||
|
||||
@@ -788,7 +788,7 @@ iterator allValues*[A, B](t: Table[A, B]; key: A): B =
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
|
||||
proc newTable*[A, B](initialsize = defaultInitialSize): <//>TableRef[A, B] =
|
||||
proc newTable*[A, B](initialSize = defaultInitialSize): <//>TableRef[A, B] =
|
||||
## Creates a new ref hash table that is empty.
|
||||
##
|
||||
## ``initialSize`` must be a power of two (default: 64).
|
||||
|
||||
@@ -250,7 +250,7 @@ type
|
||||
url*: Uri
|
||||
auth*: string
|
||||
|
||||
MultipartEntries* = openarray[tuple[name, content: string]]
|
||||
MultipartEntries* = openArray[tuple[name, content: string]]
|
||||
MultipartData* = ref object
|
||||
content: seq[string]
|
||||
|
||||
@@ -323,7 +323,7 @@ proc parseBody(s: Socket, headers: HttpHeaders, httpVersion: string, timeout: in
|
||||
# (http://tools.ietf.org/html/rfc2616#section-4.4) NR.3
|
||||
var contentLengthHeader = headers.getOrDefault"Content-Length"
|
||||
if contentLengthHeader != "":
|
||||
var length = contentLengthHeader.parseint()
|
||||
var length = contentLengthHeader.parseInt()
|
||||
if length > 0:
|
||||
result = newString(length)
|
||||
var received = 0
|
||||
@@ -403,14 +403,14 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
|
||||
|
||||
when not defined(ssl):
|
||||
type SSLContext = ref object
|
||||
var defaultSSLContext {.threadvar.}: SSLContext
|
||||
var defaultSslContext {.threadvar.}: SSLContext
|
||||
|
||||
proc getDefaultSSL(): SSLContext =
|
||||
result = defaultSslContext
|
||||
when defined(ssl):
|
||||
if result == nil:
|
||||
defaultSSLContext = newContext(verifyMode = CVerifyNone)
|
||||
result = defaultSSLContext
|
||||
defaultSslContext = newContext(verifyMode = CVerifyNone)
|
||||
result = defaultSslContext
|
||||
doAssert result != nil, "failure to initialize the SSL context"
|
||||
|
||||
proc newProxy*(url: string, auth = ""): Proxy =
|
||||
@@ -463,7 +463,7 @@ proc newMultipartData*(xs: MultipartEntries): MultipartData =
|
||||
result = MultipartData(content: @[])
|
||||
result.add(xs)
|
||||
|
||||
proc addFiles*(p: var MultipartData, xs: openarray[tuple[name, file: string]]):
|
||||
proc addFiles*(p: var MultipartData, xs: openArray[tuple[name, file: string]]):
|
||||
MultipartData {.discardable.} =
|
||||
## Add files to a multipart data object. The file will be opened from your
|
||||
## disk, read and sent with the automatically determined MIME type. Raises an
|
||||
@@ -796,7 +796,7 @@ proc parseBody(client: HttpClient | AsyncHttpClient,
|
||||
# (http://tools.ietf.org/html/rfc2616#section-4.4) NR.3
|
||||
var contentLengthHeader = headers.getOrDefault"Content-Length"
|
||||
if contentLengthHeader != "":
|
||||
var length = contentLengthHeader.parseint()
|
||||
var length = contentLengthHeader.parseInt()
|
||||
client.contentTotal = length
|
||||
if length > 0:
|
||||
let recvLen = await client.recvFull(length, client.timeout, true)
|
||||
@@ -1036,7 +1036,7 @@ proc request*(client: HttpClient | AsyncHttpClient, url: string,
|
||||
|
||||
|
||||
proc request*(client: HttpClient | AsyncHttpClient, url: string,
|
||||
httpMethod = HttpGET, body = "",
|
||||
httpMethod = HttpGet, body = "",
|
||||
headers: HttpHeaders = nil): Future[Response | AsyncResponse]
|
||||
{.multisync.} =
|
||||
## Connects to the hostname specified by the URL and performs a request
|
||||
@@ -1065,14 +1065,14 @@ proc head*(client: HttpClient | AsyncHttpClient,
|
||||
## Connects to the hostname specified by the URL and performs a HEAD request.
|
||||
##
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
result = await client.request(url, HttpHEAD)
|
||||
result = await client.request(url, HttpHead)
|
||||
|
||||
proc get*(client: HttpClient | AsyncHttpClient,
|
||||
url: string): Future[Response | AsyncResponse] {.multisync.} =
|
||||
## Connects to the hostname specified by the URL and performs a GET request.
|
||||
##
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
result = await client.request(url, HttpGET)
|
||||
result = await client.request(url, HttpGet)
|
||||
|
||||
proc getContent*(client: HttpClient | AsyncHttpClient,
|
||||
url: string): Future[string] {.multisync.} =
|
||||
@@ -1084,7 +1084,7 @@ proc delete*(client: HttpClient | AsyncHttpClient,
|
||||
url: string): Future[Response | AsyncResponse] {.multisync.} =
|
||||
## Connects to the hostname specified by the URL and performs a DELETE request.
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
result = await client.request(url, HttpDELETE)
|
||||
result = await client.request(url, HttpDelete)
|
||||
|
||||
proc deleteContent*(client: HttpClient | AsyncHttpClient,
|
||||
url: string): Future[string] {.multisync.} =
|
||||
@@ -1113,7 +1113,7 @@ proc post*(client: HttpClient | AsyncHttpClient, url: string, body = "",
|
||||
## Connects to the hostname specified by the URL and performs a POST request.
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
var (xb, headers) = makeRequestContent(body, multipart)
|
||||
result = await client.request(url, $HttpPOST, xb, headers)
|
||||
result = await client.request(url, $HttpPost, xb, headers)
|
||||
|
||||
proc postContent*(client: HttpClient | AsyncHttpClient, url: string,
|
||||
body = "",
|
||||
@@ -1129,7 +1129,7 @@ proc put*(client: HttpClient | AsyncHttpClient, url: string, body = "",
|
||||
## Connects to the hostname specified by the URL and performs a PUT request.
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
var (xb, headers) = makeRequestContent(body, multipart)
|
||||
result = await client.request(url, $HttpPUT, xb, headers)
|
||||
result = await client.request(url, $HttpPut, xb, headers)
|
||||
|
||||
proc putContent*(client: HttpClient | AsyncHttpClient, url: string,
|
||||
body = "",
|
||||
@@ -1145,7 +1145,7 @@ proc patch*(client: HttpClient | AsyncHttpClient, url: string, body = "",
|
||||
## Connects to the hostname specified by the URL and performs a PATCH request.
|
||||
## This procedure uses httpClient values such as ``client.maxRedirects``.
|
||||
var (xb, headers) = makeRequestContent(body, multipart)
|
||||
result = await client.request(url, $HttpPATCH, xb, headers)
|
||||
result = await client.request(url, $HttpPatch, xb, headers)
|
||||
|
||||
proc patchContent*(client: HttpClient | AsyncHttpClient, url: string,
|
||||
body = "",
|
||||
|
||||
@@ -102,7 +102,7 @@ proc newHttpHeaders*(): HttpHeaders =
|
||||
result.table = newTable[string, seq[string]]()
|
||||
|
||||
proc newHttpHeaders*(keyValuePairs:
|
||||
openarray[tuple[key: string, val: string]]): HttpHeaders =
|
||||
openArray[tuple[key: string, val: string]]): HttpHeaders =
|
||||
var pairs: seq[tuple[key: string, val: seq[string]]] = @[]
|
||||
for pair in keyValuePairs:
|
||||
pairs.add((pair.key.toLowerAscii(), @[pair.val]))
|
||||
|
||||
@@ -75,7 +75,7 @@ proc newSelector*[T](): Selector[T] =
|
||||
# Retrieve the maximum fd count (for current OS) via getrlimit()
|
||||
var a = RLimit()
|
||||
if getrlimit(posix.RLIMIT_NOFILE, a) != 0:
|
||||
raiseOsError(osLastError())
|
||||
raiseOSError(osLastError())
|
||||
var maxFD = int(a.rlim_max)
|
||||
doAssert(maxFD > 0)
|
||||
# Start with a reasonable size, checkFd() will grow this on demand
|
||||
@@ -83,7 +83,7 @@ proc newSelector*[T](): Selector[T] =
|
||||
|
||||
var epollFD = epoll_create(MAX_EPOLL_EVENTS)
|
||||
if epollFD < 0:
|
||||
raiseOsError(osLastError())
|
||||
raiseOSError(osLastError())
|
||||
|
||||
when hasThreadSupport:
|
||||
result = cast[Selector[T]](allocShared0(sizeof(SelectorImpl[T])))
|
||||
@@ -369,7 +369,7 @@ proc registerEvent*[T](s: Selector[T], ev: SelectEvent, data: T) =
|
||||
inc(s.count)
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openarray[ReadyKey]): int =
|
||||
results: var openArray[ReadyKey]): int =
|
||||
var
|
||||
resTable: array[MAX_EPOLL_EVENTS, EpollEvent]
|
||||
maxres = MAX_EPOLL_EVENTS
|
||||
|
||||
@@ -440,7 +440,7 @@ proc unregister*[T](s: Selector[T], ev: SelectEvent) =
|
||||
dec(s.count)
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openarray[ReadyKey]): int =
|
||||
results: var openArray[ReadyKey]): int =
|
||||
var
|
||||
tv: Timespec
|
||||
resTable: array[MAX_KQUEUE_EVENTS, KEvent]
|
||||
|
||||
@@ -337,7 +337,7 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
|
||||
posix.gethostbyaddr(cast[cstring](addr(myaddr)), sizeof(myaddr).cint,
|
||||
cint(posix.AF_INET))
|
||||
else:
|
||||
posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
|
||||
posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).SockLen,
|
||||
cint(posix.AF_INET))
|
||||
if s == nil:
|
||||
raiseOSError(osLastError(), $hstrerror(h_errno))
|
||||
@@ -403,7 +403,7 @@ proc getHostname*(): string {.tags: [ReadIOEffect].} =
|
||||
let success = winlean.gethostname(result, size)
|
||||
else:
|
||||
# Posix
|
||||
let success = posix.getHostname(result, size)
|
||||
let success = posix.gethostname(result, size)
|
||||
if success != 0.cint:
|
||||
raiseOSError(osLastError())
|
||||
let x = len(cstring(result))
|
||||
|
||||
@@ -399,7 +399,7 @@ proc isIpAddress*(addressStr: string): bool {.tags: [].} =
|
||||
|
||||
proc toSockAddr*(address: IpAddress, port: Port, sa: var Sockaddr_storage,
|
||||
sl: var SockLen) =
|
||||
## Converts `IpAddress` and `Port` to `SockAddr` and `Socklen`
|
||||
## Converts `IpAddress` and `Port` to `SockAddr` and `SockLen`
|
||||
let port = htons(uint16(port))
|
||||
case address.family
|
||||
of IpAddressFamily.IPv4:
|
||||
@@ -437,7 +437,7 @@ proc fromSockAddrAux(sa: ptr Sockaddr_storage, sl: SockLen,
|
||||
|
||||
proc fromSockAddr*(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6,
|
||||
sl: SockLen, address: var IpAddress, port: var Port) {.inline.} =
|
||||
## Converts `SockAddr` and `Socklen` to `IpAddress` and `Port`. Raises
|
||||
## Converts `SockAddr` and `SockLen` to `IpAddress` and `Port`. Raises
|
||||
## `ObjectConversionError` in case of invalid `sa` and `sl` arguments.
|
||||
fromSockAddrAux(cast[ptr Sockaddr_storage](unsafeAddr sa), sl, address, port)
|
||||
|
||||
@@ -949,7 +949,7 @@ when defined(posix) or defined(nimdoc):
|
||||
when not defined(nimdoc):
|
||||
var socketAddr = makeUnixAddr(path)
|
||||
if socket.fd.connect(cast[ptr SockAddr](addr socketAddr),
|
||||
(sizeof(socketAddr.sun_family) + path.len).Socklen) != 0'i32:
|
||||
(sizeof(socketAddr.sun_family) + path.len).SockLen) != 0'i32:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
proc bindUnix*(socket: Socket, path: string) =
|
||||
@@ -958,7 +958,7 @@ when defined(posix) or defined(nimdoc):
|
||||
when not defined(nimdoc):
|
||||
var socketAddr = makeUnixAddr(path)
|
||||
if socket.fd.bindAddr(cast[ptr SockAddr](addr socketAddr),
|
||||
(sizeof(socketAddr.sun_family) + path.len).Socklen) != 0'i32:
|
||||
(sizeof(socketAddr.sun_family) + path.len).SockLen) != 0'i32:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
when defined(ssl):
|
||||
|
||||
Reference in New Issue
Block a user