Author: markt
Date: Wed Feb 22 19:19:07 2012
New Revision: 1292453
URL: http://svn.apache.org/viewvc?rev=1292453&view=rev
Log:
Review of r1291507
Fix one issue and add some comments to clarify why some odd looking
things are indeed safe.
Modified:
tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
Modified: tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java?rev=1292453&r1=1292452&r2=1292453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java Wed Feb
22 19:19:07 2012
@@ -98,17 +98,27 @@ public abstract class StreamInbound impl
private void doClose(InputStream is) throws IOException {
// Control messages have a max size of 125 bytes. Need to try and read
- // one more so we reach end of stream (less 2 for the status)
+ // one more so we reach end of stream (less 2 for the status). Note
that
+ // the 125 byte limit is enforced in #onData() before this method is
+ // ever called.
ByteBuffer data = ByteBuffer.allocate(124);
int status = is.read();
if (status != -1) {
status = status << 8;
- status = status + is.read();
- int read = 0;
- while (read > -1) {
- data.position(data.position() + read);
- read = is.read(data.array(), data.position(),
data.remaining());
+ int i = is.read();
+ if (i == -1) {
+ // EOF during middle of close message. Closing anyway but set
+ // close code to protocol error
+ status = 1002;
+ } else {
+ status = status + i;
+ int read = 0;
+ while (read > -1) {
+ data.position(data.position() + read);
+ read = is.read(data.array(), data.position(),
+ data.remaining());
+ }
}
} else {
status = 0;
@@ -119,7 +129,8 @@ public abstract class StreamInbound impl
private void doPing(InputStream is) throws IOException {
// Control messages have a max size of 125 bytes. Need to try and read
- // one more so we reach end of stream
+ // one more so we reach end of stream. Note that the 125 byte limit is
+ // enforced in #onData() before this method is ever called.
ByteBuffer data = ByteBuffer.allocate(126);
int read = 0;
@@ -134,6 +145,9 @@ public abstract class StreamInbound impl
private void doPong(InputStream is) throws IOException {
// Unsolicited pong - swallow it
+ // Control messages have a max size of 125 bytes. Note that the 125
byte
+ // limit is enforced in #onData() before this method is ever called so
+ // the loop below is not unbounded.
int read = 0;
while (read > -1) {
read = is.read();
Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java?rev=1292453&r1=1292452&r2=1292453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Wed Feb
22 19:19:07 2012
@@ -21,6 +21,12 @@ import java.io.IOException;
import org.apache.catalina.util.Conversions;
import org.apache.coyote.http11.upgrade.UpgradeProcessor;
+/**
+ * This class is used to read WebSocket frames from the underlying socket and
+ * makes the payload available for reading as an {@link InputStream}. It only
+ * makes the number of bytes declared in the payload length available for
+ * reading even if more bytes are available from the socket.
+ */
public class WsInputStream extends java.io.InputStream {
private UpgradeProcessor<?> processor;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]