tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1292454 - in /tomcat/trunk/java/org/apache/catalina/websocket: StreamInbound.java WsOutbound.java
Date Wed, 22 Feb 2012 19:19:49 GMT
Author: markt
Date: Wed Feb 22 19:19:48 2012
New Revision: 1292454

URL: http://svn.apache.org/viewvc?rev=1292454&view=rev
Log:
Further review of r1291507.
Pass WsInputStream instead of InputStream and use actual payload
lengths.

Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/StreamInbound.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.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=1292454&r1=1292453&r2=1292454&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:48
2012
@@ -96,12 +96,12 @@ public abstract class StreamInbound impl
         return SocketState.CLOSED;
     }
 
-    private void doClose(InputStream is) throws IOException {
+    private void doClose(WsInputStream 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). Note that
         // the 125 byte limit is enforced in #onData() before this method is
         // ever called.
-        ByteBuffer data = ByteBuffer.allocate(124);
+        ByteBuffer data = null;
 
         int status = is.read();
         if (status != -1) {
@@ -113,37 +113,45 @@ public abstract class StreamInbound impl
                 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());
+                if (is.getPayloadLength() > 2) {
+                    data = ByteBuffer.allocate((int) is.getPayloadLength() - 1);
+                    int read = 0;
+                    while (read > -1) {
+                        data.position(data.position() + read);
+                        read = is.read(data.array(), data.position(),
+                                data.remaining());
+                    }
+                    data.flip();
                 }
             }
         } else {
             status = 0;
         }
-        data.flip();
         getOutbound().close(status, data);
     }
 
-    private void doPing(InputStream is) throws IOException {
+    private void doPing(WsInputStream 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. Note that the 125 byte limit is
         // enforced in #onData() before this method is ever called.
-        ByteBuffer data = ByteBuffer.allocate(126);
+        ByteBuffer data = null;
 
-        int read = 0;
-        while (read > -1) {
-            data.position(data.position() + read);
-            read = is.read(data.array(), data.position(), data.remaining());
+        if (is.getPayloadLength() > 0) {
+            data = ByteBuffer.allocate((int) is.getPayloadLength() + 1);
+
+            int read = 0;
+            while (read > -1) {
+                data.position(data.position() + read);
+                read = is.read(data.array(), data.position(), data.remaining());
+            }
+
+            data.flip();
         }
 
-        data.flip();
         getOutbound().pong(data);
     }
 
-    private void doPong(InputStream is) throws IOException {
+    private void doPong(WsInputStream 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

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=1292454&r1=1292453&r2=1292454&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Wed Feb 22 19:19:48 2012
@@ -153,8 +153,12 @@ public class WsOutbound {
         doFlush(true);
 
         upgradeOutbound.write(0x8A);
-        upgradeOutbound.write(data.limit());
-        upgradeOutbound.write(data.array(), 0, data.limit());
+        if (data == null) {
+            upgradeOutbound.write(0);
+        } else {
+            upgradeOutbound.write(data.limit());
+            upgradeOutbound.write(data.array(), 0, data.limit());
+        }
 
         upgradeOutbound.flush();
     }



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


Mime
View raw message