Author: markt
Date: Fri Jan  9 20:53:21 2015
New Revision: 1650660

URL: http://svn.apache.org/r1650660
Log:
When doing a blocking write, write directly rather than via flush() since it is 
more efficient.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1650660&r1=1650659&r2=1650660&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Fri Jan  9 
20:53:21 2015
@@ -1113,11 +1113,29 @@ public class Nio2Endpoint extends Abstra
                 return;
 
             if (block) {
-                while (len > 0) {
-                    int thisTime = transfer(buf, off, len, socketWriteBuffer);
-                    len = len - thisTime;
-                    off = off + thisTime;
-                    flush(true);
+                try {
+                    while (len > 0) {
+                        int thisTime = transfer(buf, off, len, 
socketWriteBuffer);
+                        len = len - thisTime;
+                        off = off + thisTime;
+                        socketWriteBuffer.flip();
+                        while (socketWriteBuffer.hasRemaining()) {
+                            if 
(getSocket().write(socketWriteBuffer).get(getTimeout(), 
TimeUnit.MILLISECONDS).intValue() < 0) {
+                                throw new 
EOFException(sm.getString("iob.failedwrite"));
+                            }
+                        }
+                        socketWriteBuffer.clear();
+                    }
+                } catch (ExecutionException e) {
+                    if (e.getCause() instanceof IOException) {
+                        throw (IOException) e.getCause();
+                    } else {
+                        throw new IOException(e);
+                    }
+                } catch (InterruptedException e) {
+                    throw new IOException(e);
+                } catch (TimeoutException e) {
+                    throw new SocketTimeoutException();
                 }
             } else {
                 // FIXME: Possible new behavior:



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to