Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 76059 invoked from network); 12 Nov 2007 13:36:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Nov 2007 13:36:16 -0000 Received: (qmail 64064 invoked by uid 500); 12 Nov 2007 13:36:04 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 64052 invoked by uid 500); 12 Nov 2007 13:36:04 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 64043 invoked by uid 99); 12 Nov 2007 13:36:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Nov 2007 05:36:04 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Nov 2007 13:37:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 663801A9832; Mon, 12 Nov 2007 05:35:52 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r594116 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http: impl/nio/codecs/ impl/nio/reactor/ nio/reactor/ Date: Mon, 12 Nov 2007 13:35:44 -0000 To: httpcomponents-commits@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071112133552.663801A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; }