Author: markt Date: Mon Feb 20 20:33:30 2012 New Revision: 1291433 URL: http://svn.apache.org/viewvc?rev=1291433&view=rev Log: Buffers should be ready when passed in. App should call flip() as required. Need to support output of larger frames for message API.
Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java?rev=1291433&r1=1291432&r2=1291433&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original) +++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Mon Feb 20 20:33:30 2012 @@ -123,9 +123,6 @@ public class WsOutbound { protected void doWriteBinary(ByteBuffer buffer, boolean finalFragment) throws IOException { - // Prepare to write - buffer.flip(); - // Work out the first byte int first = 0x00; if (finalFragment) { @@ -141,13 +138,24 @@ public class WsOutbound { // Continuation frame is OpCode 0 upgradeOutbound.write(first); - // Note: buffer will never be more than 2^16 in length if (buffer.limit() < 126) { upgradeOutbound.write(buffer.limit()); - } else { + } else if (buffer.limit() < 65536) { upgradeOutbound.write(126); upgradeOutbound.write(buffer.limit() >>> 8); upgradeOutbound.write(buffer.limit() & 0xFF); + } else { + // Will never be more than 2^31-1 + upgradeOutbound.write(127); + upgradeOutbound.write(0); + upgradeOutbound.write(0); + upgradeOutbound.write(0); + upgradeOutbound.write(0); + upgradeOutbound.write(buffer.limit() >>> 24); + upgradeOutbound.write(buffer.limit() >>> 16); + upgradeOutbound.write(buffer.limit() >>> 8); + upgradeOutbound.write(buffer.limit() & 0xFF); + } // Write the content @@ -167,10 +175,9 @@ public class WsOutbound { protected void doWriteText(CharBuffer buffer, boolean finalFragment) throws IOException { - buffer.flip(); - do { B2CConverter.UTF_8.newEncoder().encode(buffer, bb, true); + bb.flip(); if (buffer.hasRemaining()) { doWriteBinary(bb, false); } else { Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java?rev=1291433&r1=1291432&r2=1291433&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java (original) +++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/EchoMessage.java Mon Feb 20 20:33:30 2012 @@ -38,13 +38,11 @@ public class EchoMessage extends WebSock @Override protected void onBinaryMessage(ByteBuffer message) throws IOException { - message.position(message.limit()); getOutbound().writeBinaryMessage(message); } @Override protected void onTextMessage(CharBuffer message) throws IOException { - message.position(message.limit()); getOutbound().writeTextMessage(message); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org