Author: markt
Date: Tue Feb 21 21:13:54 2012
New Revision: 1292030
URL: http://svn.apache.org/viewvc?rev=1292030&view=rev
Log:
Fix test case failure. flip Byte/Char buffers in the right places.
Rename method since it ma be writing a binary or text message.
Modified:
tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
Modified: tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java?rev=1292030&r1=1292029&r2=1292030&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java Tue Feb
21 21:13:54 2012
@@ -56,8 +56,7 @@ public abstract class MessageInbound ext
}
read = r.read(cb.array(), cb.position(), cb.remaining());
}
- cb.limit(cb.position());
- cb.position(0);
+ cb.flip();
onTextMessage(cb);
cb.clear();
}
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=1292030&r1=1292029&r2=1292030&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Tue Feb 21
21:13:54 2012
@@ -80,7 +80,7 @@ public class WsOutbound {
flush();
}
text = Boolean.FALSE;
- doWriteBinary(msgBb, true);
+ doWriteBytes(msgBb, true);
}
@@ -104,9 +104,11 @@ public class WsOutbound {
return;
}
if (text.booleanValue()) {
+ cb.flip();
doWriteText(cb, finalFragment);
} else {
- doWriteBinary(bb, finalFragment);
+ bb.flip();
+ doWriteBytes(bb, finalFragment);
}
}
@@ -157,7 +159,15 @@ public class WsOutbound {
upgradeOutbound.flush();
}
- protected void doWriteBinary(ByteBuffer buffer, boolean finalFragment)
+ /**
+ * Writes the provided bytes as the payload in a new WebSocket frame.
+ *
+ * @param buffer The bytes to include in the payload.
+ * @param finalFragment Do these bytes represent the final fragment of a
+ * WebSocket message?
+ * @throws IOException
+ */
+ protected void doWriteBytes(ByteBuffer buffer, boolean finalFragment)
throws IOException {
// Work out the first byte
@@ -216,13 +226,13 @@ public class WsOutbound {
B2CConverter.UTF_8.newEncoder().encode(buffer, bb, true);
bb.flip();
if (buffer.hasRemaining()) {
- doWriteBinary(bb, false);
+ doWriteBytes(bb, false);
} else {
- doWriteBinary(bb, finalFragment);
+ doWriteBytes(bb, finalFragment);
}
} while (buffer.hasRemaining());
- // Reset
+ // Reset - bb will be cleared in doWriteBytes()
cb.clear();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]