From ada32b0cb13efe312a8be2e9e01e7f60129b9f63 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 22 Jan 2015 14:15:51 -0800 Subject: [PATCH] Optimize number of DATA frames for unary requests Resolves #10 --- .../main/java/com/google/net/stubby/ChannelImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/net/stubby/ChannelImpl.java b/core/src/main/java/com/google/net/stubby/ChannelImpl.java index 9b5722b63a..d6a17c2cd1 100644 --- a/core/src/main/java/com/google/net/stubby/ChannelImpl.java +++ b/core/src/main/java/com/google/net/stubby/ChannelImpl.java @@ -238,11 +238,14 @@ public final class ChannelImpl implements Channel { private class CallImpl extends Call { private final MethodDescriptor method; private final SerializingExecutor callExecutor; + private final boolean unaryRequest; private ClientStream stream; public CallImpl(MethodDescriptor method, SerializingExecutor executor) { this.method = method; this.callExecutor = executor; + this.unaryRequest = method.getType() == MethodType.UNARY + || method.getType() == MethodType.SERVER_STREAMING; } @Override @@ -308,7 +311,12 @@ public final class ChannelImpl implements Channel { cancel(); } } - stream.flush(); + // For unary requests, we don't flush since we know that halfClose should be coming soon. This + // allows us to piggy-back the END_STREAM=true on the last payload frame without opening the + // possibility of broken applications forgetting to call halfClose without noticing. + if (!unaryRequest) { + stream.flush(); + } } private class ClientStreamListenerImpl implements ClientStreamListener {