Networking work-in-progress:

De-register a peer's socket channel OP_READ interest op when producing a ChannelTask for that peer.
This should prevent duplicate ChannelTasks for the same peer.

Re-register OP_READ once node has read from peer's channel.
This commit is contained in:
catbref 2022-03-19 13:19:29 +00:00
parent 6255b2a907
commit b0e6259073

View File

@ -596,6 +596,10 @@ public class Network {
try {
peer.readChannel();
LOGGER.trace("Thread {} re-registering OP_READ interestOps on channel: {}",
Thread.currentThread().getId(), socketChannel);
socketChannel.register(channelSelector, SelectionKey.OP_READ);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().toLowerCase().contains("connection reset")) {
peer.disconnect("Connection reset");
@ -637,6 +641,12 @@ public class Network {
if (channelIterator.hasNext()) {
nextSelectionKey = channelIterator.next();
channelIterator.remove();
if (nextSelectionKey.isReadable()) {
LOGGER.trace("Thread {} clearing all interestOps on channel: {}",
Thread.currentThread().getId(), nextSelectionKey.channel());
nextSelectionKey.interestOps(0);
}
} else {
nextSelectionKey = null;
channelIterator = null; // Nothing to do so reset iterator to cause new select