diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-06 21:43:51 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-06 21:43:51 +0100 |
commit | d98b0d9f795969e594e95b9b3d0e0f56ee1f7c41 (patch) | |
tree | 29965563e5bf84effa55153a4a09510dc553d506 | |
parent | 9840a6912d8ba4fd348f265fb8733c62ac578be4 (diff) | |
download | Nim-d98b0d9f795969e594e95b9b3d0e0f56ee1f7c41.tar.gz |
Selectors module now uses select on operating systems other than Linux.
-rw-r--r-- | doc/lib.txt | 4 | ||||
-rw-r--r-- | lib/pure/selectors.nim | 32 | ||||
-rw-r--r-- | web/nimrod.ini | 2 |
3 files changed, 14 insertions, 24 deletions
diff --git a/doc/lib.txt b/doc/lib.txt index 92ca18ea1..62efe6a5d 100644 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -247,6 +247,10 @@ Internet Protocols and Support * `rawsockets <rawsockets.html>`_ 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 ------- diff --git a/lib/pure/selectors.nim b/lib/pure/selectors.nim index 454e77234..8085131f5 100644 --- a/lib/pure/selectors.nim +++ b/lib/pure/selectors.nim @@ -126,19 +126,12 @@ when defined(linux) or defined(nimdoc): else: 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 = ## Retrieves the selector key for ``fd``. return s.fds[fd] -elif defined(windows): +else: + # TODO: kqueue for bsd/mac os x. type PSelector* = ref object fds: TTable[TSocketHandle, PSelectorKey] @@ -228,11 +221,13 @@ elif defined(windows): proc `[]`*(s: PSelector, fd: TSocketHandle): PSelectorKey = return s.fds[fd] -elif defined(bsd) or defined(macosx): - # TODO: kqueue - {.error: "Sorry your platform is not supported yet.".} -else: - {.error: "Sorry your platform is not supported.".} +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 when isMainModule: # Select() @@ -258,12 +253,3 @@ when isMainModule: assert selector.unregister(sock.getFD).fd == sock.getFD selector.close() break - - - - - - - - - diff --git a/web/nimrod.ini b/web/nimrod.ini index 3160dc666..b29bcff30 100644 --- a/web/nimrod.ini +++ b/web/nimrod.ini @@ -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: "packages/docutils/rst;packages/docutils/rstast" 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/sqlite3;wrappers/postgres;wrappers/tinyc" |