aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
authorMichael Riss <Michael.Riss@gmx.de>2013-03-09 17:51:42 +0100
committerMichael Riss <Michael.Riss@gmx.de>2013-03-22 17:00:00 +0100
commit4790550b897061a8d67368eeb497e671107174a5 (patch)
tree7dbd3127c66f1155a4e49af06676a535c922ef8f /src/library.js
parent0250c45a5b9c955a38436e62ca81041515723bf7 (diff)
Move error check into canRead function and use an outer scope variable to report the error condition.
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js21
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;
}
},