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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 6e60713  64195: Revert simplification of NIO block read and write
6e60713 is described below

commit 6e60713c75141bc00f03f08f759df993a6416c71
Author: remm <r...@apache.org>
AuthorDate: Wed Mar 4 14:04:36 2020 +0100

    64195: Revert simplification of NIO block read and write
    
    Deferred to Tomcat 10.
---
 java/org/apache/tomcat/util/net/NioEndpoint.java | 105 +++++++----------------
 webapps/docs/changelog.xml                       |   4 +
 2 files changed, 34 insertions(+), 75 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java 
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 66f941c..1a9f9de 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -135,7 +135,7 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
     public boolean getUseInheritedChannel() { return useInheritedChannel; }
 
     /**
-     * Priority of the poller thread.
+     * Priority of the poller threads.
      */
     private int pollerThreadPriority = Thread.NORM_PRIORITY;
     public void setPollerThreadPriority(int pollerThreadPriority) { 
this.pollerThreadPriority = pollerThreadPriority; }
@@ -771,11 +771,6 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
                                     if 
(!socketWrapper.readOperation.process()) {
                                         closeSocket = true;
                                     }
-                                } else if (socketWrapper.readBlocking) {
-                                    synchronized (socketWrapper.readLock) {
-                                        socketWrapper.readBlocking = false;
-                                        socketWrapper.readLock.notify();
-                                    }
                                 } else if (!processSocket(socketWrapper, 
SocketEvent.OPEN_READ, true)) {
                                     closeSocket = true;
                                 }
@@ -785,11 +780,6 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
                                     if 
(!socketWrapper.writeOperation.process()) {
                                         closeSocket = true;
                                     }
-                                } else if (socketWrapper.writeBlocking) {
-                                    synchronized (socketWrapper.writeLock) {
-                                        socketWrapper.writeBlocking = false;
-                                        socketWrapper.writeLock.notify();
-                                    }
                                 } else if (!processSocket(socketWrapper, 
SocketEvent.OPEN_WRITE, true)) {
                                     closeSocket = true;
                                 }
@@ -1033,19 +1023,12 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
         private volatile long lastRead = System.currentTimeMillis();
         private volatile long lastWrite = lastRead;
 
-        private final Object readLock;
-        private volatile boolean readBlocking = false;
-        private final Object writeLock;
-        private volatile boolean writeBlocking = false;
-
         public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) {
             super(channel, endpoint);
             pool = endpoint.getSelectorPool();
             nioChannels = endpoint.getNioChannels();
             poller = endpoint.getPoller();
             socketBufferHandler = channel.getBufHandler();
-            readLock = (readPending == null) ? new Object() : readPending;
-            writeLock = (writePending == null) ? new Object() : writePending;
         }
 
         public Poller getPoller() { return poller; }
@@ -1228,37 +1211,24 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
             if (socket instanceof ClosedNioChannel) {
                 throw new ClosedChannelException();
             }
-            nRead = socket.read(to);
-            if (nRead == -1) {
-                throw new EOFException();
-            }
-            if (block && nRead == 0) {
-                long timeout = getReadTimeout();
+            if (block) {
+                Selector selector = null;
                 try {
-                    readBlocking = true;
-                    registerReadInterest();
-                    synchronized (readLock) {
-                        if (readBlocking) {
-                            try {
-                                if (timeout > 0) {
-                                    readLock.wait(timeout);
-                                } else {
-                                    readLock.wait();
-                                }
-                            } catch (InterruptedException e) {
-                                // Continue ...
-                            }
-                            if (readBlocking) {
-                                throw new SocketTimeoutException();
-                            }
-                        }
-                    }
-                    nRead = socket.read(to);
-                    if (nRead == -1) {
-                        throw new EOFException();
-                    }
+                    selector = pool.get();
+                } catch (IOException x) {
+                    // Ignore
+                }
+                try {
+                    nRead = pool.read(to, socket, selector, getReadTimeout());
                 } finally {
-                    readBlocking = false;
+                    if (selector != null) {
+                        pool.put(selector);
+                    }
+                }
+            } else {
+                nRead = socket.read(to);
+                if (nRead == -1) {
+                    throw new EOFException();
                 }
             }
             return nRead;
@@ -1272,37 +1242,22 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
                 throw new ClosedChannelException();
             }
             if (block) {
-                long timeout = getWriteTimeout();
+                long writeTimeout = getWriteTimeout();
+                Selector selector = null;
+                try {
+                    selector = pool.get();
+                } catch (IOException x) {
+                    // Ignore
+                }
                 try {
-                    int n = 0;
+                    pool.write(from, socket, selector, writeTimeout);
+                    // Make sure we are flushed
                     do {
-                        n = socket.write(from);
-                        if (n == -1) {
-                            throw new EOFException();
-                        }
-                        if (n == 0) {
-                            writeBlocking = true;
-                            registerWriteInterest();
-                            synchronized (writeLock) {
-                                if (writeBlocking) {
-                                    try {
-                                        if (timeout > 0) {
-                                            writeLock.wait(timeout);
-                                        } else {
-                                            writeLock.wait();
-                                        }
-                                    } catch (InterruptedException e) {
-                                        // Continue ...
-                                    }
-                                    if (writeBlocking) {
-                                        throw new SocketTimeoutException();
-                                    }
-                                }
-                            }
-                        }
-                    } while (from.hasRemaining());
+                    } while (!socket.flush(true, selector, writeTimeout));
                 } finally {
-                    writeBlocking = false;
+                    if (selector != null) {
+                        pool.put(selector);
+                    }
                 }
                 // If there is data left in the buffer the socket will be 
registered for
                 // write further up the stack. This is to ensure the socket is 
only
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 116d0fa..862d9fe 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -133,6 +133,10 @@
         <code>setEnableSessionCreation</code> for <code>OpenSSLEngine</code>.
         Pull request provided by Alexander Scheel. (markt)
       </fix>
+      <fix>
+        <bug>64195</bug>: Revert simplification of NIO block read and write,
+        deferred to Tomcat 10. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


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

Reply via email to