From: fhanik Date: Mon, 10 Jul 2006 14:20:00 +0000 (+0000) Subject: since we are writing on a piggy back thread, better make it thread safe in case there... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=99741be24000f19e8a9ebafbcce86edbdf88f5f4;p=tomcat7.0 since we are writing on a piggy back thread, better make it thread safe in case there are multiple backend threads writing (async or comet) git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@420538 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/http11/InternalNioInputBuffer.java b/java/org/apache/coyote/http11/InternalNioInputBuffer.java index 44d102fe7..d8765c353 100644 --- a/java/org/apache/coyote/http11/InternalNioInputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioInputBuffer.java @@ -542,7 +542,7 @@ public class InternalNioInputBuffer implements InputBuffer { * Perform blocking read with a timeout if desired * @param timeout boolean - set to true if the system will time out * @return boolean - true if data was read, false is EOF is reached - * @throws IOException + * @throws IOException */ private boolean readSocket(boolean timeout) throws IOException { int nRead = 0; diff --git a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java index 3dfb331a4..265927ee8 100644 --- a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java @@ -394,25 +394,18 @@ public class InternalNioOutputBuffer if (!committed) { //Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0 ByteBuffer buf = ByteBuffer.wrap(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length); - writeToSocket(buf); + writeToSocket(buf,false); } } - private void writeToSocket(ByteBuffer bytebuffer) throws IOException { + private synchronized void writeToSocket(ByteBuffer bytebuffer, boolean flip) throws IOException { int limit = bytebuffer.position(); - bytebuffer.rewind(); - bytebuffer.limit(limit); - int remaining = limit; - while ( remaining > 0 ) { + if ( flip ) bytebuffer.flip(); + while ( bytebuffer.hasRemaining() ) { int written = socket.write(bytebuffer); - remaining -= written; } bbuf.clear(); - bbuf.rewind(); - bbuf.limit(bbufLimit); - - //System.out.println("Written:"+limit); this.total = 0; } @@ -735,7 +728,7 @@ public class InternalNioOutputBuffer //write to the socket, if there is anything to write if (bbuf.position() > 0) { - writeToSocket(bbuf); + writeToSocket(bbuf,true); } }