From b5aff635a6793874b6fca109ecaf4994990cb586 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 3 Oct 2021 21:42:31 +0000 Subject: [PATCH] [NioPeerHandler] Un-set Read interest when we fail to write fully ...as required by the SocketDescriptor.send_data API docs --- src/main/java/org/ldk/batteries/NioPeerHandler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ldk/batteries/NioPeerHandler.java b/src/main/java/org/ldk/batteries/NioPeerHandler.java index b722d96d..71d31938 100644 --- a/src/main/java/org/ldk/batteries/NioPeerHandler.java +++ b/src/main/java/org/ldk/batteries/NioPeerHandler.java @@ -61,13 +61,14 @@ public class NioPeerHandler { @Override public long send_data(byte[] data, boolean resume_read) { try { - if (resume_read) { - do_selector_action(() -> peer.key.interestOps(peer.key.interestOps() | SelectionKey.OP_READ)); - } long written = chan.write(ByteBuffer.wrap(data)); if (written != data.length) { - do_selector_action(() -> peer.key.interestOps(peer.key.interestOps() | SelectionKey.OP_WRITE)); - } + do_selector_action(() -> peer.key.interestOps( + (peer.key.interestOps() | SelectionKey.OP_WRITE) & (~SelectionKey.OP_READ))); + } else if (resume_read) { + do_selector_action(() -> peer.key.interestOps( + (peer.key.interestOps() | SelectionKey.OP_READ) & (~SelectionKey.OP_WRITE))); + } return written; } catch (IOException e) { // Most likely the socket is disconnected, let the background thread handle it. -- 2.39.5