hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1406721 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/impl/ main/java/org/apache/http/impl/io/ test/java/org/apache/http/impl/pool/
Date Wed, 07 Nov 2012 17:05:48 GMT
Author: olegk
Date: Wed Nov  7 17:05:48 2012
New Revision: 1406721

URL: http://svn.apache.org/viewvc?rev=1406721&view=rev
Log:
Allow blocking connections to be bound to a disconnected socket

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
Wed Nov  7 17:05:48 2012
@@ -122,12 +122,14 @@ public class BHttpConnectionBase impleme
             StrictContentLengthStrategy.INSTANCE;
     }
 
-    protected void assertNotOpen() {
-        Asserts.check(!this.open, "Connection is already open");
-    }
-
-    protected void assertOpen() {
+    protected void ensureOpen() throws IOException {
         Asserts.check(this.open, "Connection is not open");
+        if (!this.inbuffer.isBound()) {
+            this.inbuffer.bind(getSocketInputStream(this.socket));
+        }
+        if (!this.outbuffer.isBound()) {
+            this.outbuffer.bind(getSocketOutputStream(this.socket));
+        }
     }
 
     protected InputStream getSocketInputStream(final Socket socket) throws IOException {
@@ -152,8 +154,8 @@ public class BHttpConnectionBase impleme
         Args.notNull(socket, "Socket");
         this.socket = socket;
         this.open = true;
-        this.inbuffer.bind(getSocketInputStream(socket));
-        this.outbuffer.bind(getSocketOutputStream(socket));
+        this.inbuffer.bind(null);
+        this.outbuffer.bind(null);
     }
 
     protected SessionInputBuffer getSessionInputBuffer() {
@@ -268,7 +270,6 @@ public class BHttpConnectionBase impleme
     }
 
     public void setSocketTimeout(int timeout) {
-        assertOpen();
         if (this.socket != null) {
             try {
                 this.socket.setSoTimeout(timeout);

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
Wed Nov  7 17:05:48 2012
@@ -125,7 +125,7 @@ public class DefaultBHttpClientConnectio
     }
 
     public boolean isResponseAvailable(int timeout) throws IOException {
-        assertOpen();
+        ensureOpen();
         try {
             return awaitInput(timeout);
         } catch (SocketTimeoutException ex) {
@@ -136,7 +136,7 @@ public class DefaultBHttpClientConnectio
     public void sendRequestHeader(final HttpRequest request)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        assertOpen();
+        ensureOpen();
         this.requestWriter.write(request);
         onRequestSubmitted(request);
         incrementRequestCount();
@@ -145,7 +145,7 @@ public class DefaultBHttpClientConnectio
     public void sendRequestEntity(final HttpEntityEnclosingRequest request)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        assertOpen();
+        ensureOpen();
         HttpEntity entity = request.getEntity();
         if (entity == null) {
             return;
@@ -156,7 +156,7 @@ public class DefaultBHttpClientConnectio
     }
 
     public HttpResponse receiveResponseHeader() throws HttpException, IOException {
-        assertOpen();
+        ensureOpen();
         HttpResponse response = this.responseParser.parse();
         onResponseReceived(response);
         if (response.getStatusLine().getStatusCode() >= 200) {
@@ -168,13 +168,13 @@ public class DefaultBHttpClientConnectio
     public void receiveResponseEntity(
             final HttpResponse response) throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        assertOpen();
+        ensureOpen();
         HttpEntity entity = prepareInput(response);
         response.setEntity(entity);
     }
 
     public void flush() throws IOException {
-        assertOpen();
+        ensureOpen();
         doFlush();
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
Wed Nov  7 17:05:48 2012
@@ -126,7 +126,7 @@ public class DefaultBHttpServerConnectio
 
     public HttpRequest receiveRequestHeader()
             throws HttpException, IOException {
-        assertOpen();
+        ensureOpen();
         HttpRequest request = this.requestParser.parse();
         onRequestReceived(request);
         incrementRequestCount();
@@ -136,7 +136,7 @@ public class DefaultBHttpServerConnectio
     public void receiveRequestEntity(final HttpEntityEnclosingRequest request)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        assertOpen();
+        ensureOpen();
         HttpEntity entity = prepareInput(request);
         request.setEntity(entity);
     }
@@ -144,7 +144,7 @@ public class DefaultBHttpServerConnectio
     public void sendResponseHeader(final HttpResponse response)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        assertOpen();
+        ensureOpen();
         this.responseWriter.write(response);
         onResponseSubmitted(response);
         if (response.getStatusLine().getStatusCode() >= 200) {
@@ -155,7 +155,7 @@ public class DefaultBHttpServerConnectio
     public void sendResponseEntity(final HttpResponse response)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        assertOpen();
+        ensureOpen();
         HttpEntity entity = response.getEntity();
         if (entity == null) {
             return;
@@ -166,7 +166,7 @@ public class DefaultBHttpServerConnectio
     }
 
     public void flush() throws IOException {
-        assertOpen();
+        ensureOpen();
         doFlush();
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
Wed Nov  7 17:05:48 2012
@@ -109,6 +109,10 @@ public class SessionInputBufferImpl impl
         this.instream = instream;
     }
 
+    public boolean isBound() {
+        return this.instream != null;
+    }
+
     public int capacity() {
         return this.buffer.length;
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
Wed Nov  7 17:05:48 2012
@@ -98,6 +98,10 @@ public class SessionOutputBufferImpl imp
         this.outstream = outstream;
     }
 
+    public boolean isBound() {
+        return this.outstream != null;
+    }
+
     public int capacity() {
         return this.buffer.capacity();
     }
@@ -116,8 +120,9 @@ public class SessionOutputBufferImpl imp
     }
 
     private void flushStream() throws IOException {
-        Asserts.notNull(outstream, "Output stream");
-        this.outstream.flush();
+        if (this.outstream != null) {
+            this.outstream.flush();
+        }
     }
 
     private void flushBuffer() throws IOException {

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java?rev=1406721&r1=1406720&r2=1406721&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
Wed Nov  7 17:05:48 2012
@@ -75,7 +75,6 @@ public class TestBasicConnPool {
         server.close();
         if(conn != null) {
             conn.close();
-            conn.shutdown();
         }
     }
 



Mime
View raw message