Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
This commit is contained in:
commit
1b97fcd448
5 changed files with 17 additions and 31 deletions
|
|
@ -247,6 +247,10 @@ Internet Protocols and Support
|
||||||
* `rawsockets <rawsockets.html>`_
|
* `rawsockets <rawsockets.html>`_
|
||||||
This module implements a low-level sockets API.
|
This module implements a low-level sockets API.
|
||||||
|
|
||||||
|
* `selectors <selectors.html>`_
|
||||||
|
This module implements a selector API with backends specific to each OS.
|
||||||
|
Currently epoll on Linux and select on other operating systems.
|
||||||
|
|
||||||
Parsers
|
Parsers
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -664,7 +664,6 @@ else:
|
||||||
var retFuture = newFuture[string]()
|
var retFuture = newFuture[string]()
|
||||||
|
|
||||||
var readBuffer = newString(size)
|
var readBuffer = newString(size)
|
||||||
var sizeRead = 0
|
|
||||||
|
|
||||||
proc cb(sock: TAsyncFD): bool =
|
proc cb(sock: TAsyncFD): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
@ -678,12 +677,11 @@ else:
|
||||||
else:
|
else:
|
||||||
result = false # We still want this callback to be called.
|
result = false # We still want this callback to be called.
|
||||||
elif res == 0:
|
elif res == 0:
|
||||||
#echo("Disconnected recv: ", sizeRead)
|
|
||||||
# Disconnected
|
# Disconnected
|
||||||
retFuture.complete("")
|
retFuture.complete("")
|
||||||
else:
|
else:
|
||||||
|
readBuffer.setLen(res)
|
||||||
retFuture.complete(readBuffer)
|
retFuture.complete(readBuffer)
|
||||||
#echo("Recv cb result: ", result)
|
|
||||||
|
|
||||||
addRead(socket, cb)
|
addRead(socket, cb)
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
|
||||||
|
|
@ -546,9 +546,6 @@ proc parseResponse(client: PAsyncHttpClient,
|
||||||
# Parse HTTP version info and status code.
|
# Parse HTTP version info and status code.
|
||||||
var le = skipIgnoreCase(line, "HTTP/", linei)
|
var le = skipIgnoreCase(line, "HTTP/", linei)
|
||||||
if le <= 0:
|
if le <= 0:
|
||||||
while true:
|
|
||||||
let nl = await client.socket.recvLine()
|
|
||||||
echo("Got another line: ", nl)
|
|
||||||
httpError("invalid http version, " & line.repr)
|
httpError("invalid http version, " & line.repr)
|
||||||
inc(linei, le)
|
inc(linei, le)
|
||||||
le = skipIgnoreCase(line, "1.1", linei)
|
le = skipIgnoreCase(line, "1.1", linei)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import tables, os, unsigned, hashes
|
||||||
|
|
||||||
when defined(linux): import posix, epoll
|
when defined(linux): import posix, epoll
|
||||||
elif defined(windows): import winlean
|
elif defined(windows): import winlean
|
||||||
|
else: import posix
|
||||||
|
|
||||||
proc hash*(x: TSocketHandle): THash {.borrow.}
|
proc hash*(x: TSocketHandle): THash {.borrow.}
|
||||||
proc `$`*(x: TSocketHandle): string {.borrow.}
|
proc `$`*(x: TSocketHandle): string {.borrow.}
|
||||||
|
|
@ -126,19 +127,12 @@ when defined(linux) or defined(nimdoc):
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc contains*(s: PSelector, key: PSelectorKey): bool =
|
|
||||||
## Determines whether selector contains this selector key. More accurate
|
|
||||||
## than checking if the file descriptor is in the selector because it
|
|
||||||
## ensures that the keys are equal. File descriptors may not always be
|
|
||||||
## unique especially when an fd is closed and then a new one is opened,
|
|
||||||
## the new one may have the same value.
|
|
||||||
return key.fd in s and s.fds[key.fd] == key
|
|
||||||
|
|
||||||
proc `[]`*(s: PSelector, fd: TSocketHandle): PSelectorKey =
|
proc `[]`*(s: PSelector, fd: TSocketHandle): PSelectorKey =
|
||||||
## Retrieves the selector key for ``fd``.
|
## Retrieves the selector key for ``fd``.
|
||||||
return s.fds[fd]
|
return s.fds[fd]
|
||||||
|
|
||||||
elif defined(windows):
|
else:
|
||||||
|
# TODO: kqueue for bsd/mac os x.
|
||||||
type
|
type
|
||||||
PSelector* = ref object
|
PSelector* = ref object
|
||||||
fds: TTable[TSocketHandle, PSelectorKey]
|
fds: TTable[TSocketHandle, PSelectorKey]
|
||||||
|
|
@ -228,11 +222,13 @@ elif defined(windows):
|
||||||
proc `[]`*(s: PSelector, fd: TSocketHandle): PSelectorKey =
|
proc `[]`*(s: PSelector, fd: TSocketHandle): PSelectorKey =
|
||||||
return s.fds[fd]
|
return s.fds[fd]
|
||||||
|
|
||||||
elif defined(bsd) or defined(macosx):
|
proc contains*(s: PSelector, key: PSelectorKey): bool =
|
||||||
# TODO: kqueue
|
## Determines whether selector contains this selector key. More accurate
|
||||||
{.error: "Sorry your platform is not supported yet.".}
|
## than checking if the file descriptor is in the selector because it
|
||||||
else:
|
## ensures that the keys are equal. File descriptors may not always be
|
||||||
{.error: "Sorry your platform is not supported.".}
|
## unique especially when an fd is closed and then a new one is opened,
|
||||||
|
## the new one may have the same value.
|
||||||
|
return key.fd in s and s.fds[key.fd] == key
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
# Select()
|
# Select()
|
||||||
|
|
@ -258,12 +254,3 @@ when isMainModule:
|
||||||
assert selector.unregister(sock.getFD).fd == sock.getFD
|
assert selector.unregister(sock.getFD).fd == sock.getFD
|
||||||
selector.close()
|
selector.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ srcdoc2: "pure/asyncio;pure/actors;core/locks;pure/oids;pure/endians;pure/uri"
|
||||||
srcdoc2: "pure/nimprof;pure/unittest;packages/docutils/highlite"
|
srcdoc2: "pure/nimprof;pure/unittest;packages/docutils/highlite"
|
||||||
srcdoc2: "packages/docutils/rst;packages/docutils/rstast"
|
srcdoc2: "packages/docutils/rst;packages/docutils/rstast"
|
||||||
srcdoc2: "packages/docutils/rstgen;pure/logging;pure/asyncdispatch;pure/asyncnet"
|
srcdoc2: "packages/docutils/rstgen;pure/logging;pure/asyncdispatch;pure/asyncnet"
|
||||||
srcdoc2: "pure/rawsockets;pure/asynchttpserver;pure/net"
|
srcdoc2: "pure/rawsockets;pure/asynchttpserver;pure/net;pure/selectors"
|
||||||
|
|
||||||
webdoc: "wrappers/libcurl;pure/md5;wrappers/mysql;wrappers/iup"
|
webdoc: "wrappers/libcurl;pure/md5;wrappers/mysql;wrappers/iup"
|
||||||
webdoc: "wrappers/sqlite3;wrappers/postgres;wrappers/tinyc"
|
webdoc: "wrappers/sqlite3;wrappers/postgres;wrappers/tinyc"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue