Added asyncio module; irc, scgi and the ftpclient modules work with it. Added (de)allocCStringArray. Many async sockets fixes.

This commit is contained in:
dom96 2012-01-22 16:21:05 +00:00
commit b298b07567
8 changed files with 812 additions and 192 deletions

View file

@ -1783,6 +1783,24 @@ when not defined(EcmaScript) and not defined(NimrodVM):
while a[L] != nil: inc(L)
result = cstringArrayToSeq(a, L)
proc allocCStringArray*(a: openArray[string]): cstringArray =
## creates a NULL terminated cstringArray from `a`. The result has to
## be freed with `deallocCStringArray` after it's not needed anymore.
result = cast[cstringArray](alloc0((a.len+1) * sizeof(cstring)))
for i in 0 .. a.high:
# XXX get rid of this string copy here:
var x = a[i]
result[i] = cast[cstring](alloc0(x.len+1))
copyMem(result[i], addr(x[0]), x.len)
proc deallocCStringArray*(a: cstringArray) =
## frees a NULL terminated cstringArray.
var i = 0
while a[i] != nil:
dealloc(a[i])
inc(i)
dealloc(a)
# ----------------------------------------------------------------------------
proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, discardable.}