Author: fhanik
Date: Thu Oct  8 22:37:52 2009
New Revision: 823351

URL: http://svn.apache.org/viewvc?rev=823351&view=rev
Log:
consolidate two input buffers into one, no functional change, just abstract out 
exact same code used in two connectors

Added:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java
Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
    tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java

Added: tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java?rev=823351&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java (added)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java Thu Oct 
 8 22:37:52 2009
@@ -0,0 +1,327 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.coyote.http11;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.coyote.InputBuffer;
+import org.apache.coyote.Request;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.http.MimeHeaders;
+import org.apache.tomcat.util.res.StringManager;
+
+public abstract class AbstractInputBuffer implements InputBuffer{
+
+    public abstract boolean parseRequestLine(boolean useAvailableDataOnly) 
throws IOException;
+    
+    public abstract boolean parseHeaders() throws IOException;
+    
+    protected abstract boolean fill(boolean block) throws IOException; 
+
+    // -------------------------------------------------------------- Constants
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    
+
+    // -------------------------------------------------------------- Variables
+
+
+    /**
+     * The string manager for this package.
+     */
+    protected static StringManager sm =
+        StringManager.getManager(Constants.Package);
+
+
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * Associated Coyote request.
+     */
+    protected Request request;
+
+
+    /**
+     * Headers of the associated request.
+     */
+    protected MimeHeaders headers;
+
+
+    /**
+     * State.
+     */
+    protected boolean parsingHeader;
+
+
+    /**
+     * Swallow input ? (in the case of an expectation)
+     */
+    protected boolean swallowInput;
+
+
+    /**
+     * Pointer to the current read buffer.
+     */
+    protected byte[] buf;
+
+
+    /**
+     * Last valid byte.
+     */
+    protected int lastValid;
+
+
+    /**
+     * Position in the buffer.
+     */
+    protected int pos;
+
+
+    /**
+     * Pos of the end of the header in the buffer, which is also the
+     * start of the body.
+     */
+    protected int end;
+
+
+    /**
+     * Underlying input stream.
+     */
+    protected InputStream inputStream;
+
+
+    /**
+     * Underlying input buffer.
+     */
+    protected InputBuffer inputStreamInputBuffer;
+
+
+    /**
+     * Filter library.
+     * Note: Filter[0] is always the "chunked" filter.
+     */
+    protected InputFilter[] filterLibrary;
+
+
+    /**
+     * Active filters (in order).
+     */
+    protected InputFilter[] activeFilters;
+
+
+    /**
+     * Index of the last active filter.
+     */
+    protected int lastActiveFilter;
+
+
+    // ------------------------------------------------------------- Properties
+
+
+    /**
+     * Set the underlying socket input stream.
+     */
+    public void setInputStream(InputStream inputStream) {
+
+        // FIXME: Check for null ?
+
+        this.inputStream = inputStream;
+
+    }
+
+
+    /**
+     * Get the underlying socket input stream.
+     */
+    public InputStream getInputStream() {
+
+        return inputStream;
+
+    }
+
+
+    /**
+     * Add an input filter to the filter library.
+     */
+    public void addFilter(InputFilter filter) {
+
+        // FIXME: Check for null ?
+
+        InputFilter[] newFilterLibrary = 
+            new InputFilter[filterLibrary.length + 1];
+        for (int i = 0; i < filterLibrary.length; i++) {
+            newFilterLibrary[i] = filterLibrary[i];
+        }
+        newFilterLibrary[filterLibrary.length] = filter;
+        filterLibrary = newFilterLibrary;
+
+        activeFilters = new InputFilter[filterLibrary.length];
+
+    }
+
+
+    /**
+     * Get filters.
+     */
+    public InputFilter[] getFilters() {
+
+        return filterLibrary;
+
+    }
+
+
+    /**
+     * Clear filters.
+     */
+    public void clearFilters() {
+
+        filterLibrary = new InputFilter[0];
+        lastActiveFilter = -1;
+
+    }
+
+
+    /**
+     * Add an input filter to the filter library.
+     */
+    public void addActiveFilter(InputFilter filter) {
+
+        if (lastActiveFilter == -1) {
+            filter.setBuffer(inputStreamInputBuffer);
+        } else {
+            for (int i = 0; i <= lastActiveFilter; i++) {
+                if (activeFilters[i] == filter)
+                    return;
+            }
+            filter.setBuffer(activeFilters[lastActiveFilter]);
+        }
+
+        activeFilters[++lastActiveFilter] = filter;
+
+        filter.setRequest(request);
+
+    }
+
+
+    /**
+     * Set the swallow input flag.
+     */
+    public void setSwallowInput(boolean swallowInput) {
+        this.swallowInput = swallowInput;
+    }
+
+    
+
+
+    // --------------------------------------------------------- Public Methods
+
+
+    /**
+     * Recycle the input buffer. This should be called when closing the 
+     * connection.
+     */
+    public void recycle() {
+
+        // Recycle Request object
+        request.recycle();
+
+        inputStream = null;
+        lastValid = 0;
+        pos = 0;
+        lastActiveFilter = -1;
+        parsingHeader = true;
+        swallowInput = true;
+
+    }
+
+
+    /**
+     * End processing of current HTTP request.
+     * Note: All bytes of the current request should have been already 
+     * consumed. This method only resets all the pointers so that we are ready
+     * to parse the next HTTP request.
+     */
+    public void nextRequest() {
+
+        // Recycle Request object
+        request.recycle();
+
+        // Copy leftover bytes to the beginning of the buffer
+        if (lastValid - pos > 0) {
+            int npos = 0;
+            int opos = pos;
+            while (lastValid - opos > opos - npos) {
+                System.arraycopy(buf, opos, buf, npos, opos - npos);
+                npos += pos;
+                opos += pos;
+            }
+            System.arraycopy(buf, opos, buf, npos, lastValid - opos);
+        }
+
+        // Recycle filters
+        for (int i = 0; i <= lastActiveFilter; i++) {
+            activeFilters[i].recycle();
+        }
+
+        // Reset pointers
+        lastValid = lastValid - pos;
+        pos = 0;
+        lastActiveFilter = -1;
+        parsingHeader = true;
+        swallowInput = true;
+
+    }
+
+
+    /**
+     * End request (consumes leftover bytes).
+     * 
+     * @throws IOException an undelying I/O error occured
+     */
+    public void endRequest()
+        throws IOException {
+
+        if (swallowInput && (lastActiveFilter != -1)) {
+            int extraBytes = (int) activeFilters[lastActiveFilter].end();
+            pos = pos - extraBytes;
+        }
+
+    }
+    
+    // ---------------------------------------------------- InputBuffer Methods
+
+
+    /**
+     * Read some bytes.
+     */
+    public int doRead(ByteChunk chunk, Request req) 
+        throws IOException {
+
+        if (lastActiveFilter == -1)
+            return inputStreamInputBuffer.doRead(chunk, req);
+        else
+            return activeFilters[lastActiveFilter].doRead(chunk,req);
+
+    }
+
+    
+}

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=823351&r1=823350&r2=823351&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Thu Oct  8 
22:37:52 2009
@@ -205,7 +205,7 @@
                         socket.setSoTimeout(soTimeout);
                     }
                 }
-                inputBuffer.parseRequestLine();
+                inputBuffer.parseRequestLine(false);
                 request.setStartTime(System.currentTimeMillis());
                 keptAlive = true;
                 if (disableUploadTimeout) {

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java?rev=823351&r1=823350&r2=823351&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java Thu Oct 
 8 22:37:52 2009
@@ -18,17 +18,13 @@
 
 package org.apache.coyote.http11;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.io.EOFException;
-
-import org.apache.tomcat.util.buf.ByteChunk;
-import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.res.StringManager;
+import java.io.IOException;
 
 import org.apache.coyote.InputBuffer;
 import org.apache.coyote.Request;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.buf.MessageBytes;
 
 /**
  * Implementation of InputBuffer which provides HTTP request header parsing as
@@ -36,14 +32,7 @@
  *
  * @author <a href="mailto:r...@apache.org";>Remy Maucherat</a>
  */
-public class InternalInputBuffer implements InputBuffer {
-
-
-    // -------------------------------------------------------------- Constants
-
-
-    // ----------------------------------------------------------- Constructors
-
+public class InternalInputBuffer extends AbstractInputBuffer {
 
     /**
      * Default constructor.
@@ -74,272 +63,6 @@
 
     }
 
-
-    // -------------------------------------------------------------- Variables
-
-
-    /**
-     * The string manager for this package.
-     */
-    protected static StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * Associated Coyote request.
-     */
-    protected Request request;
-
-
-    /**
-     * Headers of the associated request.
-     */
-    protected MimeHeaders headers;
-
-
-    /**
-     * State.
-     */
-    protected boolean parsingHeader;
-
-
-    /**
-     * Swallow input ? (in the case of an expectation)
-     */
-    protected boolean swallowInput;
-
-
-    /**
-     * Pointer to the current read buffer.
-     */
-    protected byte[] buf;
-
-
-    /**
-     * Last valid byte.
-     */
-    protected int lastValid;
-
-
-    /**
-     * Position in the buffer.
-     */
-    protected int pos;
-
-
-    /**
-     * Pos of the end of the header in the buffer, which is also the
-     * start of the body.
-     */
-    protected int end;
-
-
-    /**
-     * Underlying input stream.
-     */
-    protected InputStream inputStream;
-
-
-    /**
-     * Underlying input buffer.
-     */
-    protected InputBuffer inputStreamInputBuffer;
-
-
-    /**
-     * Filter library.
-     * Note: Filter[0] is always the "chunked" filter.
-     */
-    protected InputFilter[] filterLibrary;
-
-
-    /**
-     * Active filters (in order).
-     */
-    protected InputFilter[] activeFilters;
-
-
-    /**
-     * Index of the last active filter.
-     */
-    protected int lastActiveFilter;
-
-
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * Set the underlying socket input stream.
-     */
-    public void setInputStream(InputStream inputStream) {
-
-        // FIXME: Check for null ?
-
-        this.inputStream = inputStream;
-
-    }
-
-
-    /**
-     * Get the underlying socket input stream.
-     */
-    public InputStream getInputStream() {
-
-        return inputStream;
-
-    }
-
-
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addFilter(InputFilter filter) {
-
-        // FIXME: Check for null ?
-
-        InputFilter[] newFilterLibrary = 
-            new InputFilter[filterLibrary.length + 1];
-        for (int i = 0; i < filterLibrary.length; i++) {
-            newFilterLibrary[i] = filterLibrary[i];
-        }
-        newFilterLibrary[filterLibrary.length] = filter;
-        filterLibrary = newFilterLibrary;
-
-        activeFilters = new InputFilter[filterLibrary.length];
-
-    }
-
-
-    /**
-     * Get filters.
-     */
-    public InputFilter[] getFilters() {
-
-        return filterLibrary;
-
-    }
-
-
-    /**
-     * Clear filters.
-     */
-    public void clearFilters() {
-
-        filterLibrary = new InputFilter[0];
-        lastActiveFilter = -1;
-
-    }
-
-
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addActiveFilter(InputFilter filter) {
-
-        if (lastActiveFilter == -1) {
-            filter.setBuffer(inputStreamInputBuffer);
-        } else {
-            for (int i = 0; i <= lastActiveFilter; i++) {
-                if (activeFilters[i] == filter)
-                    return;
-            }
-            filter.setBuffer(activeFilters[lastActiveFilter]);
-        }
-
-        activeFilters[++lastActiveFilter] = filter;
-
-        filter.setRequest(request);
-
-    }
-
-
-    /**
-     * Set the swallow input flag.
-     */
-    public void setSwallowInput(boolean swallowInput) {
-        this.swallowInput = swallowInput;
-    }
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    /**
-     * Recycle the input buffer. This should be called when closing the 
-     * connection.
-     */
-    public void recycle() {
-
-        // Recycle Request object
-        request.recycle();
-
-        inputStream = null;
-        lastValid = 0;
-        pos = 0;
-        lastActiveFilter = -1;
-        parsingHeader = true;
-        swallowInput = true;
-
-    }
-
-
-    /**
-     * End processing of current HTTP request.
-     * Note: All bytes of the current request should have been already 
-     * consumed. This method only resets all the pointers so that we are ready
-     * to parse the next HTTP request.
-     */
-    public void nextRequest() {
-
-        // Recycle Request object
-        request.recycle();
-
-        // Copy leftover bytes to the beginning of the buffer
-        if (lastValid - pos > 0) {
-            int npos = 0;
-            int opos = pos;
-            while (lastValid - opos > opos - npos) {
-                System.arraycopy(buf, opos, buf, npos, opos - npos);
-                npos += pos;
-                opos += pos;
-            }
-            System.arraycopy(buf, opos, buf, npos, lastValid - opos);
-        }
-
-        // Recycle filters
-        for (int i = 0; i <= lastActiveFilter; i++) {
-            activeFilters[i].recycle();
-        }
-
-        // Reset pointers
-        lastValid = lastValid - pos;
-        pos = 0;
-        lastActiveFilter = -1;
-        parsingHeader = true;
-        swallowInput = true;
-
-    }
-
-
-    /**
-     * End request (consumes leftover bytes).
-     * 
-     * @throws IOException an undelying I/O error occured
-     */
-    public void endRequest()
-        throws IOException {
-
-        if (swallowInput && (lastActiveFilter != -1)) {
-            int extraBytes = (int) activeFilters[lastActiveFilter].end();
-            pos = pos - extraBytes;
-        }
-
-    }
-
-
     /**
      * Read the request line. This function is meant to be used during the 
      * HTTP request header parsing. Do NOT attempt to read the request body 
@@ -349,7 +72,8 @@
      * read operations, or if the given buffer is not big enough to accomodate
      * the whole line.
      */
-    public void parseRequestLine()
+    public boolean parseRequestLine(boolean useAvailableDataOnly)
+    
         throws IOException {
 
         int start = 0;
@@ -516,6 +240,8 @@
         } else {
             request.protocol().setString("");
         }
+        
+        return true;
 
     }
 
@@ -523,7 +249,7 @@
     /**
      * Parse the HTTP headers.
      */
-    public void parseHeaders()
+    public boolean parseHeaders()
         throws IOException {
 
         while (parseHeader()) {
@@ -531,7 +257,7 @@
 
         parsingHeader = false;
         end = pos;
-
+        return true;
     }
 
 
@@ -695,33 +421,19 @@
     }
 
 
-    // ---------------------------------------------------- InputBuffer Methods
-
-
-    /**
-     * Read some bytes.
-     */
-    public int doRead(ByteChunk chunk, Request req) 
-        throws IOException {
-
-        if (lastActiveFilter == -1)
-            return inputStreamInputBuffer.doRead(chunk, req);
-        else
-            return activeFilters[lastActiveFilter].doRead(chunk,req);
-
-    }
-
-
     // ------------------------------------------------------ Protected Methods
 
 
     /**
-     * Fill the internal buffer using data from the undelying input stream.
+     * Fill the internal buffer using data from the underlying input stream.
      * 
      * @return false if at end of stream
      */
-    protected boolean fill()
-        throws IOException {
+    protected boolean fill() throws IOException {
+        return fill(true);
+    }
+
+    protected boolean fill(boolean block) throws IOException {
 
         int nRead = 0;
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=823351&r1=823350&r2=823351&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Thu 
Oct  8 22:37:52 2009
@@ -26,11 +26,9 @@
 import org.apache.coyote.Request;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.net.NioChannel;
-import org.apache.tomcat.util.net.NioSelectorPool;
-import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.net.NioEndpoint;
+import org.apache.tomcat.util.net.NioSelectorPool;
 
 /**
  * Implementation of InputBuffer which provides HTTP request header parsing as
@@ -39,7 +37,7 @@
  * @author <a href="mailto:r...@apache.org";>Remy Maucherat</a>
  * @author Filip Hanik
  */
-public class InternalNioInputBuffer implements InputBuffer {
+public class InternalNioInputBuffer extends AbstractInputBuffer {
 
 
     // -------------------------------------------------------------- Constants
@@ -82,32 +80,6 @@
 
     }
 
-
-    // -------------------------------------------------------------- Variables
-
-
-    /**
-     * The string manager for this package.
-     */
-    protected static StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * Associated Coyote request.
-     */
-    protected Request request;
-
-
-    /**
-     * Headers of the associated request.
-     */
-    protected MimeHeaders headers;
-
-
     /**
      * Parsing state - used for non blocking parsing so that
      * when more data arrives, we can pick up where we left off.
@@ -120,39 +92,6 @@
     protected int parsingRequestLineQPos = -1;
     protected HeaderParsePosition headerParsePos;
 
-
-    /**
-     * Swallow input ? (in the case of an expectation)
-     */
-    protected boolean swallowInput;
-
-
-    /**
-     * Pointer to the current read buffer.
-     */
-    protected byte[] buf;
-
-
-    /**
-     * Last valid byte.
-     */
-    protected int lastValid;
-
-
-    /**
-     * Position in the buffer.
-     */
-    protected int pos;
-
-
-    /**
-     * Pos of the end of the header in the buffer, which is also the
-     * start of the body.
-     */
-    protected int end;
-
-
-
     /**
      * Underlying socket.
      */
@@ -164,30 +103,6 @@
     protected NioSelectorPool pool;
     
 
-    /**
-     * Underlying input buffer.
-     */
-    protected InputBuffer inputStreamInputBuffer;
-
-
-    /**
-     * Filter library.
-     * Note: Filter[0] is always the "chunked" filter.
-     */
-    protected InputFilter[] filterLibrary;
-
-
-    /**
-     * Active filters (in order).
-     */
-    protected InputFilter[] activeFilters;
-
-
-    /**
-     * Index of the last active filter.
-     */
-    protected int lastActiveFilter;
-
 
     // ------------------------------------------------------------- Properties
 
@@ -215,74 +130,6 @@
     }
 
 
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addFilter(InputFilter filter) {
-
-        InputFilter[] newFilterLibrary = 
-            new InputFilter[filterLibrary.length + 1];
-        for (int i = 0; i < filterLibrary.length; i++) {
-            newFilterLibrary[i] = filterLibrary[i];
-        }
-        newFilterLibrary[filterLibrary.length] = filter;
-        filterLibrary = newFilterLibrary;
-
-        activeFilters = new InputFilter[filterLibrary.length];
-
-    }
-
-
-    /**
-     * Get filters.
-     */
-    public InputFilter[] getFilters() {
-
-        return filterLibrary;
-
-    }
-
-
-    /**
-     * Clear filters.
-     */
-    public void clearFilters() {
-
-        filterLibrary = new InputFilter[0];
-        lastActiveFilter = -1;
-
-    }
-
-
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addActiveFilter(InputFilter filter) {
-
-        if (lastActiveFilter == -1) {
-            filter.setBuffer(inputStreamInputBuffer);
-        } else {
-            for (int i = 0; i <= lastActiveFilter; i++) {
-                if (activeFilters[i] == filter)
-                    return;
-            }
-            filter.setBuffer(activeFilters[lastActiveFilter]);
-        }
-
-        activeFilters[++lastActiveFilter] = filter;
-
-        filter.setRequest(request);
-
-    }
-
-
-    /**
-     * Set the swallow input flag.
-     */
-    public void setSwallowInput(boolean swallowInput) {
-        this.swallowInput = swallowInput;
-    }
-
     // --------------------------------------------------------- Public Methods
     /**
      * Returns true if there are bytes available from the socket layer
@@ -307,19 +154,12 @@
      * connection.
      */
     public void recycle() {
+        super.recycle();
         // Recycle filters
         for (int i = 0; i <= lastActiveFilter; i++) {
             activeFilters[i].recycle();
         }
-
-        // Recycle Request object
-        request.recycle();
-
         socket = null;
-        lastValid = 0;
-        pos = 0;
-        lastActiveFilter = -1;
-        parsingHeader = true;
         headerParsePos = HeaderParsePosition.HEADER_START;
         parsingRequestLine = true;
         parsingRequestLinePhase = 0;
@@ -327,8 +167,6 @@
         parsingRequestLineStart = 0;
         parsingRequestLineQPos = -1;
         headerData.recycle();
-        swallowInput = true;
-
     }
 
 
@@ -339,31 +177,7 @@
      * to parse the next HTTP request.
      */
     public void nextRequest() {
-
-        // Recycle Request object
-        request.recycle();
-
-        // Copy leftover bytes to the beginning of the buffer
-        if (lastValid - pos > 0) {
-            int npos = 0;
-            int opos = pos;
-            while (lastValid - opos > opos - npos) {
-                System.arraycopy(buf, opos, buf, npos, opos - npos);
-                npos += pos;
-                opos += pos;
-            }
-            System.arraycopy(buf, opos, buf, npos, lastValid - opos);
-        }
-
-        // Recycle filters
-        for (int i = 0; i <= lastActiveFilter; i++) {
-            activeFilters[i].recycle();
-        }
-
-        // Reset pointers
-        lastValid = lastValid - pos;
-        pos = 0;
-        lastActiveFilter = -1;
+        super.nextRequest();
         parsingHeader = true;
         headerParsePos = HeaderParsePosition.HEADER_START;
         parsingRequestLine = true;
@@ -372,27 +186,8 @@
         parsingRequestLineStart = 0;
         parsingRequestLineQPos = -1;
         headerData.recycle();
-        swallowInput = true;
-
-    }
-
-
-    /**
-     * End request (consumes leftover bytes).
-     * 
-     * @throws IOException an undelying I/O error occured
-     */
-    public void endRequest()
-        throws IOException {
-
-        if (swallowInput && (lastActiveFilter != -1)) {
-            int extraBytes = (int) activeFilters[lastActiveFilter].end();
-            pos = pos - extraBytes;
-        }
-
     }
 
-
     /**
      * Read the request line. This function is meant to be used during the 
      * HTTP request header parsing. Do NOT attempt to read the request body 
@@ -404,7 +199,7 @@
      * @return true if data is properly fed; false if no data is available 
      * immediately and thread should be freed
      */
-    public boolean parseRequestLine(boolean useAvailableData)
+    public boolean parseRequestLine(boolean useAvailableDataOnly)
         throws IOException {
 
         //check state
@@ -418,7 +213,7 @@
                 
                 // Read new bytes if needed
                 if (pos >= lastValid) {
-                    if (useAvailableData) {
+                    if (useAvailableDataOnly) {
                         return false;
                     }
                     // Do a simple read with a short timeout
@@ -434,7 +229,7 @@
             // Mark the current buffer position
             
             if (pos >= lastValid) {
-                if (useAvailableData) {
+                if (useAvailableDataOnly) {
                     return false;
                 }
                 // Do a simple read with a short timeout
@@ -593,6 +388,7 @@
      * @throws IOException if a socket exception occurs
      * @throws EOFException if end of stream is reached
      */
+    
     private int readSocket(boolean timeout, boolean block) throws IOException {
         int nRead = 0;
         socket.getBufHandler().getReadBuffer().clear();
@@ -849,32 +645,21 @@
     }
 
 
-    // ---------------------------------------------------- InputBuffer Methods
-
-
-    /**
-     * Read some bytes.
-     */
-    public int doRead(ByteChunk chunk, Request req) 
-        throws IOException {
-
-        if (lastActiveFilter == -1)
-            return inputStreamInputBuffer.doRead(chunk, req);
-        else
-            return activeFilters[lastActiveFilter].doRead(chunk,req);
-
-    }
 
 
     // ------------------------------------------------------ Protected Methods
 
     /**
-     * Fill the internal buffer using data from the undelying input stream.
+     * Fill the internal buffer using data from the underlying input stream.
      * 
      * @return false if at end of stream
      */
-    protected boolean fill(boolean timeout, boolean block)
-        throws IOException, EOFException {
+    protected boolean fill(boolean block) throws IOException, EOFException {
+        return fill(true,block);
+    }
+
+    protected boolean fill(boolean timeout, boolean block) throws IOException, 
EOFException {
+        
 
         boolean read = false;
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=823351&r1=823350&r2=823351&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Thu Oct  8 
22:37:52 2009
@@ -21,6 +21,7 @@
 import java.net.BindException;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.SocketException;
 import java.util.concurrent.RejectedExecutionException;
 
 import org.apache.juli.logging.Log;
@@ -338,6 +339,13 @@
         try {
             // 1: Set socket options: timeout, linger, etc
             socketProperties.setProperties(socket);
+        } catch (SocketException s) {
+            //error here is common if the client has reset the connection
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("endpoint.err.unexpected"), s);
+            }
+            // Close the socket
+            return false;
         } catch (Throwable t) {
             log.error(sm.getString("endpoint.err.unexpected"), t);
             // Close the socket



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

Reply via email to