hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r478156 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio: impl/NHttpConnectionBase.java impl/reactor/BaseIOReactor.java impl/reactor/SessionSet.java util/ContentInputBuffer.java
Date Wed, 22 Nov 2006 13:10:58 GMT
Author: olegk
Date: Wed Nov 22 05:10:57 2006
New Revision: 478156

URL: http://svn.apache.org/viewvc?view=rev&rev=478156
Log:
Added additional safeguards intended to ensure that the I/O reactor refires 'input ready'
event until all buffered session content is fully consumed even if the underlying socket channel
no longer selects for input

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/BaseIOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/SessionSet.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java?view=diff&rev=478156&r1=478155&r2=478156
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
Wed Nov 22 05:10:57 2006
@@ -115,6 +115,7 @@
         this.outgoingContentStrategy = new StrictContentLengthStrategy();
         
         this.closed = false;
+        this.session.setBufferStatus(this);
         this.session.setEvent(EventMask.READ);
     }
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/BaseIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/BaseIOReactor.java?view=diff&rev=478156&r1=478155&r2=478156
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/BaseIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/BaseIOReactor.java
Wed Nov 22 05:10:57 2006
@@ -34,16 +34,20 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SessionBufferStatus;
 
 public class BaseIOReactor extends AbstractIOReactor {
 
     private final long timeoutCheckInterval;
+    private SessionSet bufferingSessions;
     
     private long lastTimeoutCheck;
     
     public BaseIOReactor(long selectTimeout) throws IOException {
         super(selectTimeout);
+        this.bufferingSessions = new SessionSet();
         this.timeoutCheckInterval = selectTimeout;
         this.lastTimeoutCheck = System.currentTimeMillis();
     }
@@ -60,6 +64,12 @@
         handle.resetLastRead();
 
         this.eventDispatch.inputReady(session);
+        SessionBufferStatus bufStatus = session.getBufferStatus();
+        if (bufStatus != null) {
+            if (bufStatus.hasBufferedInput()) {
+                this.bufferingSessions.add(session);
+            }
+        }
     }
 
     protected void writable(final SelectionKey key) {
@@ -78,6 +88,29 @@
                 for (Iterator it = keys.iterator(); it.hasNext();) {
                     SelectionKey key = (SelectionKey) it.next();
                     timeoutCheck(key, currentTime);
+                }
+            }
+        }
+        synchronized (this.bufferingSessions) {
+            if (!this.bufferingSessions.isEmpty()) {
+                for (Iterator it = this.bufferingSessions.iterator(); it.hasNext(); ) {
+                    IOSession session = (IOSession) it.next();
+                    SessionBufferStatus bufStatus = session.getBufferStatus();
+                    if (bufStatus != null) {
+                        if (!bufStatus.hasBufferedInput()) {
+                            it.remove();
+                            continue;
+                        }
+                    }
+                    int ops = session.getEventMask();
+                    if ((ops & EventMask.READ) > 0) {
+                        this.eventDispatch.inputReady(session);
+                        if (bufStatus != null) {
+                            if (!bufStatus.hasBufferedInput()) {
+                                it.remove();
+                            }
+                        }
+                    }
                 }
             }
         }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/SessionSet.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/SessionSet.java?view=diff&rev=478156&r1=478155&r2=478156
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/SessionSet.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/SessionSet.java
Wed Nov 22 05:10:57 2006
@@ -62,6 +62,10 @@
         this.set.clear();
     }
 
+    public synchronized boolean isEmpty() {
+        return this.set.isEmpty();
+    }
+    
     public Iterator iterator() {
         return this.set.iterator();
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java?view=diff&rev=478156&r1=478155&r2=478156
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
Wed Nov 22 05:10:57 2006
@@ -67,11 +67,15 @@
         }
         synchronized (this.mutex) {
             setInputMode();
-            int bytesRead = decoder.read(this.buffer);
+            int totalRead = 0;
+            int bytesRead;
+            while ((bytesRead = decoder.read(this.buffer)) > 0) {
+                totalRead += bytesRead; 
+            }
             if (bytesRead == -1 || decoder.isCompleted()) {
                 this.endOfStream = true;
             }
-            if (bytesRead > 0) {
+            if (totalRead > 0) {
                 this.ioctrl.suspendInput();
             }
             this.mutex.notifyAll();            



Mime
View raw message