hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r678837 - in /httpcomponents/httpcore/trunk: ./ module-main/src/main/java/org/apache/http/impl/ module-main/src/main/java/org/apache/http/impl/io/
Date Tue, 22 Jul 2008 18:01:27 GMT
Author: olegk
Date: Tue Jul 22 11:01:26 2008
New Revision: 678837

URL: http://svn.apache.org/viewvc?rev=678837&view=rev
Log:
HTTPCORE-167: Fixed handling the end of stream (EOF) condition in the #isStale() check of
blocking HTTP connections

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=678837&r1=678836&r2=678837&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Jul 22 11:01:26 2008
@@ -1,6 +1,10 @@
 Changes since 4.0 Beta2
 -------------------
 
+* [HTTPCORE-167] Fixed handling the end of stream (EOF) condition in the #isStale() 
+  check of blocking HTTP connections.
+  Contributed by Oleg Kalnichevski <olegk at apache.org> 
+
 * [HTTPCORE-166] NIO reactors now maintain an audit log of fatal exceptions,
   which can be used to examine the cause and problems experienced during 
   the shutdown process.

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java?rev=678837&r1=678836&r2=678837&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
Tue Jul 22 11:01:26 2008
@@ -47,6 +47,7 @@
 import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.io.HttpRequestWriter;
 import org.apache.http.impl.io.HttpResponseParser;
+import org.apache.http.io.EofSensor;
 import org.apache.http.io.HttpMessageParser;
 import org.apache.http.io.HttpMessageWriter;
 import org.apache.http.io.SessionInputBuffer;
@@ -70,12 +71,11 @@
     
     private SessionInputBuffer inbuffer = null;
     private SessionOutputBuffer outbuffer = null;
+    private EofSensor eofSensor = null;
     private HttpMessageParser responseParser = null;
     private HttpMessageWriter requestWriter = null;
     private HttpConnectionMetricsImpl metrics = null;
 
-
-
     public AbstractHttpClientConnection() {
         super();
         this.entityserializer = createEntitySerializer();
@@ -123,6 +123,9 @@
         }
         this.inbuffer = inbuffer;
         this.outbuffer = outbuffer;
+        if (inbuffer instanceof EofSensor) {
+            this.eofSensor = (EofSensor) inbuffer;
+        }
         this.responseParser = createResponseParser(
                 inbuffer, 
                 createHttpResponseFactory(), 
@@ -193,13 +196,20 @@
         response.setEntity(entity);
     }
     
+    protected boolean isEof() {
+        return this.eofSensor != null && this.eofSensor.isEof();
+    }
+    
     public boolean isStale() {
         if (!isOpen()) {
             return true;
         }
+        if (isEof()) {
+            return true;
+        }
         try {
             this.inbuffer.isDataAvailable(1);
-            return false;
+            return isEof();
         } catch (IOException ex) {
             return true;
         }

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?rev=678837&r1=678836&r2=678837&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
Tue Jul 22 11:01:26 2008
@@ -47,6 +47,7 @@
 import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.io.HttpRequestParser;
 import org.apache.http.impl.io.HttpResponseWriter;
+import org.apache.http.io.EofSensor;
 import org.apache.http.io.HttpMessageParser;
 import org.apache.http.io.HttpMessageWriter;
 import org.apache.http.io.SessionInputBuffer;
@@ -70,12 +71,11 @@
     
     private SessionInputBuffer inbuffer = null;
     private SessionOutputBuffer outbuffer = null;
+    private EofSensor eofSensor = null;
     private HttpMessageParser requestParser = null;
     private HttpMessageWriter responseWriter = null;
     private HttpConnectionMetricsImpl metrics = null;
 
-
-
     public AbstractHttpServerConnection() {
         super();
         this.entityserializer = createEntitySerializer();
@@ -124,6 +124,9 @@
         }
         this.inbuffer = inbuffer;
         this.outbuffer = outbuffer;
+        if (inbuffer instanceof EofSensor) {
+            this.eofSensor = (EofSensor) inbuffer;
+        }
         this.requestParser = createRequestParser(
                 inbuffer, 
                 createHttpRequestFactory(), 
@@ -185,11 +188,20 @@
                 response.getEntity());
     }
     
+    protected boolean isEof() {
+        return this.eofSensor != null && this.eofSensor.isEof();
+    }
+    
     public boolean isStale() {
-        assertOpen();
+        if (!isOpen()) {
+            return true;
+        }
+        if (isEof()) {
+            return true;
+        }
         try {
             this.inbuffer.isDataAvailable(1);
-            return false;
+            return isEof();
         } catch (IOException ex) {
             return true;
         }

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java?rev=678837&r1=678836&r2=678837&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
Tue Jul 22 11:01:26 2008
@@ -76,14 +76,14 @@
         }
     }
     
-    protected SessionInputBuffer createHttpDataReceiver(
+    protected SessionInputBuffer createSessionInputBuffer(
             final Socket socket, 
             int buffersize,
             final HttpParams params) throws IOException {
         return new SocketInputBuffer(socket, buffersize, params);
     }
     
-    protected SessionOutputBuffer createHttpDataTransmitter(
+    protected SessionOutputBuffer createSessionOutputBuffer(
             final Socket socket, 
             int buffersize,
             final HttpParams params) throws IOException {
@@ -102,8 +102,8 @@
         int buffersize = HttpConnectionParams.getSocketBufferSize(params);
         
         init(
-                createHttpDataReceiver(socket, buffersize, params), 
-                createHttpDataTransmitter(socket, buffersize, params),
+                createSessionInputBuffer(socket, buffersize, params), 
+                createSessionOutputBuffer(socket, buffersize, params),
                 params);
         
         this.open = true;

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java?rev=678837&r1=678836&r2=678837&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java
Tue Jul 22 11:01:26 2008
@@ -35,6 +35,7 @@
 import java.io.InterruptedIOException;
 import java.net.Socket;
 
+import org.apache.http.io.EofSensor;
 import org.apache.http.params.HttpParams;
 
 
@@ -47,7 +48,7 @@
  * 
  * @since 4.0
  */
-public class SocketInputBuffer extends AbstractSessionInputBuffer {
+public class SocketInputBuffer extends AbstractSessionInputBuffer implements EofSensor {
 
     static private final Class SOCKET_TIMEOUT_CLASS = SocketTimeoutExceptionClass();
 
@@ -75,6 +76,8 @@
     
     private final Socket socket;
     
+    private boolean eof;
+    
     public SocketInputBuffer(
             final Socket socket, 
             int buffersize, 
@@ -84,6 +87,7 @@
             throw new IllegalArgumentException("Socket may not be null");
         }
         this.socket = socket;
+        this.eof = false;
         if (buffersize < 0) {
             buffersize = socket.getReceiveBufferSize();
         }
@@ -93,6 +97,12 @@
         init(socket.getInputStream(), buffersize, params);
     }
     
+    protected int fillBuffer() throws IOException {
+        int i = super.fillBuffer();
+        this.eof = i == -1;
+        return i;
+    }
+
     public boolean isDataAvailable(int timeout) throws IOException {
         boolean result = hasBufferedData();
         if (!result) {
@@ -110,6 +120,10 @@
             }
         }
         return result;
+    }
+
+    public boolean isEof() {
+        return this.eof;
     }    
-        
+    
 }



Mime
View raw message