You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/11/12 14:35:44 UTC

svn commit: r594116 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http: impl/nio/codecs/ impl/nio/reactor/ nio/reactor/

Author: olegk
Date: Mon Nov 12 05:35:43 2007
New Revision: 594116

URL: http://svn.apache.org/viewvc?rev=594116&view=rev
Log:
Eliminated intermediate buffering of session data during channel transfer in LengthDelimitedDecoder and IdentityDecoder  

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java Mon Nov 12 05:35:43 2007
@@ -97,10 +97,7 @@
         
         long bytesRead;
         if (this.buffer.hasData()) {
-            ByteBuffer tmpDst = ByteBuffer.allocate((int)count);
-            this.buffer.read(tmpDst);
-            tmpDst.flip();
-            bytesRead = dst.write(tmpDst);
+            bytesRead = this.buffer.read(dst);
         } else {
             if (this.channel.isOpen()) {
                 bytesRead = dst.transferFrom(this.channel, position, count);

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java Mon Nov 12 05:35:43 2007
@@ -124,10 +124,7 @@
         long bytesRead;
         if (this.buffer.hasData()) {
             int maxLen = Math.min(lenRemaining, this.buffer.length());
-            ByteBuffer tmpDst = ByteBuffer.allocate(maxLen);
-            this.buffer.read(tmpDst, maxLen);
-            tmpDst.flip();
-            bytesRead = dst.write(tmpDst);
+            bytesRead = this.buffer.read(dst, maxLen);
         } else {
             if (count > lenRemaining) {
                 count = lenRemaining;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java Mon Nov 12 05:35:43 2007
@@ -35,6 +35,7 @@
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
@@ -109,8 +110,37 @@
         }
         return read(dst, dst.remaining());
     }
+
+    public int read(final WritableByteChannel dst, int maxLen) throws IOException {
+        if (dst == null) {
+            return 0;
+        }
+        setOutputMode();
+        int bytesRead;
+        if (this.buffer.remaining() > maxLen) {
+            int oldLimit = this.buffer.limit();
+            int newLimit = oldLimit - (this.buffer.remaining() - maxLen);
+            this.buffer.limit(newLimit);
+            bytesRead = dst.write(this.buffer);
+            this.buffer.limit(oldLimit);
+        } else {
+            bytesRead = dst.write(this.buffer);
+        }
+        return bytesRead;
+    }
+    
+    public int read(final WritableByteChannel dst) throws IOException {
+        if (dst == null) {
+            return 0;
+        }
+        setOutputMode();
+        return dst.write(this.buffer);
+    }
     
-    public boolean readLine(final CharArrayBuffer linebuffer, boolean endOfStream) throws CharacterCodingException {
+    public boolean readLine(
+            final CharArrayBuffer linebuffer, 
+            boolean endOfStream) throws CharacterCodingException {
+        
         setOutputMode();
         // See if there is LF char present in the buffer
         int pos = -1;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java Mon Nov 12 05:35:43 2007
@@ -34,6 +34,7 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
+import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
@@ -89,13 +90,21 @@
     }
 
     public void write(final ByteBuffer src) {
-        if (buffer == null) {
+        if (src == null) {
             return;
         }
         setInputMode();
         int requiredCapacity = this.buffer.position() + src.remaining();
         ensureCapacity(requiredCapacity);
         this.buffer.put(src);
+    }
+
+    public void write(final ReadableByteChannel src) throws IOException {
+        if (src == null) {
+            return;
+        }
+        setInputMode();
+        src.read(this.buffer);
     }
 
     private void write(final byte[] b) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionInputBuffer.java Mon Nov 12 05:35:43 2007
@@ -34,6 +34,7 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 import java.nio.charset.CharacterCodingException;
 
 import org.apache.http.util.CharArrayBuffer;
@@ -59,6 +60,10 @@
     int read(ByteBuffer dst, int maxLen);
     
     int read(ByteBuffer dst);
+    
+    int read(WritableByteChannel dst, int maxLen) throws IOException;
+    
+    int read(WritableByteChannel dst) throws IOException;
     
     boolean readLine(CharArrayBuffer linebuffer, boolean endOfStream) 
         throws CharacterCodingException;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java?rev=594116&r1=594115&r2=594116&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionOutputBuffer.java Mon Nov 12 05:35:43 2007
@@ -33,6 +33,7 @@
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.CharacterCodingException;
 
@@ -54,11 +55,15 @@
     int flush(WritableByteChannel channel) 
         throws IOException;
 
-    void write(final ByteBuffer src);
+    void write(ByteBuffer src);
 
+    void write(ReadableByteChannel src) 
+        throws IOException;
+    
     void writeLine(CharArrayBuffer linebuffer) 
         throws CharacterCodingException;
     
-    void writeLine(String s) throws IOException;
+    void writeLine(String s) 
+        throws IOException;
     
 }