diff options
author | Michael Riss <Michael.Riss@gmx.de> | 2013-03-09 17:51:42 +0100 |
---|---|---|
committer | Michael Riss <Michael.Riss@gmx.de> | 2013-03-22 17:00:00 +0100 |
commit | 4790550b897061a8d67368eeb497e671107174a5 (patch) | |
tree | 7dbd3127c66f1155a4e49af06676a535c922ef8f | |
parent | 0250c45a5b9c955a38436e62ca81041515723bf7 (diff) |
Move error check into canRead function and use an outer scope variable to report the error condition.
-rw-r--r-- | src/library.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/library.js b/src/library.js index 00c7cfc7..000b625c 100644 --- a/src/library.js +++ b/src/library.js @@ -7288,11 +7288,17 @@ LibraryManager.library = { // exceptfds not supported // timeout is always 0 - fully async assert(!exceptfds); + + var errorCondition = 0; function canRead(info) { // make sure hasData exists. // we do create it when the socket is connected, // but other implementations may create it lazily + if ((info.socket.readyState == WebSocket.CLOSING || info.socket.readyState == WebSocket.CLOSED) && info.inQueue.length == 0) { + errorCondition = -1; + return false; + } return info.hasData && info.hasData(); } @@ -7318,12 +7324,7 @@ LibraryManager.library = { if (int & mask) { // index is in the set, check if it is ready for read var info = Sockets.fds[fd]; - if (!info) continue; - if ((info.socket.readyState == WebSocket.CLOSING || info.socket.readyState == WebSocket.CLOSED) && info.inQueue.length == 0) { - ___setErrNo(ERRNO_CODES.EBADF); - return -1; - } - if (can(info)) { + if (info && can(info)) { // set bit fd < 32 ? (dstLow = dstLow | mask) : (dstHigh = dstHigh | mask); bitsSet++; @@ -7336,12 +7337,12 @@ LibraryManager.library = { return bitsSet; } - var readHandles = checkfds(nfds, readfds, canRead); - var writeHandles = checkfds(nfds, writefds, canWrite); - if ((readHandles == -1) || (writeHandles == -1)){ + var totalHandles = checkfds(nfds, readfds, canRead) + checkfds(nfds, writefds, canWrite); + if (errorCondition) { + ___setErrNo(ERRNO_CODES.EBADF); return -1; } else { - return readHandles + writeHandles; + return totalHandles; } }, |