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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

remm
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 c92fab2  Harmonize again writes, thanks to Mark for the review.
c92fab2 is described below

commit c92fab26992ec12dc6815e1f7869e41e98076204
Author: remm <[hidden email]>
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 22bcf87..deddf81 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -525,14 +525,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;
+            }
         }
     }
 
@@ -551,12 +554,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());
+            }
         }
     }
 
@@ -579,11 +584,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()) {
@@ -595,7 +601,7 @@ public abstract class SocketWrapperBase<E> {
                     // else to do here. Exit the loop.
                     break;
                 }
-                len = len - thisTime;
+                len -= thisTime;
             }
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Mark Thomas-2
On 02/12/2019 19:25, [hidden email] wrote:
> 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 c92fab2  Harmonize again writes, thanks to Mark for the review.


> c92fab2 is described below
>
> commit c92fab26992ec12dc6815e1f7869e41e98076204
> Author: remm <[hidden email]>
> AuthorDate: Mon Dec 2 20:25:21 2019 +0100
>
>     Harmonize again writes, thanks to Mark for the review.

Thanks for taking care of this. They look the same to me now.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]