aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-02 14:27:42 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-02 14:27:42 -0800
commit4485acfbd300ccecd86e37a3d8fdb9c9ade5e541 (patch)
treea1754dd11c9dfb3ee8244f871f1ced0ce5949f3a /src
parentfaf6b1d3504a8e999d94469abf92938492bedb7b (diff)
select()
Diffstat (limited to 'src')
-rw-r--r--src/library.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 42eb951f..75a8a90a 100644
--- a/src/library.js
+++ b/src/library.js
@@ -7058,6 +7058,26 @@ LibraryManager.library = {
return fd;
},
+ select: function(nfds, readfds, writefds, exceptfds, timeout) {
+ // only readfds are supported, not writefds or exceptfds
+ // timeout is always 0 - fully async
+ assert(!writefds && !exceptfds);
+ var ret = 0;
+ var l = {{{ makeGetValue('readfds', 0, 'i32') }}};
+ var h = {{{ makeGetValue('readfds', 4, 'i32') }}};
+ nfds = Math.min(64, nfds); // fd sets have 64 bits
+ for (var fd = 0; fd < nfds; fd++) {
+ var bit = fd % 32, int = fd < 32 ? l : h;
+ if (int & (1 << bit)) {
+ // index is in the set, check if it is ready for read
+ var info = Sockets.fds[fd];
+ if (!info) continue;
+ if (info.bufferWrite != info.bufferRead) ret++;
+ }
+ }
+ return ret;
+ },
+
// ==========================================================================
// emscripten.h
// ==========================================================================