Skip to content

Commit

Permalink
Optimize number of DATA frames for unary requests
Browse files Browse the repository at this point in the history
Resolves #10
  • Loading branch information
ejona86 committed Jan 23, 2015
1 parent 5e60785 commit ada32b0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/src/main/java/com/google/net/stubby/ChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ public void running() {}
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
Expand Down Expand Up @@ -308,7 +311,12 @@ public void sendPayload(ReqT payload) {
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 {
Expand Down

0 comments on commit ada32b0

Please sign in to comment.