Closed wsky closed 11 years ago
as NIO Selector is readable when processbuffer, in the same io-thread just can read and pend message to sendbuffer
for (SelectionKey key : selector.selectedKeys()) {
if (key.isValid() && key.isWritable() && upstreamQueue.peek() != null) {
SocketChannel channel = (SocketChannel) key
.channel();
channel.write(upstreamQueue.poll());
socket.register(selector, OP_READ);
} else if (key.isValid() && key.isReadable()) {
read(socket, downstreamBuffer); // read
// response
switch (state) {
case HANDSHAKE: // CONNECTED -> HANDSHAKE
pipeline.sendHandshakeDownstream(WebSocketBase.this, downstreamBuffer);
if (getHandshake().isDone()){
processBuffer(downstreamBuffer);
handshakeLatch.countDown();
}
break;
case WAIT: // read frames
case CLOSING:
processBuffer(downstreamBuffer);
break;
default:
break;
}
}
always timeout if onMessage raised in io-thread
after enable scheduler that onMessage called in business thread, it works.