From fcf5a7aa5efa0e117cdd8927f97594871e26cda7 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 20 Aug 2018 19:53:18 +0000 Subject: [PATCH] Fix refactoring of writing from the non-blocking write buffer to the network for NIO2. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1838473 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/Nio2Endpoint.java | 13 +++++++++++++ .../apache/tomcat/util/net/SocketWrapperBase.java | 5 ++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java index 171ffea8d81b..1364c455ac29 100644 --- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java +++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java @@ -1183,6 +1183,19 @@ protected void writeNonBlocking(byte[] buf, int off, int len) throws IOException */ @Override protected void writeNonBlocking(ByteBuffer from) throws IOException { + writeNonBlockingInternal(from); + } + + + /** + * {@inheritDoc} + *

+ * Overridden for NIO2 to enable a gathering write to be used to write + * all of the remaining data in a single additional write should a + * non-blocking write leave data in the buffer. + */ + @Override + protected void writeNonBlockingInternal(ByteBuffer from) throws IOException { // Note: Possible alternate behavior: // If there's non blocking abuse (like a test writing 1MB in a single // "non blocking" write), then block until the previous write is diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java b/java/org/apache/tomcat/util/net/SocketWrapperBase.java index dcb75443f802..21889c8d839d 100644 --- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java +++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java @@ -621,12 +621,11 @@ protected void writeNonBlocking(ByteBuffer from) } - /* + /** * Separate method so it can be re-used by the socket write buffer to write * data to the network */ - void writeNonBlockingInternal(ByteBuffer from) throws IOException { - // TODO Explore refactoring this method back into writeNonBlocking + protected void writeNonBlockingInternal(ByteBuffer from) throws IOException { if (socketBufferHandler.isWriteBufferEmpty()) { writeNonBlockingDirect(from); } else {