Merge branch 'devel' of https://github.com/Araq/Nimrod into devel

This commit is contained in:
Araq
2014-04-20 01:19:10 +02:00
43 changed files with 123 additions and 61 deletions

View File

@@ -196,7 +196,7 @@ proc `==`*[A, B](s, t: TTable[A, B]): bool =
# to use the slow route here:
for key, val in s:
if not hasKey(t, key): return false
if mget(t, key) != val: return false
if t[key] != val: return false
return true
proc indexBy*[A, B, C](collection: A, index: proc(x: B): C): TTable[C, B] =

View File

@@ -107,6 +107,7 @@ proc ftpClient*(address: string, port = TPort(21),
result.isAsync = false
result.dsockConnected = false
result.csock = socket()
if result.csock == InvalidSocket: osError(osLastError())
proc getDSock(ftp: PFTPClient): TSocket =
if ftp.isAsync: return ftp.asyncDSock else: return ftp.dsock
@@ -213,6 +214,7 @@ proc pasv(ftp: PFTPClient) =
## Negotiate a data connection.
if not ftp.isAsync:
ftp.dsock = socket()
if ftp.dsock == InvalidSocket: osError(osLastError())
else:
ftp.asyncDSock = AsyncSocket()
ftp.asyncDSock.handleRead =

View File

@@ -75,7 +75,7 @@
## constructor should be used for this purpose. However,
## currently only basic authentication is supported.
import sockets, strutils, parseurl, parseutils, strtabs, base64
import sockets, strutils, parseurl, parseutils, strtabs, base64, os
import asyncnet, asyncdispatch
import rawsockets
@@ -288,6 +288,7 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
add(headers, "\c\L")
var s = socket()
if s == InvalidSocket: osError(osLastError())
var port = sockets.TPort(80)
if r.scheme == "https":
when defined(ssl):

View File

@@ -249,6 +249,7 @@ proc reconnect*(irc: PIRC, timeout = 5000) =
if secSinceReconnect < timeout:
sleep(timeout - secSinceReconnect)
irc.sock = socket()
if irc.sock == InvalidSocket: osError(osLastError())
irc.connect()
irc.lastReconnect = epochTime()
@@ -274,6 +275,7 @@ proc irc*(address: string, port: TPort = 6667.TPort,
result.messageBuffer = @[]
result.status = SockIdle
result.sock = socket()
if result.sock == InvalidSocket: osError(osLastError())
proc processLine(irc: PIRC, line: string): TIRCEvent =
if line.len == 0:

View File

@@ -137,6 +137,14 @@ proc startProcess*(command: string,
## to `startProcess`. See the documentation of ``TProcessOption`` for the
## meaning of these flags. You need to `close` the process when done.
##
## Note that you can't pass any `args` if you use the option
## ``poEvalCommand``, which invokes the system shell to run the specified
## `command`. In this situation you have to concatenate manually the contents
## of `args` to `command` carefully escaping/quoting any special characters,
## since it will be passed *as is* to the system shell. Each system/shell may
## feature different escaping rules, so try to avoid this kind of shell
## invokation if possible as it leads to non portable software.
##
## Return value: The newly created process object. Nil is never returned,
## but ``EOS`` is raised in case of an error.
@@ -633,7 +641,7 @@ elif not defined(useNimRtl):
if poEvalCommand in options:
sysCommand = "/bin/sh"
sysArgsRaw = @[sysCommand, "-c", command]
assert args.len == 0
assert args.len == 0, "`args` has to be empty when using poEvalCommand."
else:
sysCommand = command
sysArgsRaw = @[command]

View File

@@ -102,6 +102,7 @@ proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1",
s.input = newString(s.buflen) # will be reused
s.server = socket()
if s.server == InvalidSocket: osError(osLastError())
new(s.client) # Initialise s.client for `next`
if s.server == InvalidSocket: scgiError("could not open socket")
#s.server.connect(connectionName, port)

View File

@@ -238,6 +238,7 @@ when isMainModule:
sock: TSocket
var sock = socket()
if sock == sockets.InvalidSocket: osError(osLastError())
#sock.setBlocking(false)
sock.connect("irc.freenode.net", TPort(6667))

View File

@@ -178,7 +178,7 @@ proc hash(data: pointer, size: int): THash =
while s > 0:
h = h !& ord(p[i])
inc(i)
cec(s)
dec(s)
result = !$h
proc hashGcHeader(data: pointer): THash =

View File

@@ -90,6 +90,7 @@ const
SQLITE_IGNORE* = 2 # Original from sqlite3.h:
##define SQLITE_STATIC ((void(*)(void *))0)
##define SQLITE_TRANSIENT ((void(*)(void *))-1)
SQLITE_DETERMINISTIC* = 0x800
const
SQLITE_STATIC* = nil