Author: markt
Date: Thu Aug 16 07:34:13 2018
New Revision: 1838155

URL: http://svn.apache.org/viewvc?rev=1838155&view=rev
Log:
Rename and provide a better comment

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1838155&r1=1838154&r2=1838155&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Thu Aug 16 
07:34:13 2018
@@ -572,10 +572,10 @@ public class Nio2Endpoint extends Abstra
                     synchronized (writeCompletionHandler) {
                         if (nBytes.intValue() < 0) {
                             failed(new 
EOFException(sm.getString("iob.failedwrite")), attachment);
-                        } else if (!writeBuffer.isEmpty()) {
+                        } else if (!nonBlockingWriteBuffer.isEmpty()) {
                             nestedWriteCompletionCount.get().incrementAndGet();
                             // Continue writing data using a gathering write
-                            ByteBuffer[] array = 
writeBuffer.toArray(attachment);
+                            ByteBuffer[] array = 
nonBlockingWriteBuffer.toArray(attachment);
                             getSocket().write(array, 0, array.length,
                                     toNio2Timeout(getWriteTimeout()), 
TimeUnit.MILLISECONDS,
                                     array, gatheringWriteCompletionHandler);
@@ -621,10 +621,10 @@ public class Nio2Endpoint extends Abstra
                     synchronized (writeCompletionHandler) {
                         if (nBytes.longValue() < 0) {
                             failed(new 
EOFException(sm.getString("iob.failedwrite")), attachment);
-                        } else if (!writeBuffer.isEmpty() || 
arrayHasData(attachment)) {
+                        } else if (!nonBlockingWriteBuffer.isEmpty() || 
arrayHasData(attachment)) {
                             // Continue writing data using a gathering write
                             nestedWriteCompletionCount.get().incrementAndGet();
-                            ByteBuffer[] array = 
writeBuffer.toArray(attachment);
+                            ByteBuffer[] array = 
nonBlockingWriteBuffer.toArray(attachment);
                             getSocket().write(array, 0, array.length,
                                     toNio2Timeout(getWriteTimeout()), 
TimeUnit.MILLISECONDS,
                                     array, gatheringWriteCompletionHandler);
@@ -1164,11 +1164,11 @@ public class Nio2Endpoint extends Abstra
                     off = off + thisTime;
                     if (len > 0) {
                         // Remaining data must be buffered
-                        writeBuffer.add(buf, off, len);
+                        nonBlockingWriteBuffer.add(buf, off, len);
                     }
                     flushNonBlocking(true);
                 } else {
-                    writeBuffer.add(buf, off, len);
+                    nonBlockingWriteBuffer.add(buf, off, len);
                 }
             }
         }
@@ -1199,11 +1199,11 @@ public class Nio2Endpoint extends Abstra
                     transfer(from, socketBufferHandler.getWriteBuffer());
                     if (from.remaining() > 0) {
                         // Remaining data must be buffered
-                        writeBuffer.add(from);
+                        nonBlockingWriteBuffer.add(from);
                     }
                     flushNonBlocking(true);
                 } else {
-                    writeBuffer.add(from);
+                    nonBlockingWriteBuffer.add(from);
                 }
             }
         }
@@ -1274,8 +1274,8 @@ public class Nio2Endpoint extends Abstra
             synchronized (writeCompletionHandler) {
                 if (hasPermit || writePending.tryAcquire()) {
                     socketBufferHandler.configureWriteBufferForRead();
-                    if (!writeBuffer.isEmpty()) {
-                        ByteBuffer[] array = 
writeBuffer.toArray(socketBufferHandler.getWriteBuffer());
+                    if (!nonBlockingWriteBuffer.isEmpty()) {
+                        ByteBuffer[] array = 
nonBlockingWriteBuffer.toArray(socketBufferHandler.getWriteBuffer());
                         Nio2Endpoint.startInline();
                         getSocket().write(array, 0, array.length, 
toNio2Timeout(getWriteTimeout()),
                                 TimeUnit.MILLISECONDS, array, 
gatheringWriteCompletionHandler);
@@ -1303,7 +1303,7 @@ public class Nio2Endpoint extends Abstra
         public boolean hasDataToWrite() {
             synchronized (writeCompletionHandler) {
                 return !socketBufferHandler.isWriteBufferEmpty() ||
-                        !writeBuffer.isEmpty() || getError() != null;
+                        !nonBlockingWriteBuffer.isEmpty() || getError() != 
null;
             }
         }
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1838155&r1=1838154&r2=1838155&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Thu Aug 
16 07:34:13 2018
@@ -82,12 +82,16 @@ public abstract class SocketWrapperBase<
     protected int bufferedWriteSize = 64 * 1024; // 64k default write buffer
 
     /**
-     * For "non-blocking" writes use an external set of buffers. Although the
-     * API only allows one non-blocking write at a time, due to buffering and
-     * the possible need to write HTTP headers, there may be more than one 
write
-     * to the OutputBuffer.
+     * Additional buffer used for non-blocking writes. Non-blocking writes need
+     * to return immediately even if the data cannot be written immediately but
+     * the socket buffer may not be big enough to hold all of the unwritten
+     * data. This structure provides an additional buffer to hold the data 
until
+     * it can be written.
+     * Not that while the Servlet API only allows one non-blocking write at a
+     * time, due to buffering and the possible need to write HTTP headers, this
+     * layer may see multiple writes.
      */
-    protected final WriteBuffer writeBuffer = new 
WriteBuffer(bufferedWriteSize);
+    protected final WriteBuffer nonBlockingWriteBuffer = new 
WriteBuffer(bufferedWriteSize);
 
     public SocketWrapperBase(E socket, AbstractEndpoint<E,?> endpoint) {
         this.socket = socket;
@@ -249,7 +253,7 @@ public abstract class SocketWrapperBase<
     public SocketBufferHandler getSocketBufferHandler() { return 
socketBufferHandler; }
 
     public boolean hasDataToWrite() {
-        return !socketBufferHandler.isWriteBufferEmpty() || 
!writeBuffer.isEmpty();
+        return !socketBufferHandler.isWriteBufferEmpty() || 
!nonBlockingWriteBuffer.isEmpty();
     }
 
     /**
@@ -279,7 +283,7 @@ public abstract class SocketWrapperBase<
         if (socketBufferHandler == null) {
             throw new IllegalStateException(sm.getString("socket.closed"));
         }
-        return socketBufferHandler.isWriteBufferWritable() && 
writeBuffer.isEmpty();
+        return socketBufferHandler.isWriteBufferWritable() && 
nonBlockingWriteBuffer.isEmpty();
     }
 
 
@@ -502,7 +506,7 @@ public abstract class SocketWrapperBase<
      * @throws IOException If an IO error occurs during the write
      */
     protected void writeNonBlocking(byte[] buf, int off, int len) throws 
IOException {
-        if (writeBuffer.isEmpty() && 
socketBufferHandler.isWriteBufferWritable()) {
+        if (nonBlockingWriteBuffer.isEmpty() && 
socketBufferHandler.isWriteBufferWritable()) {
             socketBufferHandler.configureWriteBufferForWrite();
             int thisTime = transfer(buf, off, len, 
socketBufferHandler.getWriteBuffer());
             len = len - thisTime;
@@ -524,7 +528,7 @@ public abstract class SocketWrapperBase<
 
         if (len > 0) {
             // Remaining data must be buffered
-            writeBuffer.add(buf, off, len);
+            nonBlockingWriteBuffer.add(buf, off, len);
         }
     }
 
@@ -541,13 +545,13 @@ public abstract class SocketWrapperBase<
      * @throws IOException If an IO error occurs during the write
      */
     protected void writeNonBlocking(ByteBuffer from) throws IOException {
-        if (writeBuffer.isEmpty() && 
socketBufferHandler.isWriteBufferWritable()) {
+        if (nonBlockingWriteBuffer.isEmpty() && 
socketBufferHandler.isWriteBufferWritable()) {
             writeNonBlockingInternal(from);
         }
 
         if (from.remaining() > 0) {
             // Remaining data must be buffered
-            writeBuffer.add(from);
+            nonBlockingWriteBuffer.add(from);
         }
     }
 
@@ -624,8 +628,8 @@ public abstract class SocketWrapperBase<
     protected void flushBlocking() throws IOException {
         doWrite(true);
 
-        if (!writeBuffer.isEmpty()) {
-            writeBuffer.write(this, true);
+        if (!nonBlockingWriteBuffer.isEmpty()) {
+            nonBlockingWriteBuffer.write(this, true);
 
             if (!socketBufferHandler.isWriteBufferEmpty()) {
                 doWrite(true);
@@ -644,8 +648,8 @@ public abstract class SocketWrapperBase<
             dataLeft = !socketBufferHandler.isWriteBufferEmpty();
         }
 
-        if (!dataLeft && !writeBuffer.isEmpty()) {
-            dataLeft = writeBuffer.write(this, false);
+        if (!dataLeft && !nonBlockingWriteBuffer.isEmpty()) {
+            dataLeft = nonBlockingWriteBuffer.write(this, false);
 
             if (!dataLeft && !socketBufferHandler.isWriteBufferEmpty()) {
                 doWrite(false);



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

Reply via email to