Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better handling of TCP fragmentation.

  • Loading branch information...
commit bf066e019ca3aea7e84c429a900bddfa4f38fac7 1 parent 78667c5
Eric Butler authored April 05, 2012
16  src/com/codebutler/android_websockets/HybiParser.java
@@ -351,9 +351,21 @@ public HappyDataInputStream(InputStream in) {
351 351
 
352 352
         public byte[] readBytes(int length) throws IOException {
353 353
             byte[] buffer = new byte[length];
354  
-            if (read(buffer) != length) {
355  
-                throw new IOException("Read wrong number of bytes.");
  354
+
  355
+            int total = 0;
  356
+
  357
+            while (total < length) {
  358
+                int count = read(buffer, total, length - total);
  359
+                if (count == -1) {
  360
+                    break;
  361
+                }
  362
+                total += count;
356 363
             }
  364
+
  365
+            if (total != length) {
  366
+                throw new IOException(String.format("Read wrong number of bytes. Got: %s, Expected: %s.", total, length));
  367
+            }
  368
+
357 369
             return buffer;
358 370
         }
359 371
     }

0 notes on commit bf066e0

Please sign in to comment.
Something went wrong with that request. Please try again.