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/01 10:29:04 UTC

[tomcat] branch master updated: Revert again for now

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 23d554f  Revert again for now
23d554f is described below

commit 23d554fa045ee5d980b2919b34bf77c0da4d4f15
Author: remm <re...@apache.org>
AuthorDate: Fri Mar 1 11:28:52 2019 +0100

    Revert again for now
---
 java/org/apache/tomcat/util/net/Nio2Endpoint.java | 77 +++++++++--------------
 1 file changed, 30 insertions(+), 47 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 982dd44..b1dbb7c 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -476,7 +476,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
         private final CompletionHandler<Integer, ByteBuffer> readCompletionHandler;
         private final Semaphore readPending = new Semaphore(1);
         private boolean readInterest = false; // Guarded by readCompletionHandler
-        private boolean readNotify = false;
 
         private final CompletionHandler<Integer, ByteBuffer> writeCompletionHandler;
         private final CompletionHandler<Long, ByteBuffer[]> gatheringWriteCompletionHandler;
@@ -494,7 +493,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                     failed(new ClosedChannelException(), attachment);
                     return;
                 }
-                readNotify = true;
                 getEndpoint().processSocket(attachment, SocketEvent.OPEN_READ, Nio2Endpoint.isInline());
             }
 
@@ -592,10 +590,10 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
             this.readCompletionHandler = new CompletionHandler<Integer, ByteBuffer>() {
                 @Override
                 public void completed(Integer nBytes, ByteBuffer attachment) {
+                    boolean readNotify = false;
                     if (log.isDebugEnabled()) {
                         log.debug("Socket: [" + Nio2SocketWrapper.this + "], Interest: [" + readInterest + "]");
                     }
-                    readNotify = false;
                     synchronized (readCompletionHandler) {
                         if (nBytes.intValue() < 0) {
                             failed(new EOFException(), attachment);
@@ -744,10 +742,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
         @Override
         public boolean isReadyForRead() throws IOException {
             synchronized (readCompletionHandler) {
-                if (readNotify) {
-                    return true;
-                }
-
                 if (!readPending.tryAcquire()) {
                     readInterest = true;
                     return false;
@@ -782,29 +776,23 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                 throw new IOException(sm.getString("socket.closed"));
             }
 
-            if (!readNotify) {
-                if (block) {
-                    try {
-                        readPending.acquire();
-                    } catch (InterruptedException e) {
-                        throw new IOException(e);
-                    }
-                } else {
-                    if (!readPending.tryAcquire()) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("Socket: [" + this + "], Read in progress. Returning [0]");
-                        }
-                        return 0;
+            if (block) {
+                try {
+                    readPending.acquire();
+                } catch (InterruptedException e) {
+                    throw new IOException(e);
+                }
+            } else {
+                if (!readPending.tryAcquire()) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Socket: [" + this + "], Read in progress. Returning [0]");
                     }
+                    return 0;
                 }
             }
 
             int nRead = populateReadBuffer(b, off, len);
             if (nRead > 0) {
-                if (readNotify) {
-                    // The code that was notified is now reading its data
-                    readNotify = false;
-                }
                 // This may be sufficient to complete the request and we
                 // don't want to trigger another read since if there is no
                 // more data to read and this request takes a while to
@@ -822,7 +810,7 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                     socketBufferHandler.configureReadBufferForRead();
                     nRead = Math.min(nRead, len);
                     socketBufferHandler.getReadBuffer().get(b, off, nRead);
-                } else if (nRead == 0 && !block) {
+                } else if (nRead == 0 && !block && ContainerThreadMarker.isContainerThread()) {
                     readInterest = true;
                 }
                 if (log.isDebugEnabled()) {
@@ -841,29 +829,23 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                 throw new IOException(sm.getString("socket.closed"));
             }
 
-            if (!readNotify) {
-                if (block) {
-                    try {
-                        readPending.acquire();
-                    } catch (InterruptedException e) {
-                        throw new IOException(e);
-                    }
-                } else {
-                    if (!readPending.tryAcquire()) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("Socket: [" + this + "], Read in progress. Returning [0]");
-                        }
-                        return 0;
+            if (block) {
+                try {
+                    readPending.acquire();
+                } catch (InterruptedException e) {
+                    throw new IOException(e);
+                }
+            } else {
+                if (!readPending.tryAcquire()) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Socket: [" + this + "], Read in progress. Returning [0]");
                     }
+                    return 0;
                 }
             }
 
             int nRead = populateReadBuffer(to);
             if (nRead > 0) {
-                if (readNotify) {
-                    // The code that was notified is now reading its data
-                    readNotify = false;
-                }
                 // This may be sufficient to complete the request and we
                 // don't want to trigger another read since if there is no
                 // more data to read and this request takes a while to
@@ -891,7 +873,7 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
                     // data that was just read
                     if (nRead > 0) {
                         nRead = populateReadBuffer(to);
-                    } else if (nRead == 0 && !block) {
+                    } else if (nRead == 0 && !block && ContainerThreadMarker.isContainerThread()) {
                         readInterest = true;
                     }
                 }
@@ -1494,10 +1476,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
         @Override
         public void registerReadInterest() {
             synchronized (readCompletionHandler) {
-                // A notification is already being sent
-                if (readNotify) {
-                    return;
-                }
                 if (readPending.availablePermits() == 0) {
                     readInterest = true;
                 } else {
@@ -1742,6 +1720,11 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
 
         @Override
         protected void doRun() {
+            if (SocketEvent.OPEN_WRITE != event) {
+                // Anything other than OPEN_WRITE is a genuine read or an
+                // error condition so for all of those release the semaphore
+                ((Nio2SocketWrapper) socketWrapper).releaseReadPending();
+            }
             boolean launch = false;
             try {
                 int handshake = -1;


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