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/04/19 14:35:05 UTC

[tomcat] branch master updated: Simplify non blocking write

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 4377d2d  Simplify non blocking write
4377d2d is described below

commit 4377d2db4078f4ae7a3ac33b4a4d058fe2965863
Author: remm <re...@apache.org>
AuthorDate: Fri Apr 19 16:34:53 2019 +0200

    Simplify non blocking write
    
    Non blocking read uses a straight read, and I couldn't see why write
    wouldn't be able to do the same thing, the called code is 100%
    equivalent once block is false: it doesn't do anything except call the
    channel write.
    Note: if it works fine, it should be possible to remove the block flag
    in NioSelectorPool as it is now unused (it is always true when it is
    called).
---
 java/org/apache/tomcat/util/net/NioEndpoint.java | 54 +++++++++++++-----------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 5ba1c1a..bfa53bb 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -1310,33 +1310,39 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
 
         @Override
         protected void doWrite(boolean block, ByteBuffer from) throws IOException {
-            long writeTimeout = getWriteTimeout();
-            Selector selector = null;
-            try {
-                selector = pool.get();
-            } catch (IOException x) {
-                // Ignore
-            }
-            try {
-                pool.write(from, getSocket(), selector, writeTimeout, block);
-                if (block) {
-                    // Make sure we are flushed
-                    do {
-                        if (getSocket().flush(true, selector, writeTimeout)) {
-                            break;
-                        }
-                    } while (true);
+            if (block) {
+                long writeTimeout = getWriteTimeout();
+                Selector selector = null;
+                try {
+                    selector = pool.get();
+                } catch (IOException x) {
+                    // Ignore
                 }
-                updateLastWrite();
-            } finally {
-                if (selector != null) {
-                    pool.put(selector);
+                try {
+                    pool.write(from, getSocket(), selector, writeTimeout, block);
+                    if (block) {
+                        // Make sure we are flushed
+                        do {
+                            if (getSocket().flush(true, selector, writeTimeout)) {
+                                break;
+                            }
+                        } while (true);
+                    }
+                } finally {
+                    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
+                // registered for write once as both container and user code can trigger
+                // write registration.
+            } else {
+                if (getSocket().write(from) == -1) {
+                    throw new EOFException();
                 }
             }
-            // 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
-            // registered for write once as both container and user code can trigger
-            // write registration.
+            updateLastWrite();
         }
 
 


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