Author: remm Date: Fri Apr 18 22:30:31 2014 New Revision: 1588583 URL: http://svn.apache.org/r1588583 Log: Minor flush tweaks.
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java?rev=1588583&r1=1588582&r2=1588583&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java Fri Apr 18 22:30:31 2014 @@ -378,43 +378,35 @@ public class InternalNio2OutputBuffer ex // Ignore timeout } } - if (hasMoreDataToFlush()) { - try { - if (!flipped) { - byteBuffer.flip(); - flipped = true; - } - if (bufferedWrites.size() > 0) { - for (ByteBuffer buffer : bufferedWrites) { - buffer.flip(); - while (buffer.hasRemaining()) { - if (socket.getSocket().write(buffer).get(socket.getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) { - throw new EOFException(sm.getString("iob.failedwrite")); - } + try { + if (bufferedWrites.size() > 0) { + for (ByteBuffer buffer : bufferedWrites) { + buffer.flip(); + while (buffer.hasRemaining()) { + if (socket.getSocket().write(buffer).get(socket.getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) { + throw new EOFException(sm.getString("iob.failedwrite")); } } - bufferedWrites.clear(); - } - while (byteBuffer.hasRemaining()) { - if (socket.getSocket().write(byteBuffer).get(socket.getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) { - throw new EOFException(sm.getString("iob.failedwrite")); - } } - } catch (InterruptedException | ExecutionException e) { - throw new IOException(e); - } catch (TimeoutException e) { - throw new SocketTimeoutException(); + bufferedWrites.clear(); } - if (byteBuffer.remaining() == 0) { - //blocking writes must empty the buffer - //and if remaining==0 then we did empty it - byteBuffer.clear(); - flipped = false; + if (!flipped) { + byteBuffer.flip(); + flipped = true; } - } else { - byteBuffer.clear(); - flipped = false; + while (byteBuffer.hasRemaining()) { + if (socket.getSocket().write(byteBuffer).get(socket.getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) { + throw new EOFException(sm.getString("iob.failedwrite")); + } + } + } catch (InterruptedException | ExecutionException e) { + throw new IOException(e); + } catch (TimeoutException e) { + throw new SocketTimeoutException(); } + byteBuffer.clear(); + flipped = false; + return false; } else { synchronized (completionHandler) { if (hasPermit || writePending.tryAcquire()) { @@ -455,9 +447,9 @@ public class InternalNio2OutputBuffer ex } } } + return hasMoreDataToFlush() || hasBufferedData() || e != null; } } - return hasMoreDataToFlush(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org