Skip to content

Commit ada32b0

Browse files
committed
Optimize number of DATA frames for unary requests
Resolves #10
1 parent 5e60785 commit ada32b0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/src/main/java/com/google/net/stubby/ChannelImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,14 @@ public void running() {}
238238
private class CallImpl<ReqT, RespT> extends Call<ReqT, RespT> {
239239
private final MethodDescriptor<ReqT, RespT> method;
240240
private final SerializingExecutor callExecutor;
241+
private final boolean unaryRequest;
241242
private ClientStream stream;
242243

243244
public CallImpl(MethodDescriptor<ReqT, RespT> method, SerializingExecutor executor) {
244245
this.method = method;
245246
this.callExecutor = executor;
247+
this.unaryRequest = method.getType() == MethodType.UNARY
248+
|| method.getType() == MethodType.SERVER_STREAMING;
246249
}
247250

248251
@Override
@@ -308,7 +311,12 @@ public void sendPayload(ReqT payload) {
308311
cancel();
309312
}
310313
}
311-
stream.flush();
314+
// For unary requests, we don't flush since we know that halfClose should be coming soon. This
315+
// allows us to piggy-back the END_STREAM=true on the last payload frame without opening the
316+
// possibility of broken applications forgetting to call halfClose without noticing.
317+
if (!unaryRequest) {
318+
stream.flush();
319+
}
312320
}
313321

314322
private class ClientStreamListenerImpl implements ClientStreamListener {

0 commit comments

Comments
 (0)