private NioState synchronousAdd(final NioChannelHandler handler) { try { final SelectableChannel channel = handler.getChannel(); channel.configureBlocking(false); final int interestSet = handler.getInterestSet(); final NioState nioState = handlers.get(channel); if (nioState != null) { if (!nioState.attemptUpdateInterest(interestSet)) { handler.onEnd(); return null; } nioState.handlers.add(handler); return nioState; } final NioState value = new NioState(channel); value.key = channel.register(selector, interestSet, value); value.handlers.add(handler); handlers.put(channel, value); return value; } catch (IOException failed) { handler.onEnd(); //already closed/cancelled return null; } }
handlers.remove(attachment.channel); key.cancel(); attachment.onEnd(); break; nioState.onSelectorEnd();
handlers.remove(attachment.channel); key.cancel(); attachment.onEnd(); break; nioState.onSelectorEnd();
} else if (key.buffer == null) { final NioStateWrite handler = new NioStateWrite<>(accept, writeFailed, onBuffer); if (key.attemptUpdateInterest(handler.getInterestSet())) { handler.state = key; key.buffer = handler; key.addToBuffer(buffer);
} else if (key.buffer == null) { final NioStateWrite handler = new NioStateWrite<>(accept, writeFailed, onBuffer); if (key.attemptUpdateInterest(handler.getInterestSet())) { handler.state = key; key.buffer = handler; key.addToBuffer(buffer);
private NioState synchronousAdd(final NioChannelHandler handler) { try { final SelectableChannel channel = handler.getChannel(); channel.configureBlocking(false); final int interestSet = handler.getInterestSet(); final NioState nioState = handlers.get(channel); if (nioState != null) { if (!nioState.attemptUpdateInterest(interestSet)) { handler.onEnd(); return null; } nioState.handlers.add(handler); return nioState; } final NioState value = new NioState(channel); value.key = channel.register(selector, interestSet, value); value.handlers.add(handler); handlers.put(channel, value); return value; } catch (IOException failed) { handler.onEnd(); //already closed/cancelled return null; } }
@Override public boolean close(SelectableChannel channel) { closeQuietly(channel); final NioState nioState = handlers.remove(channel); if (nioState != null) { nioState.onEnd(); return true; } return false; } };
private NioChannelHandler.Result execEvent(SelectionKey key, NioState attachment) { try { return attachment.onSelect(executor, this, controls, key); } catch (CancelledKeyException invalid) { //key is cancelled, so remove all handlers. //this won't close the socket, but it is assumed that //the code that initiated the cancel knows whether the socket //should be closed return NioChannelHandler.Result.RemoveHandler; } }
@Override public boolean close(SelectableChannel channel) { closeQuietly(channel); final NioState nioState = handlers.remove(channel); if (nioState != null) { nioState.onEnd(); return true; } return false; } };
private NioChannelHandler.Result execEvent(SelectionKey key, NioState attachment) { try { return attachment.onSelect(executor, this, controls, key); } catch (CancelledKeyException invalid) { //key is cancelled, so remove all handlers. //this won't close the socket, but it is assumed that //the code that initiated the cancel knows whether the socket //should be closed return NioChannelHandler.Result.RemoveHandler; } }