diff options
author | max99x <max99x@gmail.com> | 2011-07-21 04:08:42 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-07-21 04:08:42 +0300 |
commit | 818de314d4d36f1cc0a7554c8f425ab842da5983 (patch) | |
tree | 94b13f86cc56a3817a6d148608c4aa7b62b1c07f /src | |
parent | 10ca04685b6e0ec0e8089fbe859e0085d8020622 (diff) |
Implemented <poll.h>.
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js index 793454de..3088fb3c 100644 --- a/src/library.js +++ b/src/library.js @@ -857,6 +857,36 @@ LibraryManager.library = { }, // ========================================================================== + // poll.h + // ========================================================================== + + __pollfd_struct_layout: Types.structDefinitions.pollfd, + poll__deps: ['$FS', '__setErrNo', '$ERRNO_CODES', '__pollfd_struct_layout'], + poll: function(fds, nfds, timeout) { + // int poll(struct pollfd fds[], nfds_t nfds, int timeout); + // http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html + // NOTE: This is pretty much a no-op mimicing glibc. + var members = ___pollfd_struct_layout.members; + var nonzero = 0; + for (var i = 0; i < nfds; i++) { + var pollfd = fds + ___pollfd_struct_layout.size * i; + var fd = {{{ makeGetValue('pollfd', 'members.fd.offset', 'i32') }}}; + var events = {{{ makeGetValue('pollfd', 'members.events.offset', 'i16') }}}; + var revents = 0; + if (fd in FS.streams) { + var stream = FS.streams[fd]; + if (events & 0x1) revents |= 0x1; // POLLIN. + if (events & 0x4) revents |= 0x4; // POLLOUT. + } else { + if (events & 0x20) revents |= 0x20; // POLLNVAL. + } + if (revents) nonzero++; + {{{ makeSetValue('pollfd', 'members.revents.offset', 'revents', 'i16') }}} + } + return nonzero; + }, + + // ========================================================================== _scanString: function() { // Supports %x, %4x, %d.%d, %s |