if ( handshake == 0 ) {
// Process the request from this socket
if ((status != null) && (handler.event(socket, status) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
KeyAttachment att = (KeyAttachment)socket.getAttachment(true);
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
key.cancel();
key.attach(null);
nioChannels.offer(socket);
if ( att!=null ) keyCache.offer(att);
}catch ( Exception x ) {
log.error("",x);
}
} else if ((status == null) && (handler.process(socket) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
KeyAttachment att = (KeyAttachment)socket.getAttachment(true);
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
key.cancel();
key.attach(null);
nioChannels.offer(socket);
if ( att!=null ) keyCache.offer(att);
}catch ( Exception x ) {
log.error("",x);
}
}
} else if (handshake == -1 ) {
socket.getPoller().cancelledKey(key,SocketStatus.DISCONNECT);
try {socket.close(true);}catch (IOException ignore){}
nioChannels.offer(socket);
} else {
final SelectionKey fk = key;
final int intops = handshake;
final KeyAttachment ka = (KeyAttachment)fk.attachment();
ka.getPoller().add(socket,intops);
}
}
} finally {
//dereference socket to let GC do its job
socket = null;