renamefest
This commit is contained in:
parent
2f43fdb837
commit
15a7bcc89f
5 changed files with 60 additions and 59 deletions
|
|
@ -431,7 +431,7 @@ proc getNumber(L: var TLexer): TToken =
|
||||||
lexMessage(L, errNumberOutOfRange, result.literal)
|
lexMessage(L, errNumberOutOfRange, result.literal)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
lexMessage(L, errInvalidNumber, result.literal)
|
lexMessage(L, errInvalidNumber, result.literal)
|
||||||
except OverflowError, EOutOfRange:
|
except OverflowError, RangeError:
|
||||||
lexMessage(L, errNumberOutOfRange, result.literal)
|
lexMessage(L, errNumberOutOfRange, result.literal)
|
||||||
L.bufpos = endpos
|
L.bufpos = endpos
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -951,7 +951,7 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
||||||
if res2 == - 1'i32: osError(osLastError())
|
if res2 == - 1'i32: osError(osLastError())
|
||||||
|
|
||||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect, FWriteIO].} =
|
tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
## Copies a file from `source` to `dest`.
|
## Copies a file from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `EOS` is raised. On the Windows platform this proc will
|
## If this fails, `EOS` is raised. On the Windows platform this proc will
|
||||||
|
|
@ -972,7 +972,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
else:
|
else:
|
||||||
# generic version of copyFile which works for any platform:
|
# generic version of copyFile which works for any platform:
|
||||||
const bufSize = 8000 # better for memory manager
|
const bufSize = 8000 # better for memory manager
|
||||||
var d, s: TFile
|
var d, s: File
|
||||||
if not open(s, source): osError(osLastError())
|
if not open(s, source): osError(osLastError())
|
||||||
if not open(d, dest, fmWrite):
|
if not open(d, dest, fmWrite):
|
||||||
close(s)
|
close(s)
|
||||||
|
|
@ -993,7 +993,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
close(d)
|
close(d)
|
||||||
|
|
||||||
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect, FWriteIO].} =
|
tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
|
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
|
||||||
if c_rename(source, dest) != 0'i32:
|
if c_rename(source, dest) != 0'i32:
|
||||||
raise newException(OSError, $strerror(errno))
|
raise newException(OSError, $strerror(errno))
|
||||||
|
|
@ -1031,7 +1031,7 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if c_remove(file) != 0'i32 and errno != ENOENT:
|
if c_remove(file) != 0'i32 and errno != ENOENT:
|
||||||
raise newException(EOS, $strerror(errno))
|
raise newException(OSError, $strerror(errno))
|
||||||
|
|
||||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||||
tags: [ExecIOEffect].} =
|
tags: [ExecIOEffect].} =
|
||||||
|
|
@ -1364,7 +1364,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||||
rawCreateDir(dir)
|
rawCreateDir(dir)
|
||||||
|
|
||||||
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [WriteIOEffect, FReadIO].} =
|
tags: [WriteIOEffect, ReadIOEffect].} =
|
||||||
## Copies a directory from `source` to `dest`.
|
## Copies a directory from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `EOS` is raised. On the Windows platform this proc will
|
## If this fails, `EOS` is raised. On the Windows platform this proc will
|
||||||
|
|
@ -1537,7 +1537,7 @@ proc copyFileWithPermissions*(source, dest: string,
|
||||||
|
|
||||||
proc copyDirWithPermissions*(source, dest: string,
|
proc copyDirWithPermissions*(source, dest: string,
|
||||||
ignorePermissionErrors = true) {.rtl, extern: "nos$1",
|
ignorePermissionErrors = true) {.rtl, extern: "nos$1",
|
||||||
tags: [WriteIOEffect, FReadIO].} =
|
tags: [WriteIOEffect, ReadIOEffect].} =
|
||||||
## Copies a directory from `source` to `dest` preserving file permissions.
|
## Copies a directory from `source` to `dest` preserving file permissions.
|
||||||
##
|
##
|
||||||
## If this fails, `EOS` is raised. This is a wrapper proc around `copyDir()
|
## If this fails, `EOS` is raised. This is a wrapper proc around `copyDir()
|
||||||
|
|
@ -1674,12 +1674,12 @@ elif not defined(createNimRtl):
|
||||||
cmdCount {.importc: "cmdCount".}: cint
|
cmdCount {.importc: "cmdCount".}: cint
|
||||||
cmdLine {.importc: "cmdLine".}: cstringArray
|
cmdLine {.importc: "cmdLine".}: cstringArray
|
||||||
|
|
||||||
proc paramStr*(i: int): TaintedString {.tags: [FReadIO].} =
|
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||||
# Docstring in nimdoc block.
|
# Docstring in nimdoc block.
|
||||||
if i < cmdCount and i >= 0: return TaintedString($cmdLine[i])
|
if i < cmdCount and i >= 0: return TaintedString($cmdLine[i])
|
||||||
raise newException(EInvalidIndex, "invalid index")
|
raise newException(IndexError, "invalid index")
|
||||||
|
|
||||||
proc paramCount*(): int {.tags: [FReadIO].} =
|
proc paramCount*(): int {.tags: [ReadIOEffect].} =
|
||||||
# Docstring in nimdoc block.
|
# Docstring in nimdoc block.
|
||||||
result = cmdCount-1
|
result = cmdCount-1
|
||||||
|
|
||||||
|
|
@ -1820,7 +1820,7 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
||||||
result = rdFileSize(a)
|
result = rdFileSize(a)
|
||||||
findClose(resA)
|
findClose(resA)
|
||||||
else:
|
else:
|
||||||
var f: TFile
|
var f: File
|
||||||
if open(f, file):
|
if open(f, file):
|
||||||
result = getFileSize(f)
|
result = getFileSize(f)
|
||||||
close(f)
|
close(f)
|
||||||
|
|
@ -1867,7 +1867,7 @@ when defined(Windows):
|
||||||
else:
|
else:
|
||||||
type
|
type
|
||||||
DeviceId* = TDev
|
DeviceId* = TDev
|
||||||
FileId* = TIno
|
FileId* = Tino
|
||||||
|
|
||||||
type
|
type
|
||||||
FileInfo* = object
|
FileInfo* = object
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ type
|
||||||
inHandle, outHandle, errHandle: FileHandle
|
inHandle, outHandle, errHandle: FileHandle
|
||||||
id: THandle
|
id: THandle
|
||||||
else:
|
else:
|
||||||
inHandle, outHandle, errHandle: TFileHandle
|
inHandle, outHandle, errHandle: FileHandle
|
||||||
inStream, outStream, errStream: PStream
|
inStream, outStream, errStream: PStream
|
||||||
id: TPid
|
id: TPid
|
||||||
exitCode: cint
|
exitCode: cint
|
||||||
|
|
@ -109,7 +109,7 @@ proc execProcess*(command: string,
|
||||||
poUsePath,
|
poUsePath,
|
||||||
poEvalCommand}): TaintedString {.
|
poEvalCommand}): TaintedString {.
|
||||||
rtl, extern: "nosp$1",
|
rtl, extern: "nosp$1",
|
||||||
tags: [ExecIOEffect, FReadIO].}
|
tags: [ExecIOEffect, ReadIOEffect].}
|
||||||
## A convenience procedure that executes ``command`` with ``startProcess``
|
## A convenience procedure that executes ``command`` with ``startProcess``
|
||||||
## and returns its output as a string.
|
## and returns its output as a string.
|
||||||
## WARNING: this function uses poEvalCommand by default for backward compatibility.
|
## WARNING: this function uses poEvalCommand by default for backward compatibility.
|
||||||
|
|
@ -233,7 +233,7 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
|
||||||
proc execProcesses*(cmds: openArray[string],
|
proc execProcesses*(cmds: openArray[string],
|
||||||
options = {poStdErrToStdOut, poParentStreams},
|
options = {poStdErrToStdOut, poParentStreams},
|
||||||
n = countProcessors()): int {.rtl, extern: "nosp$1",
|
n = countProcessors()): int {.rtl, extern: "nosp$1",
|
||||||
tags: [ExecIOEffect, FTime, FReadEnv]} =
|
tags: [ExecIOEffect, TimeEffect, FReadEnv]} =
|
||||||
## executes the commands `cmds` in parallel. Creates `n` processes
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
## that execute in parallel. The highest return value of all processes
|
## that execute in parallel. The highest return value of all processes
|
||||||
## is returned.
|
## is returned.
|
||||||
|
|
@ -584,12 +584,12 @@ elif not defined(useNimRtl):
|
||||||
|
|
||||||
when not defined(useFork):
|
when not defined(useFork):
|
||||||
proc startProcessAuxSpawn(data: TStartProcessData): TPid {.
|
proc startProcessAuxSpawn(data: TStartProcessData): TPid {.
|
||||||
tags: [FExecIO, FReadEnv], gcsafe.}
|
tags: [ExecIOEffect, FReadEnv], gcsafe.}
|
||||||
proc startProcessAuxFork(data: TStartProcessData): TPid {.
|
proc startProcessAuxFork(data: TStartProcessData): TPid {.
|
||||||
tags: [FExecIO, FReadEnv], gcsafe.}
|
tags: [ExecIOEffect, FReadEnv], gcsafe.}
|
||||||
{.push stacktrace: off, profiler: off.}
|
{.push stacktrace: off, profiler: off.}
|
||||||
proc startProcessAfterFork(data: ptr TStartProcessData) {.
|
proc startProcessAfterFork(data: ptr TStartProcessData) {.
|
||||||
tags: [FExecIO, FReadEnv], cdecl, gcsafe.}
|
tags: [ExecIOEffect, FReadEnv], cdecl, gcsafe.}
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
proc startProcess(command: string,
|
proc startProcess(command: string,
|
||||||
|
|
@ -850,9 +850,9 @@ elif not defined(useNimRtl):
|
||||||
if p.exitCode == -3: result = -1
|
if p.exitCode == -3: result = -1
|
||||||
else: result = p.exitCode.int shr 8
|
else: result = p.exitCode.int shr 8
|
||||||
|
|
||||||
proc createStream(stream: var PStream, handle: var TFileHandle,
|
proc createStream(stream: var PStream, handle: var FileHandle,
|
||||||
fileMode: TFileMode) =
|
fileMode: FileMode) =
|
||||||
var f: TFile
|
var f: File
|
||||||
if not open(f, handle, fileMode): osError(osLastError())
|
if not open(f, handle, fileMode): osError(osLastError())
|
||||||
stream = newFileStream(f)
|
stream = newFileStream(f)
|
||||||
|
|
||||||
|
|
@ -897,7 +897,7 @@ elif not defined(useNimRtl):
|
||||||
setLen(s, L)
|
setLen(s, L)
|
||||||
|
|
||||||
proc select(readfds: var seq[PProcess], timeout = 500): int =
|
proc select(readfds: var seq[PProcess], timeout = 500): int =
|
||||||
var tv: TTimeVal
|
var tv: Ttimeval
|
||||||
tv.tv_sec = 0
|
tv.tv_sec = 0
|
||||||
tv.tv_usec = timeout * 1000
|
tv.tv_usec = timeout * 1000
|
||||||
|
|
||||||
|
|
@ -916,7 +916,7 @@ elif not defined(useNimRtl):
|
||||||
proc execCmdEx*(command: string, options: set[TProcessOption] = {
|
proc execCmdEx*(command: string, options: set[TProcessOption] = {
|
||||||
poStdErrToStdOut, poUsePath}): tuple[
|
poStdErrToStdOut, poUsePath}): tuple[
|
||||||
output: TaintedString,
|
output: TaintedString,
|
||||||
exitCode: int] {.tags: [ExecIOEffect, FReadIO], gcsafe.} =
|
exitCode: int] {.tags: [ExecIOEffect, ReadIOEffect], gcsafe.} =
|
||||||
## a convenience proc that runs the `command`, grabs all its output and
|
## a convenience proc that runs the `command`, grabs all its output and
|
||||||
## exit code and returns both.
|
## exit code and returns both.
|
||||||
var p = startCmd(command, options)
|
var p = startCmd(command, options)
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ type
|
||||||
TReadLineResult* = enum ## result for readLineAsync
|
TReadLineResult* = enum ## result for readLineAsync
|
||||||
ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone
|
ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone
|
||||||
|
|
||||||
ETimeout* = object of ESynch
|
ETimeout* = object of Exception
|
||||||
|
|
||||||
let
|
let
|
||||||
invalidSocket*: TSocket = nil ## invalid socket
|
invalidSocket*: TSocket = nil ## invalid socket
|
||||||
|
|
@ -439,16 +439,16 @@ proc bindAddr*(socket: TSocket, port = TPort(0), address = "") {.
|
||||||
name.sin_port = sockets.htons(int16(port))
|
name.sin_port = sockets.htons(int16(port))
|
||||||
name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
|
name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
|
||||||
if bindSocket(socket.fd, cast[ptr TSockAddr](addr(name)),
|
if bindSocket(socket.fd, cast[ptr TSockAddr](addr(name)),
|
||||||
sizeof(name).TSockLen) < 0'i32:
|
sizeof(name).TSocklen) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
var hints: TAddrInfo
|
var hints: Taddrinfo
|
||||||
var aiList: ptr TAddrInfo = nil
|
var aiList: ptr Taddrinfo = nil
|
||||||
hints.ai_family = toInt(AF_INET)
|
hints.ai_family = toInt(AF_INET)
|
||||||
hints.ai_socktype = toInt(SOCK_STREAM)
|
hints.ai_socktype = toInt(SOCK_STREAM)
|
||||||
hints.ai_protocol = toInt(IPPROTO_TCP)
|
hints.ai_protocol = toInt(IPPROTO_TCP)
|
||||||
gaiNim(address, port, hints, aiList)
|
gaiNim(address, port, hints, aiList)
|
||||||
if bindSocket(socket.fd, aiList.ai_addr, aiList.ai_addrlen.TSockLen) < 0'i32:
|
if bindSocket(socket.fd, aiList.ai_addr, aiList.ai_addrlen.TSocklen) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc getSockName*(socket: TSocket): TPort =
|
proc getSockName*(socket: TSocket): TPort =
|
||||||
|
|
@ -460,7 +460,7 @@ proc getSockName*(socket: TSocket): TPort =
|
||||||
name.sin_family = posix.AF_INET
|
name.sin_family = posix.AF_INET
|
||||||
#name.sin_port = htons(cint16(port))
|
#name.sin_port = htons(cint16(port))
|
||||||
#name.sin_addr.s_addr = htonl(INADDR_ANY)
|
#name.sin_addr.s_addr = htonl(INADDR_ANY)
|
||||||
var namelen = sizeof(name).TSockLen
|
var namelen = sizeof(name).TSocklen
|
||||||
if getsockname(socket.fd, cast[ptr TSockAddr](addr(name)),
|
if getsockname(socket.fd, cast[ptr TSockAddr](addr(name)),
|
||||||
addr(namelen)) == -1'i32:
|
addr(namelen)) == -1'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
@ -470,7 +470,7 @@ template acceptAddrPlain(noClientRet, successRet: expr,
|
||||||
sslImplementation: stmt): stmt {.immediate.} =
|
sslImplementation: stmt): stmt {.immediate.} =
|
||||||
assert(client != nil)
|
assert(client != nil)
|
||||||
var sockAddress: Tsockaddr_in
|
var sockAddress: Tsockaddr_in
|
||||||
var addrLen = sizeof(sockAddress).TSockLen
|
var addrLen = sizeof(sockAddress).TSocklen
|
||||||
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
||||||
addr(addrLen))
|
addr(addrLen))
|
||||||
|
|
||||||
|
|
@ -685,7 +685,7 @@ proc getHostByAddr*(ip: string): Thostent {.tags: [ReadIOEffect].} =
|
||||||
var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).TSocklen,
|
var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).TSocklen,
|
||||||
cint(posix.AF_INET))
|
cint(posix.AF_INET))
|
||||||
if s == nil:
|
if s == nil:
|
||||||
raise newException(EOS, $hstrerror(h_errno))
|
raise newException(OSError, $hstrerror(h_errno))
|
||||||
|
|
||||||
result.name = $s.h_name
|
result.name = $s.h_name
|
||||||
result.aliases = cstringArrayToSeq(s.h_aliases)
|
result.aliases = cstringArrayToSeq(s.h_aliases)
|
||||||
|
|
@ -697,7 +697,7 @@ proc getHostByAddr*(ip: string): Thostent {.tags: [ReadIOEffect].} =
|
||||||
elif s.h_addrtype == posix.AF_INET6:
|
elif s.h_addrtype == posix.AF_INET6:
|
||||||
result.addrtype = AF_INET6
|
result.addrtype = AF_INET6
|
||||||
else:
|
else:
|
||||||
raise newException(EOS, "unknown h_addrtype")
|
raise newException(OSError, "unknown h_addrtype")
|
||||||
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
||||||
result.length = int(s.h_length)
|
result.length = int(s.h_length)
|
||||||
|
|
||||||
|
|
@ -718,7 +718,7 @@ proc getHostByName*(name: string): Thostent {.tags: [ReadIOEffect].} =
|
||||||
elif s.h_addrtype == posix.AF_INET6:
|
elif s.h_addrtype == posix.AF_INET6:
|
||||||
result.addrtype = AF_INET6
|
result.addrtype = AF_INET6
|
||||||
else:
|
else:
|
||||||
raise newException(EOS, "unknown h_addrtype")
|
raise newException(OSError, "unknown h_addrtype")
|
||||||
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
||||||
result.length = int(s.h_length)
|
result.length = int(s.h_length)
|
||||||
|
|
||||||
|
|
@ -726,7 +726,7 @@ proc getSockOptInt*(socket: TSocket, level, optname: int): int {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## getsockopt for integer options.
|
## getsockopt for integer options.
|
||||||
var res: cint
|
var res: cint
|
||||||
var size = sizeof(res).TSockLen
|
var size = sizeof(res).TSocklen
|
||||||
if getsockopt(socket.fd, cint(level), cint(optname),
|
if getsockopt(socket.fd, cint(level), cint(optname),
|
||||||
addr(res), addr(size)) < 0'i32:
|
addr(res), addr(size)) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
@ -737,7 +737,7 @@ proc setSockOptInt*(socket: TSocket, level, optname, optval: int) {.
|
||||||
## setsockopt for integer options.
|
## setsockopt for integer options.
|
||||||
var value = cint(optval)
|
var value = cint(optval)
|
||||||
if setsockopt(socket.fd, cint(level), cint(optname), addr(value),
|
if setsockopt(socket.fd, cint(level), cint(optname), addr(value),
|
||||||
sizeof(value).TSockLen) < 0'i32:
|
sizeof(value).TSocklen) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc toCInt(opt: TSOBool): cint =
|
proc toCInt(opt: TSOBool): cint =
|
||||||
|
|
@ -754,7 +754,7 @@ proc getSockOpt*(socket: TSocket, opt: TSOBool, level = SOL_SOCKET): bool {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## Retrieves option ``opt`` as a boolean value.
|
## Retrieves option ``opt`` as a boolean value.
|
||||||
var res: cint
|
var res: cint
|
||||||
var size = sizeof(res).TSockLen
|
var size = sizeof(res).TSocklen
|
||||||
if getsockopt(socket.fd, cint(level), toCInt(opt),
|
if getsockopt(socket.fd, cint(level), toCInt(opt),
|
||||||
addr(res), addr(size)) < 0'i32:
|
addr(res), addr(size)) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
@ -765,7 +765,7 @@ proc setSockOpt*(socket: TSocket, opt: TSOBool, value: bool, level = SOL_SOCKET)
|
||||||
## Sets option ``opt`` to a boolean value specified by ``value``.
|
## Sets option ``opt`` to a boolean value specified by ``value``.
|
||||||
var valuei = cint(if value: 1 else: 0)
|
var valuei = cint(if value: 1 else: 0)
|
||||||
if setsockopt(socket.fd, cint(level), toCInt(opt), addr(valuei),
|
if setsockopt(socket.fd, cint(level), toCInt(opt), addr(valuei),
|
||||||
sizeof(valuei).TSockLen) < 0'i32:
|
sizeof(valuei).TSocklen) < 0'i32:
|
||||||
osError(osLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc connect*(socket: TSocket, address: string, port = TPort(0),
|
proc connect*(socket: TSocket, address: string, port = TPort(0),
|
||||||
|
|
@ -776,8 +776,8 @@ proc connect*(socket: TSocket, address: string, port = TPort(0),
|
||||||
## not do it.
|
## not do it.
|
||||||
##
|
##
|
||||||
## If ``socket`` is an SSL socket a handshake will be automatically performed.
|
## If ``socket`` is an SSL socket a handshake will be automatically performed.
|
||||||
var hints: TAddrInfo
|
var hints: Taddrinfo
|
||||||
var aiList: ptr TAddrInfo = nil
|
var aiList: ptr Taddrinfo = nil
|
||||||
hints.ai_family = toInt(af)
|
hints.ai_family = toInt(af)
|
||||||
hints.ai_socktype = toInt(SOCK_STREAM)
|
hints.ai_socktype = toInt(SOCK_STREAM)
|
||||||
hints.ai_protocol = toInt(IPPROTO_TCP)
|
hints.ai_protocol = toInt(IPPROTO_TCP)
|
||||||
|
|
@ -787,7 +787,7 @@ proc connect*(socket: TSocket, address: string, port = TPort(0),
|
||||||
var lastError: TOSErrorCode
|
var lastError: TOSErrorCode
|
||||||
var it = aiList
|
var it = aiList
|
||||||
while it != nil:
|
while it != nil:
|
||||||
if connect(socket.fd, it.ai_addr, it.ai_addrlen.TSockLen) == 0'i32:
|
if connect(socket.fd, it.ai_addr, it.ai_addrlen.TSocklen) == 0'i32:
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
else: lastError = osLastError()
|
else: lastError = osLastError()
|
||||||
|
|
@ -839,8 +839,8 @@ proc connectAsync*(socket: TSocket, name: string, port = TPort(0),
|
||||||
##
|
##
|
||||||
## **Note**: For SSL sockets, the ``handshake`` procedure must be called
|
## **Note**: For SSL sockets, the ``handshake`` procedure must be called
|
||||||
## whenever the socket successfully connects to a server.
|
## whenever the socket successfully connects to a server.
|
||||||
var hints: TAddrInfo
|
var hints: Taddrinfo
|
||||||
var aiList: ptr TAddrInfo = nil
|
var aiList: ptr Taddrinfo = nil
|
||||||
hints.ai_family = toInt(af)
|
hints.ai_family = toInt(af)
|
||||||
hints.ai_socktype = toInt(SOCK_STREAM)
|
hints.ai_socktype = toInt(SOCK_STREAM)
|
||||||
hints.ai_protocol = toInt(IPPROTO_TCP)
|
hints.ai_protocol = toInt(IPPROTO_TCP)
|
||||||
|
|
@ -850,7 +850,7 @@ proc connectAsync*(socket: TSocket, name: string, port = TPort(0),
|
||||||
var lastError: TOSErrorCode
|
var lastError: TOSErrorCode
|
||||||
var it = aiList
|
var it = aiList
|
||||||
while it != nil:
|
while it != nil:
|
||||||
var ret = connect(socket.fd, it.ai_addr, it.ai_addrlen.TSockLen)
|
var ret = connect(socket.fd, it.ai_addr, it.ai_addrlen.TSocklen)
|
||||||
if ret == 0'i32:
|
if ret == 0'i32:
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
|
|
@ -915,7 +915,7 @@ when defined(ssl):
|
||||||
else:
|
else:
|
||||||
SSLError("Socket is not an SSL socket.")
|
SSLError("Socket is not an SSL socket.")
|
||||||
|
|
||||||
proc timeValFromMilliseconds(timeout = 500): TTimeval =
|
proc timeValFromMilliseconds(timeout = 500): Ttimeval =
|
||||||
if timeout != -1:
|
if timeout != -1:
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
|
|
@ -975,7 +975,7 @@ proc select*(readfds, writefds, exceptfds: var seq[TSocket],
|
||||||
if buffersFilled > 0:
|
if buffersFilled > 0:
|
||||||
return buffersFilled
|
return buffersFilled
|
||||||
|
|
||||||
var tv {.noInit.}: TTimeval = timeValFromMilliseconds(timeout)
|
var tv {.noInit.}: Ttimeval = timeValFromMilliseconds(timeout)
|
||||||
|
|
||||||
var rd, wr, ex: TFdSet
|
var rd, wr, ex: TFdSet
|
||||||
var m = 0
|
var m = 0
|
||||||
|
|
@ -998,7 +998,7 @@ proc select*(readfds, writefds: var seq[TSocket],
|
||||||
let buffersFilled = checkBuffer(readfds)
|
let buffersFilled = checkBuffer(readfds)
|
||||||
if buffersFilled > 0:
|
if buffersFilled > 0:
|
||||||
return buffersFilled
|
return buffersFilled
|
||||||
var tv {.noInit.}: TTimeval = timeValFromMilliseconds(timeout)
|
var tv {.noInit.}: Ttimeval = timeValFromMilliseconds(timeout)
|
||||||
|
|
||||||
var rd, wr: TFdSet
|
var rd, wr: TFdSet
|
||||||
var m = 0
|
var m = 0
|
||||||
|
|
@ -1022,7 +1022,7 @@ proc selectWrite*(writefds: var seq[TSocket],
|
||||||
##
|
##
|
||||||
## ``timeout`` is specified in miliseconds and ``-1`` can be specified for
|
## ``timeout`` is specified in miliseconds and ``-1`` can be specified for
|
||||||
## an unlimited time.
|
## an unlimited time.
|
||||||
var tv {.noInit.}: TTimeval = timeValFromMilliseconds(timeout)
|
var tv {.noInit.}: Ttimeval = timeValFromMilliseconds(timeout)
|
||||||
|
|
||||||
var wr: TFdSet
|
var wr: TFdSet
|
||||||
var m = 0
|
var m = 0
|
||||||
|
|
@ -1040,7 +1040,7 @@ proc select*(readfds: var seq[TSocket], timeout = 500): int =
|
||||||
let buffersFilled = checkBuffer(readfds)
|
let buffersFilled = checkBuffer(readfds)
|
||||||
if buffersFilled > 0:
|
if buffersFilled > 0:
|
||||||
return buffersFilled
|
return buffersFilled
|
||||||
var tv {.noInit.}: TTimeval = timeValFromMilliseconds(timeout)
|
var tv {.noInit.}: Ttimeval = timeValFromMilliseconds(timeout)
|
||||||
|
|
||||||
var rd: TFdSet
|
var rd: TFdSet
|
||||||
var m = 0
|
var m = 0
|
||||||
|
|
@ -1153,7 +1153,7 @@ proc waitFor(socket: TSocket, waited: var float, timeout, size: int,
|
||||||
waited += (epochTime() - startTime)
|
waited += (epochTime() - startTime)
|
||||||
|
|
||||||
proc recv*(socket: TSocket, data: pointer, size: int, timeout: int): int {.
|
proc recv*(socket: TSocket, data: pointer, size: int, timeout: int): int {.
|
||||||
tags: [ReadIOEffect, FTime].} =
|
tags: [ReadIOEffect, TimeEffect].} =
|
||||||
## overload with a ``timeout`` parameter in miliseconds.
|
## overload with a ``timeout`` parameter in miliseconds.
|
||||||
var waited = 0.0 # number of seconds already waited
|
var waited = 0.0 # number of seconds already waited
|
||||||
|
|
||||||
|
|
@ -1224,7 +1224,7 @@ proc peekChar(socket: TSocket, c: var char): int {.tags: [ReadIOEffect].} =
|
||||||
result = recv(socket.fd, addr(c), 1, MSG_PEEK)
|
result = recv(socket.fd, addr(c), 1, MSG_PEEK)
|
||||||
|
|
||||||
proc recvLine*(socket: TSocket, line: var TaintedString, timeout = -1): bool {.
|
proc recvLine*(socket: TSocket, line: var TaintedString, timeout = -1): bool {.
|
||||||
tags: [ReadIOEffect, FTime], deprecated.} =
|
tags: [ReadIOEffect, TimeEffect], deprecated.} =
|
||||||
## Receive a line of data from ``socket``.
|
## Receive a line of data from ``socket``.
|
||||||
##
|
##
|
||||||
## If a full line is received ``\r\L`` is not
|
## If a full line is received ``\r\L`` is not
|
||||||
|
|
@ -1271,7 +1271,7 @@ proc recvLine*(socket: TSocket, line: var TaintedString, timeout = -1): bool {.
|
||||||
add(line.string, c)
|
add(line.string, c)
|
||||||
|
|
||||||
proc readLine*(socket: TSocket, line: var TaintedString, timeout = -1) {.
|
proc readLine*(socket: TSocket, line: var TaintedString, timeout = -1) {.
|
||||||
tags: [ReadIOEffect, FTime].} =
|
tags: [ReadIOEffect, TimeEffect].} =
|
||||||
## Reads a line of data from ``socket``.
|
## Reads a line of data from ``socket``.
|
||||||
##
|
##
|
||||||
## If a full line is read ``\r\L`` is not
|
## If a full line is read ``\r\L`` is not
|
||||||
|
|
@ -1493,7 +1493,7 @@ proc recvFrom*(socket: TSocket, data: var string, length: int,
|
||||||
# TODO: Buffered sockets
|
# TODO: Buffered sockets
|
||||||
data.setLen(length)
|
data.setLen(length)
|
||||||
var sockAddress: Tsockaddr_in
|
var sockAddress: Tsockaddr_in
|
||||||
var addrLen = sizeof(sockAddress).TSockLen
|
var addrLen = sizeof(sockAddress).TSocklen
|
||||||
result = recvfrom(socket.fd, cstring(data), length.cint, flags.cint,
|
result = recvfrom(socket.fd, cstring(data), length.cint, flags.cint,
|
||||||
cast[ptr TSockAddr](addr(sockAddress)), addr(addrLen))
|
cast[ptr TSockAddr](addr(sockAddress)), addr(addrLen))
|
||||||
|
|
||||||
|
|
@ -1627,8 +1627,8 @@ proc sendTo*(socket: TSocket, address: string, port: TPort, data: pointer,
|
||||||
## this function will try each IP of that hostname.
|
## this function will try each IP of that hostname.
|
||||||
##
|
##
|
||||||
## **Note:** This proc is not available for SSL sockets.
|
## **Note:** This proc is not available for SSL sockets.
|
||||||
var hints: TAddrInfo
|
var hints: Taddrinfo
|
||||||
var aiList: ptr TAddrInfo = nil
|
var aiList: ptr Taddrinfo = nil
|
||||||
hints.ai_family = toInt(af)
|
hints.ai_family = toInt(af)
|
||||||
hints.ai_socktype = toInt(SOCK_STREAM)
|
hints.ai_socktype = toInt(SOCK_STREAM)
|
||||||
hints.ai_protocol = toInt(IPPROTO_TCP)
|
hints.ai_protocol = toInt(IPPROTO_TCP)
|
||||||
|
|
@ -1639,7 +1639,7 @@ proc sendTo*(socket: TSocket, address: string, port: TPort, data: pointer,
|
||||||
var it = aiList
|
var it = aiList
|
||||||
while it != nil:
|
while it != nil:
|
||||||
result = sendto(socket.fd, data, size.cint, flags.cint, it.ai_addr,
|
result = sendto(socket.fd, data, size.cint, flags.cint, it.ai_addr,
|
||||||
it.ai_addrlen.TSockLen)
|
it.ai_addrlen.TSocklen)
|
||||||
if result != -1'i32:
|
if result != -1'i32:
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
|
|
@ -1685,7 +1685,7 @@ discard """ proc setReuseAddr*(s: TSocket) =
|
||||||
OSError(OSLastError()) """
|
OSError(OSLastError()) """
|
||||||
|
|
||||||
proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
|
proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
|
||||||
af: TDomain = AF_INET) {.tags: [ReadIOEffect, FWriteIO].} =
|
af: TDomain = AF_INET) {.tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
## Connects to server as specified by ``address`` on port specified by ``port``.
|
## Connects to server as specified by ``address`` on port specified by ``port``.
|
||||||
##
|
##
|
||||||
## The ``timeout`` paremeter specifies the time in miliseconds to allow for
|
## The ``timeout`` paremeter specifies the time in miliseconds to allow for
|
||||||
|
|
|
||||||
|
|
@ -384,11 +384,11 @@ type
|
||||||
##
|
##
|
||||||
## This happens for calculations whose results are too large to fit in the
|
## This happens for calculations whose results are too large to fit in the
|
||||||
## provided bits. See the full `exception hierarchy`_.
|
## provided bits. See the full `exception hierarchy`_.
|
||||||
AccessViolationError* {.compilerproc.} = object of Exception ## \
|
AccessViolationError* = object of Exception ## \
|
||||||
## Raised for invalid memory access errors
|
## Raised for invalid memory access errors
|
||||||
##
|
##
|
||||||
## See the full `exception hierarchy`_.
|
## See the full `exception hierarchy`_.
|
||||||
AssertionError* {.compilerproc.} = object of Exception ## \
|
AssertionError* = object of Exception ## \
|
||||||
## Raised when assertion is proved wrong.
|
## Raised when assertion is proved wrong.
|
||||||
##
|
##
|
||||||
## Usually the result of using the `assert() template <#assert>`_. See the
|
## Usually the result of using the `assert() template <#assert>`_. See the
|
||||||
|
|
@ -496,7 +496,8 @@ type
|
||||||
EFloatingPoint: FloatingPointError,
|
EFloatingPoint: FloatingPointError,
|
||||||
EFloatInvalidOp: FloatInvalidOpError,
|
EFloatInvalidOp: FloatInvalidOpError,
|
||||||
EFloatDivByZero: FloatDivByZeroError,
|
EFloatDivByZero: FloatDivByZeroError,
|
||||||
EFloatOverflow: FloatOverflowError
|
EFloatOverflow: FloatOverflowError,
|
||||||
|
ESynch: Exception
|
||||||
].}
|
].}
|
||||||
|
|
||||||
proc sizeof*[T](x: T): Natural {.magic: "SizeOf", noSideEffect.}
|
proc sizeof*[T](x: T): Natural {.magic: "SizeOf", noSideEffect.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue