From: Matt Corallo Date: Sun, 3 Oct 2021 21:42:31 +0000 (+0000) Subject: [NioPeerHandler] Un-set Read interest when we fail to write fully X-Git-Tag: v0.0.101.3^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b5aff635a6793874b6fca109ecaf4994990cb586;p=ldk-java [NioPeerHandler] Un-set Read interest when we fail to write fully ...as required by the SocketDescriptor.send_data API docs --- 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.