Author: markt Date: Mon Sep 4 16:35:21 2017 New Revision: 1807251 URL: http://svn.apache.org/viewvc?rev=1807251&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60523 Reduce the number of packets used to send WebSocket messages by not flushing between the header and the payload when the two are written together.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java?rev=1807251&r1=1807250&r2=1807251&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java Mon Sep 4 16:35:21 2017 @@ -74,29 +74,29 @@ public class WsRemoteEndpointImplServer onWritePossible(true); } else { // Blocking - for (ByteBuffer buffer : buffers) { - long timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis(); - if (timeout <= 0) { - SendResult sr = new SendResult(new SocketTimeoutException()); - handler.onResult(sr); - return; - } - socketWrapper.setWriteTimeout(timeout); - try { - socketWrapper.write(true, buffer); - timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis(); + try { + for (ByteBuffer buffer : buffers) { + long timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis(); if (timeout <= 0) { SendResult sr = new SendResult(new SocketTimeoutException()); handler.onResult(sr); return; } socketWrapper.setWriteTimeout(timeout); - socketWrapper.flush(true); - handler.onResult(SENDRESULT_OK); - } catch (IOException e) { - SendResult sr = new SendResult(e); + socketWrapper.write(true, buffer); + } + long timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis(); + if (timeout <= 0) { + SendResult sr = new SendResult(new SocketTimeoutException()); handler.onResult(sr); + return; } + socketWrapper.setWriteTimeout(timeout); + socketWrapper.flush(true); + handler.onResult(SENDRESULT_OK); + } catch (IOException e) { + SendResult sr = new SendResult(e); + handler.onResult(sr); } } } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1807251&r1=1807250&r2=1807251&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Sep 4 16:35:21 2017 @@ -167,6 +167,15 @@ </fix> </changelog> </subsection> + <subsection name="WebSocket"> + <changelog> + <fix> + <bug>60523</bug>: Reduce the number of packets used to send WebSocket + messages by not flushing between the header and the payload when the + two are written together. (markt) + </fix> + </changelog> + </subsection> <subsection name="Web applications"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org