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/12/02 20:25:55 UTC

[tomcat] branch 8.5.x updated: Harmonize again writes, thanks to Mark for the review.

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

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


The following commit(s) were added to refs/heads/8.5.x by this push:
     new bb8649c  Harmonize again writes, thanks to Mark for the review.
bb8649c is described below

commit bb8649c67f1f3caefd294116f37b50d5fd529206
Author: remm <re...@apache.org>
AuthorDate: Mon Dec 2 20:25:21 2019 +0100

    Harmonize again writes, thanks to Mark for the review.
---
 .../apache/tomcat/util/net/SocketWrapperBase.java  | 36 +++++++++++++---------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
index 30d2d47..0d348a6 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -475,14 +475,17 @@ public abstract class SocketWrapperBase<E> {
      * @throws IOException If an IO error occurs during the write
      */
     protected void writeBlocking(byte[] buf, int off, int len) throws IOException {
-        socketBufferHandler.configureWriteBufferForWrite();
-        int thisTime = transfer(buf, off, len, socketBufferHandler.getWriteBuffer());
-        while (!socketBufferHandler.getWriteBuffer().hasRemaining()) {
-            len = len - thisTime;
-            off = off + thisTime;
-            doWrite(true);
+        if (len > 0) {
             socketBufferHandler.configureWriteBufferForWrite();
-            thisTime = transfer(buf, off, len, socketBufferHandler.getWriteBuffer());
+            int thisTime = transfer(buf, off, len, socketBufferHandler.getWriteBuffer());
+            len -= thisTime;
+            while (len > 0) {
+                off += thisTime;
+                doWrite(true);
+                socketBufferHandler.configureWriteBufferForWrite();
+                thisTime = transfer(buf, off, len, socketBufferHandler.getWriteBuffer());
+                len -= thisTime;
+            }
         }
     }
 
@@ -501,12 +504,14 @@ public abstract class SocketWrapperBase<E> {
      * @throws IOException If an IO error occurs during the write
      */
     protected void writeBlocking(ByteBuffer from) throws IOException {
-        socketBufferHandler.configureWriteBufferForWrite();
-        transfer(from, socketBufferHandler.getWriteBuffer());
-        while (from.hasRemaining()) {
-            doWrite(true);
+        if (from.hasRemaining()) {
             socketBufferHandler.configureWriteBufferForWrite();
             transfer(from, socketBufferHandler.getWriteBuffer());
+            while (from.hasRemaining()) {
+                doWrite(true);
+                socketBufferHandler.configureWriteBufferForWrite();
+                transfer(from, socketBufferHandler.getWriteBuffer());
+            }
         }
     }
 
@@ -529,11 +534,12 @@ public abstract class SocketWrapperBase<E> {
      * @throws IOException If an IO error occurs during the write
      */
     protected void writeNonBlocking(byte[] buf, int off, int len) throws IOException {
-        if (nonBlockingWriteBuffer.isEmpty() && socketBufferHandler.isWriteBufferWritable()) {
+        if (len > 0 && nonBlockingWriteBuffer.isEmpty()
+                && socketBufferHandler.isWriteBufferWritable()) {
             socketBufferHandler.configureWriteBufferForWrite();
             int thisTime = transfer(buf, off, len, socketBufferHandler.getWriteBuffer());
-            len = len - thisTime;
-            while (!socketBufferHandler.isWriteBufferWritable()) {
+            len -= thisTime;
+            while (len > 0) {
                 off = off + thisTime;
                 doWrite(false);
                 if (len > 0 && socketBufferHandler.isWriteBufferWritable()) {
@@ -545,7 +551,7 @@ public abstract class SocketWrapperBase<E> {
                     // else to do here. Exit the loop.
                     break;
                 }
-                len = len - thisTime;
+                len -= thisTime;
             }
         }
 


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