Author: markt
Date: Mon Mar 24 13:52:42 2008
New Revision: 640572
URL: http://svn.apache.org/viewvc?rev=640572&view=rev
Log:
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
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?rev=640572&r1=640571&r2=640572&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Mon
Mar 24 13:52:42 2008
@@ -614,11 +614,21 @@
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 @@
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();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]