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 2894522  Fix async writes
2894522 is described below

commit 2894522060492b8d7f983aab5df4462b9f34d13c
Author: remm <r...@apache.org>
AuthorDate: Fri May 17 20:57:42 2019 +0200

    Fix async writes
---
 java/org/apache/tomcat/util/net/AprEndpoint.java | 31 ++++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index c577257..d61febc 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -2763,6 +2763,7 @@ public class AprEndpoint extends 
AbstractEndpoint<Long,Long> implements SNICallB
 
         private class AprOperationState<A> extends OperationState<A> {
             private volatile boolean inline = true;
+            private volatile long flushBytes = 0;
             private AprOperationState(boolean read, ByteBuffer[] buffers, int 
offset, int length,
                     BlockingMode block, long timeout, TimeUnit unit, A 
attachment, CompletionCheck check,
                     CompletionHandler<Long, ? super A> handler, Semaphore 
semaphore,
@@ -2800,21 +2801,35 @@ public class AprEndpoint extends 
AbstractEndpoint<Long,Long> implements SNICallB
                                     break;
                                 }
                             }
-                            if (buffer == null) {
+                            if (buffer == null && flushBytes == 0) {
                                 // Nothing to do
                                 return;
                             }
                             if (read) {
                                 nBytes = read(false, buffer);
                             } else {
-                                if (!flush(false)) {
-                                    int remaining = buffer.remaining();
-                                    writeNonBlockingDirect(buffer);
-                                    nBytes = remaining - buffer.remaining();
-                                    if (nBytes > 0 && !buffer.isDirect() && 
flush(block == BlockingMode.BLOCK)) {
-                                        inline = false;
-                                        registerWriteInterest();
+                                if (!flush(block == BlockingMode.BLOCK)) {
+                                    if (flushBytes > 0) {
+                                        // Flushing was done, continue 
processing
+                                        nBytes = flushBytes;
+                                        flushBytes = 0;
+                                    } else {
+                                        int remaining = buffer.remaining();
+                                        write(block == BlockingMode.BLOCK, 
buffer);
+                                        nBytes = remaining - 
buffer.remaining();
+                                        if (nBytes > 0 && flush(block == 
BlockingMode.BLOCK)) {
+                                            // We have to flush and it's 
incomplete, save the bytes written until done
+                                            inline = false;
+                                            registerWriteInterest();
+                                            flushBytes = nBytes;
+                                            return;
+                                        }
                                     }
+                                } else {
+                                    // Continue flushing
+                                    inline = false;
+                                    registerWriteInterest();
+                                    return;
                                 }
                             }
                             if (nBytes != 0) {


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

Reply via email to