final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
final KeyAttachment att = (KeyAttachment)key.attachment();
//to do, add in a check, we might have just timed out on the wait,
//so there is no need to register us again.
boolean addToQueue = false;
try { addToQueue = ((att.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ckx ){ throw new IOException("Socket key cancelled.");}
if ( addToQueue ) {
synchronized (att.getMutex()) {
addToReadQueue(key, att);
att.getMutex().wait(readTimeout);
}