diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-02-04 19:00:09 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-02-04 19:00:09 -0800 |
commit | 27841ea86c6be6f96a2ab777a19d00686c551ed9 (patch) | |
tree | 9411fc0455311a7de1c979b2728be0c5a690df50 | |
parent | 4d92685fcbb75db54a5f1a090c31a8fd67b8b1f7 (diff) |
refactor sockets code
-rw-r--r-- | src/library.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js index 623d1626..aa93598e 100644 --- a/src/library.js +++ b/src/library.js @@ -6906,8 +6906,9 @@ LibraryManager.library = { var i8Temp = new Uint8Array(i32Temp.buffer); info.inQueue = []; + info.hasData = function() { return info.inQueue.length > 0 } if (!info.stream) { - var partialBuffer = null; // inQueue contains full dgram messages; this buffers incomplete data. Must begin with the beginning of a message + var partialBuffer = null; // in datagram mode, inQueue contains full dgram messages; this buffers incomplete data. Must begin with the beginning of a message } info.socket.onmessage = function(event) { @@ -7043,7 +7044,7 @@ LibraryManager.library = { recv: function(fd, buf, len, flags) { var info = Sockets.fds[fd]; if (!info) return -1; - if (info.inQueue.length == 0) { + if (!info.hasData()) { ___setErrNo(ERRNO_CODES.EAGAIN); // no data, and all sockets are nonblocking, so this is the right behavior return -1; } @@ -7114,7 +7115,7 @@ LibraryManager.library = { assert(name, 'sendmsg on non-connected socket, and no name/address in the message'); _connect(fd, name, {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_namelen', 'i32') }}}); } - if (info.inQueue.length == 0) { + if (!info.hasData()) { ___setErrNo(ERRNO_CODES.EWOULDBLOCK); return -1; } @@ -7179,7 +7180,7 @@ LibraryManager.library = { var info = Sockets.fds[fd]; if (!info) return -1; var bytes = 0; - if (info.inQueue.length > 0) { + if (info.hasData()) { bytes = info.inQueue[0].length; } var dest = {{{ makeGetValue('varargs', '0', 'i32') }}}; @@ -7229,7 +7230,7 @@ LibraryManager.library = { // index is in the set, check if it is ready for read var info = Sockets.fds[fd]; if (!info) continue; - if (info.inQueue.length > 0) ret++; + if (info.hasData()) ret++; } } return ret; |