From: markt Date: Mon, 24 Mar 2008 20:52:42 +0000 (+0000) Subject: Fix BZ 44620 https://issues.apache.org/bugzilla/show_bug.cgi?id=44620 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0d7aef71bffcb4f28b3ebee65c9df365c7191f09;p=tomcat7.0 Fix BZ 44620 https://issues.apache.org/bugzilla/show_bug.cgi?id=44620 Move the code that handles writing more than the output buffer can accept in a single write to the method that does the writing. This then protects all calls to addToBB() from the issue described in BZ 44620 and does not require the socket.appWriteBufSize to be >= maxHttpHeaderSize git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@640572 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java index 8539213bb..598c9a229 100644 --- a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java @@ -614,11 +614,21 @@ public class InternalNioOutputBuffer int total = 0; private synchronized void addToBB(byte[] buf, int offset, int length) throws IOException { - while (socket.getBufHandler().getWriteBuffer().remaining() < length) { - flushBuffer(); + while (length > 0) { + int thisTime = length; + if (socket.getBufHandler().getWriteBuffer().position() == + socket.getBufHandler().getWriteBuffer().capacity() + || socket.getBufHandler().getWriteBuffer().remaining()==0) { + flushBuffer(); + } + if (thisTime > socket.getBufHandler().getWriteBuffer().remaining()) { + thisTime = socket.getBufHandler().getWriteBuffer().remaining(); + } + socket.getBufHandler().getWriteBuffer().put(buf, offset, thisTime); + length = length - thisTime; + offset = offset + thisTime; + total += thisTime; } - socket.getBufHandler().getWriteBuffer().put(buf, offset, length); - total += length; NioEndpoint.KeyAttachment ka = (NioEndpoint.KeyAttachment)socket.getAttachment(false); if ( ka!= null ) ka.access();//prevent timeouts for just doing client writes } @@ -794,18 +804,7 @@ public class InternalNioOutputBuffer int len = chunk.getLength(); int start = chunk.getStart(); byte[] b = chunk.getBuffer(); - while (len > 0) { - int thisTime = len; - if (socket.getBufHandler().getWriteBuffer().position() == socket.getBufHandler().getWriteBuffer().capacity() ||socket.getBufHandler().getWriteBuffer().remaining()==0) { - flushBuffer(); - } - if (thisTime > socket.getBufHandler().getWriteBuffer().remaining()) { - thisTime = socket.getBufHandler().getWriteBuffer().remaining(); - } - addToBB(b,start,thisTime); - len = len - thisTime; - start = start + thisTime; - } + addToBB(b, start, len); return chunk.getLength(); }