Author: violetagg
Date: Fri Aug 26 10:23:15 2016
New Revision: 1757813

URL: http://svn.apache.org/viewvc?rev=1757813&view=rev
Log:
Introduce a new method SocketWrapperBase.doWrite(boolean, ByteBuffer)

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

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1757813&r1=1757812&r2=1757813&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Fri Aug 26 
10:23:15 2016
@@ -2441,7 +2441,7 @@ public class AprEndpoint extends Abstrac
 
 
         @Override
-        protected void doWrite(boolean block) throws IOException {
+        protected void doWrite(boolean block, ByteBuffer from) throws 
IOException {
             if (closed) {
                 throw new IOException(sm.getString("socket.apr.closed", 
getSocket()));
             }
@@ -2455,7 +2455,7 @@ public class AprEndpoint extends Abstrac
                     if (block) {
                         Socket.timeoutSet(getSocket().longValue(), 
getWriteTimeout() * 1000);
                     }
-                    doWriteInternal();
+                    doWriteInternal(from);
                     return;
                 }
             } finally {
@@ -2476,7 +2476,7 @@ public class AprEndpoint extends Abstrac
                 readLock.lock();
                 try {
                     writeLock.unlock();
-                    doWriteInternal();
+                    doWriteInternal(from);
                 } finally {
                     readLock.unlock();
                 }
@@ -2490,18 +2490,16 @@ public class AprEndpoint extends Abstrac
         }
 
 
-        private void doWriteInternal() throws IOException {
+        private void doWriteInternal(ByteBuffer from) throws IOException {
             int thisTime;
 
-            ByteBuffer socketWriteBuffer = 
socketBufferHandler.getWriteBuffer();
             do {
                 thisTime = 0;
                 if (getEndpoint().isSSLEnabled()) {
                     if (sslOutputBuffer.remaining() == 0) {
                         // Buffer was fully written last time around
                         sslOutputBuffer.clear();
-                        socketBufferHandler.configureWriteBufferForRead();
-                        transfer(socketWriteBuffer, sslOutputBuffer);
+                        transfer(from, sslOutputBuffer);
                         sslOutputBuffer.flip();
                     } else {
                         // Buffer still has data from previous attempt to write
@@ -2514,11 +2512,10 @@ public class AprEndpoint extends Abstrac
                         sslOutputBuffer.position(sslOutputBuffer.position() + 
thisTime);
                     }
                 } else {
-                    socketBufferHandler.configureWriteBufferForRead();
-                    thisTime = Socket.sendb(getSocket().longValue(), 
socketWriteBuffer,
-                            socketWriteBuffer.position(), 
socketWriteBuffer.remaining());
+                    thisTime = Socket.sendb(getSocket().longValue(), from, 
from.position(),
+                            from.remaining());
                     if (thisTime > 0) {
-                        
socketWriteBuffer.position(socketWriteBuffer.position() + thisTime);
+                        from.position(from.position() + thisTime);
                     }
                 }
                 if (Status.APR_STATUS_IS_EAGAIN(-thisTime)) {
@@ -2533,7 +2530,7 @@ public class AprEndpoint extends Abstrac
                     throw new 
IOException(sm.getString("socket.apr.write.error",
                             Integer.valueOf(-thisTime), getSocket(), this));
                 }
-            } while ((thisTime > 0 || getBlockingStatus()) && 
socketWriteBuffer.hasRemaining());
+            } while ((thisTime > 0 || getBlockingStatus()) && 
from.hasRemaining());
 
             // 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

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=1757813&r1=1757812&r2=1757813&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Fri Aug 26 
10:23:15 2016
@@ -1158,16 +1158,15 @@ public class Nio2Endpoint extends Abstra
          *              blocking case
          */
         @Override
-        protected void doWrite(boolean block) throws IOException {
+        protected void doWrite(boolean block, ByteBuffer from) throws 
IOException {
             Future<Integer> integer = null;
             try {
-                socketBufferHandler.configureWriteBufferForRead();
                 do {
-                    integer = 
getSocket().write(socketBufferHandler.getWriteBuffer());
+                    integer = getSocket().write(from);
                     if (integer.get(getNio2WriteTimeout(), 
TimeUnit.MILLISECONDS).intValue() < 0) {
                         throw new 
EOFException(sm.getString("iob.failedwrite"));
                     }
-                } while (socketBufferHandler.getWriteBuffer().hasRemaining());
+                } while (from.hasRemaining());
             } catch (ExecutionException e) {
                 if (e.getCause() instanceof IOException) {
                     throw (IOException) e.getCause();

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1757813&r1=1757812&r2=1757813&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Aug 26 
10:23:15 2016
@@ -25,6 +25,7 @@ import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
+import java.nio.ByteBuffer;
 import java.nio.channels.CancelledKeyException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.SelectionKey;
@@ -1207,9 +1208,7 @@ public class NioEndpoint extends Abstrac
 
 
         @Override
-        protected void doWrite(boolean block) throws IOException {
-            socketBufferHandler.configureWriteBufferForRead();
-
+        protected void doWrite(boolean block, ByteBuffer from) throws 
IOException {
             long writeTimeout = getWriteTimeout();
             Selector selector = null;
             try {
@@ -1218,12 +1217,13 @@ public class NioEndpoint extends Abstrac
                 // Ignore
             }
             try {
-                pool.write(socketBufferHandler.getWriteBuffer(), getSocket(),
-                        selector, writeTimeout, block);
+                pool.write(from, getSocket(), selector, writeTimeout, block);
                 if (block) {
                     // Make sure we are flushed
                     do {
-                        if (getSocket().flush(true, selector, writeTimeout)) 
break;
+                        if (getSocket().flush(true, selector, writeTimeout)) {
+                            break;
+                        }
                     } while (true);
                 }
                 updateLastWrite();

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=1757813&r1=1757812&r2=1757813&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Fri Aug 
26 10:23:15 2016
@@ -510,7 +510,24 @@ public abstract class SocketWrapperBase<
      * @throws IOException If an I/O error such as a timeout occurs during the
      *                     write
      */
-    protected abstract void doWrite(boolean block) throws IOException;
+    protected void doWrite(boolean block) throws IOException {
+        socketBufferHandler.configureWriteBufferForRead();
+        doWrite(block, socketBufferHandler.getWriteBuffer());
+    }
+
+
+    /**
+     * Write the contents of the ByteBuffer to the socket. For blocking writes
+     * either then entire contents of the buffer will be written or an
+     * IOException will be thrown. Partial blocking writes will not occur.
+     *
+     * @param block Should the write be blocking or not?
+     * @param from the ByteBuffer containing the data to be written
+     *
+     * @throws IOException If an I/O error such as a timeout occurs during the
+     *                     write
+     */
+    protected abstract void doWrite(boolean block, ByteBuffer from) throws 
IOException;
 
 
     protected void addToBuffers(byte[] buf, int offset, int length) {



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

Reply via email to