try {\r
final SelectionKey key = socket.keyFor(poller.getSelector());\r
final KeyAttachment att = (KeyAttachment)key.attachment();\r
- att.setWakeUp(true);\r
- \r
- poller.addEvent(\r
- new Runnable() {\r
+ //to do, add in a check, we might have just timed out on the wait,\r
+ //so there is no need to register us again.\r
+ boolean addToQueue = false;\r
+ try { addToQueue = ((key.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ignore ){}\r
+ if ( addToQueue ) {\r
+ att.setWakeUp(true);\r
+ poller.addEvent(\r
+ new Runnable() {\r
public void run() {\r
try {\r
if (key != null) key.interestOps(SelectionKey.OP_READ);\r
} catch (Exception ignore) {}\r
}\r
}\r
- });\r
- synchronized (att.getMutex()) { att.getMutex().wait(25);}\r
+ });\r
+ }//end if\r
+ synchronized (att.getMutex()) {\r
+ if ( att.getWakeUp() ) att.getMutex().wait(25);\r
+ }\r
}catch ( Exception x ) {}\r
}while ( nRead == 0 && (!timedOut) );\r
//else throw new IOException(sm.getString("iib.failedread"));\r
- return false; //timeout\r
+ //return false; //timeout\r
+ throw new IOException("read timed out.");\r
}\r
\r
\r