Author: markt
Date: Sun May 15 21:58:10 2011
New Revision: 1103554

URL: http://svn.apache.org/viewvc?rev=1103554&view=rev
Log:
Improve handling for reading request bodies. More testing still required.

Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1103554&r1=1103553&r2=1103554&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Sun May 15 
21:58:10 2011
@@ -109,21 +109,19 @@ public class AjpNioProcessor extends Abs
     protected NioChannel socket;
 
     
+    /**
+     * Selector pool for the associated endpoint.
+     */
     protected NioSelectorPool pool;
 
 
     /**
-     * Input buffer.
-     */
-    protected ByteBuffer readBuffer;
-    protected int readBufferEnd = 0;
-    
-    /**
-     * Output buffer.
+     * NIO socket read may return more than just the current message. Need to
+     * buffer the response to ensure data isn't lost.
      */
-    protected ByteBuffer writeBuffer;
+    protected byte[] inputBuffer;
+    protected int inputBufferEnd;
 
-    
     /**
      * Direct buffer used for sending right away a get body message.
      */
@@ -204,8 +202,6 @@ public class AjpNioProcessor extends Abs
 
         // Setting up the socket
         this.socket = socket;
-        readBuffer = socket.getBufHandler().getReadBuffer();
-        writeBuffer = socket.getBufHandler().getWriteBuffer();
         
         int soTimeout = -1;
         final KeyAttachment ka = (KeyAttachment)socket.getAttachment(false);
@@ -348,23 +344,12 @@ public class AjpNioProcessor extends Abs
                 return SocketState.OPEN;
             }
         } else {
-            readBuffer = null;
-            writeBuffer = null;
             return SocketState.CLOSED;
         }
         
     }
 
     
-    @Override
-    public void recycle() {
-        if (readBuffer != null) {
-            readBuffer.clear();
-        }
-        readBufferEnd = 0;
-        super.recycle();
-    }
-
     public SocketState asyncDispatch(SocketStatus status) {
 
         RequestInfo rp = request.getRequestProcessor();
@@ -388,8 +373,6 @@ public class AjpNioProcessor extends Abs
             if (error) {
                 response.setStatus(500);
                 request.updateCounters();
-                readBuffer = null;
-                writeBuffer = null;
                 return SocketState.CLOSED;
             } else {
                 return SocketState.LONG;
@@ -399,8 +382,6 @@ public class AjpNioProcessor extends Abs
                 response.setStatus(500);
             }
             request.updateCounters();
-            readBuffer = null;
-            writeBuffer = null;
             return SocketState.CLOSED;
         }
 
@@ -503,29 +484,29 @@ public class AjpNioProcessor extends Abs
 
 
     /**
-     * Read at least the specified amount of bytes, and place them
-     * in the input buffer.
+     * Read the specified amount of bytes, and place them in the input buffer.
      */
     protected int read(byte[] buf, int pos, int n, boolean block)
         throws IOException {
 
-        int read = readBufferEnd - pos;
+        int read = 0;
         int res = 0;
         while (read < n) {
-            res = readSocket(buf, read + pos, block);
+            res = readSocket(buf, read + pos, n, block);
             if (res > 0) {
                 read += res;
             } else {
                 throw new IOException(sm.getString("ajpprotocol.failedread"));
             }
         }
-        readBufferEnd += read;
         return read;
     }
 
-    private int readSocket(byte[] buf, int pos, boolean block) throws 
IOException {
+    private int readSocket(byte[] buf, int pos, int n, boolean block)
+            throws IOException {
         int nRead = 0;
         socket.getBufHandler().getReadBuffer().clear();
+        socket.getBufHandler().getReadBuffer().limit(n);
         if ( block ) {
             Selector selector = null;
             try {



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

Reply via email to