hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r580730 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http: impl/nio/DefaultNHttpClientConnection.java impl/nio/DefaultNHttpServerConnection.java impl/nio/NHttpConnectionBase.java nio/NHttpConnection.java
Date Sun, 30 Sep 2007 14:36:07 GMT
Author: olegk
Date: Sun Sep 30 07:36:07 2007
New Revision: 580730

URL: http://svn.apache.org/viewvc?rev=580730&view=rev
Log:
HTTPCORE-117: 
* Reverted my previous changes preventing the session output buffer from being flushed upon
connection closure
* Introduced connection status attribute indicating whether the connection is active, closed
or is in the process of flushing the content of its session output buffer

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpConnection.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=580730&r1=580729&r2=580730&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
Sun Sep 30 07:36:07 2007
@@ -102,7 +102,7 @@
     }
     
     public void consumeInput(final NHttpClientHandler handler) {
-        if (this.closed) {
+        if (this.status != ACTIVE) {
             this.session.clearEvent(EventMask.READ);
             return;
         }
@@ -159,8 +159,9 @@
                 }
             }
             if (!this.outbuf.hasData()) {
-                if (this.closed) {
+                if (this.status == CLOSING) {
                     this.session.close();
+                    this.status = CLOSED;
                     resetOutput();
                     return;
                 } else {
@@ -173,8 +174,9 @@
                 }
                 
                 if (this.contentEncoder == null && !this.outbuf.hasData()) {
-                    if (this.closed) {
+                    if (this.status == CLOSING) {
                         this.session.close();
+                        this.status = CLOSED;
                         return;
                     }
                     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=580730&r1=580729&r2=580730&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
Sun Sep 30 07:36:07 2007
@@ -99,7 +99,7 @@
     }
     
     public void consumeInput(final NHttpServiceHandler handler) {
-        if (this.closed) {
+        if (this.status != ACTIVE) {
             this.session.clearEvent(EventMask.READ);
             return;
         }
@@ -158,8 +158,9 @@
                 }
             }
             if (!this.outbuf.hasData()) {
-                if (this.closed) {
+                if (this.status == CLOSING) {
                     this.session.close();
+                    this.status = CLOSED;
                     resetOutput();
                     return;
                 } else {
@@ -172,8 +173,9 @@
                 }
                 
                 if (this.contentEncoder == null && !this.outbuf.hasData()) {
-                    if (this.closed) {
+                    if (this.status == CLOSING) {
                         this.session.close();
+                        this.status = CLOSED;
                         return;
                     }
                     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=580730&r1=580729&r2=580730&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
Sun Sep 30 07:36:07 2007
@@ -95,7 +95,7 @@
     protected volatile HttpRequest request;
     protected volatile HttpResponse response;
 
-    protected volatile boolean closed;
+    protected volatile int status;
     
     public NHttpConnectionBase(
             final IOSession session,
@@ -129,9 +129,13 @@
                 this.inTransportMetrics, 
                 this.outTransportMetrics);
         
-        this.closed = false;
         this.session.setBufferStatus(this);
         this.session.setEvent(EventMask.READ);
+        this.status = ACTIVE;
+    }
+
+    public int getStatus() {
+        return this.status;
     }
 
     public HttpContext getContext() {
@@ -230,18 +234,26 @@
     }
     
     protected void assertNotClosed() throws IOException {
-        if (this.closed) {
+        if (this.status != ACTIVE) {
             throw new ConnectionClosedException("Connection is closed");
         }
     }
 
     public void close() throws IOException {
-        this.closed = true;
-        this.session.close();
+        if (this.status != ACTIVE) {
+            return;
+        }
+        this.status = CLOSING;
+        if (this.outbuf.hasData()) {
+            this.session.setEvent(EventMask.WRITE);
+        } else {
+            this.session.close();
+            this.status = CLOSED;
+        }
     }
 
     public boolean isOpen() {
-        return !this.closed && !this.session.isClosed();
+        return this.status == ACTIVE && !this.session.isClosed();
     }
 
     public boolean isStale() {
@@ -293,7 +305,7 @@
     }
 
     public void shutdown() throws IOException {
-        this.closed = true;
+        this.status = CLOSED;
         this.session.shutdown();
     }
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpConnection.java?rev=580730&r1=580729&r2=580730&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpConnection.java
Sun Sep 30 07:36:07 2007
@@ -45,6 +45,12 @@
  */
 public interface NHttpConnection extends HttpConnection, IOControl {
 
+    public static final int ACTIVE      = 0;
+    public static final int CLOSING     = 1;
+    public static final int CLOSED      = 2;
+    
+    int getStatus();
+    
     /** 
      * Returns the current HTTP request if one is being received / transmitted.
      * Otherwise returns <tt>null</tt>.



Mime
View raw message