Deframer.deframe returns number of unprocessed bytes.
This is intended to reduce the flakiness of test_TestServiceBenchmarks.
TAP showed some flaky runs where HttpStreamDeframer threw the exception
"GRPC stream not correctly aligned".
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=69166650
diff --git a/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java b/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java
index e793aad..cc88173 100644
--- a/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java
+++ b/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java
@@ -22,15 +22,17 @@
/**
* Deframing a single input stream that contains multiple GRPC frames
+ *
+ * @return the number of unconsumed bytes remaining in the buffer
*/
@Override
public int deframe(InputStream frame, Operation target) {
try {
- int read = 0;
- while (frame.available() > 0) {
- read += super.deframe(frame, target);
- }
- return read;
+ int remaining;
+ do {
+ remaining = super.deframe(frame, target);
+ } while (frame.available() > 0);
+ return remaining;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}