]> git.bitcoin.ninja Git - ldk-java/commitdiff
[NioPeerHandler] Un-set Read interest when we fail to write fully
authorMatt Corallo <git@bluematt.me>
Sun, 3 Oct 2021 21:42:31 +0000 (21:42 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 10 Oct 2021 00:43:04 +0000 (00:43 +0000)
...as required by the SocketDescriptor.send_data API docs

src/main/java/org/ldk/batteries/NioPeerHandler.java

index b722d96d8c1408568659466d87433821bf29bd18..71d31938e7a7ef1d31ea8e5fe16e64a1c6c26538 100644 (file)
@@ -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.