You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2019/03/27 10:16:10 UTC

[tomcat] branch master updated: Harmonize NIO2 isReadyForWrite with isReadyForRead code

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 950b940  Harmonize NIO2 isReadyForWrite with isReadyForRead code
950b940 is described below

commit 950b940c6abdc1b674278c59c6bd6672a23120ea
Author: remm <re...@apache.org>
AuthorDate: Wed Mar 27 11:15:59 2019 +0100

    Harmonize NIO2 isReadyForWrite with isReadyForRead code
    
    Following 8.5 #1717, it is better to redo it with sync as it seems to
    indicate a leftover write issue.
---
 java/org/apache/tomcat/util/net/Nio2Endpoint.java | 35 +++++++++++++++++++++--
 webapps/docs/changelog.xml                        |  3 ++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 0028edb..711f777 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -729,9 +729,7 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                 }
 
                 int nRead = fillReadBuffer(false);
-
                 boolean isReady = nRead > 0;
-
                 if (!isReady) {
                     readInterest = true;
                 }
@@ -741,6 +739,39 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
 
 
         @Override
+        public boolean isReadyForWrite() {
+            synchronized (writeCompletionHandler) {
+                if (writeNotify) {
+                    return true;
+                }
+
+                if (!writePending.tryAcquire()) {
+                    writeInterest = true;
+                    return false;
+                }
+
+                if (socketBufferHandler.isWriteBufferEmpty() && nonBlockingWriteBuffer.isEmpty()) {
+                    writePending.release();
+                    return true;
+                }
+
+                boolean dataLeft = false;
+                try {
+                    dataLeft = flushNonBlocking(true);
+                } catch (IOException e) {
+                    setError(e);
+                    return true;
+                }
+                boolean isReady = !dataLeft;
+                if (!isReady) {
+                    writeInterest = true;
+                }
+                return isReady;
+            }
+        }
+
+
+        @Override
         public int read(boolean block, byte[] b, int off, int len) throws IOException {
             checkError();
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ae2b56d..fd00294 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -101,6 +101,9 @@
         Restore original maxConnections default for NIO2 as the underlying
         close issues have been fixed. (remm)
       </fix>
+      <fix>
+        Harmonize NIO2 isReadyForWrite with isReadyForRead code. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org