Optimize number of DATA frames for unary requests

Resolves #10
This commit is contained in:
Eric Anderson 2015-01-22 14:15:51 -08:00
parent 5e6078594b
commit ada32b0cb1
1 changed files with 9 additions and 1 deletions

View File

@ -238,11 +238,14 @@ public final class ChannelImpl implements Channel {
private class CallImpl<ReqT, RespT> extends Call<ReqT, RespT> {
private final MethodDescriptor<ReqT, RespT> method;
private final SerializingExecutor callExecutor;
private final boolean unaryRequest;
private ClientStream stream;
public CallImpl(MethodDescriptor<ReqT, RespT> 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 {