aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpcpp/impl/codegen/method_handler_impl.h
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-08-28 12:53:57 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-08-28 12:53:57 -0700
commit4b5b019d5644affef122e06c6898811286850b8d (patch)
tree73c601dc31c436e3d800a846d08b9ace7ff05235 /include/grpcpp/impl/codegen/method_handler_impl.h
parentb8f030bc0b507903e9d156fb44d161015273d0c6 (diff)
parentee65a5eaee45a765d1d4176a797bb8288faeb180 (diff)
Merge branch 'master' of https://github.com/grpc/grpc into channelz-subchannels
Diffstat (limited to 'include/grpcpp/impl/codegen/method_handler_impl.h')
-rw-r--r--include/grpcpp/impl/codegen/method_handler_impl.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/include/grpcpp/impl/codegen/method_handler_impl.h b/include/grpcpp/impl/codegen/method_handler_impl.h
index 851aa2a024..53117f941b 100644
--- a/include/grpcpp/impl/codegen/method_handler_impl.h
+++ b/include/grpcpp/impl/codegen/method_handler_impl.h
@@ -272,12 +272,14 @@ class SplitServerStreamingHandler
ServerSplitStreamer<RequestType, ResponseType>, false>(func) {}
};
-/// Handle unknown method by returning UNIMPLEMENTED error.
-class UnknownMethodHandler : public MethodHandler {
+/// General method handler class for errors that prevent real method use
+/// e.g., handle unknown method by returning UNIMPLEMENTED error.
+template <StatusCode code>
+class ErrorMethodHandler : public MethodHandler {
public:
template <class T>
static void FillOps(ServerContext* context, T* ops) {
- Status status(StatusCode::UNIMPLEMENTED, "");
+ Status status(code, "");
if (!context->sent_initial_metadata_) {
ops->SendInitialMetadata(context->initial_metadata_,
context->initial_metadata_flags());
@@ -294,9 +296,18 @@ class UnknownMethodHandler : public MethodHandler {
FillOps(param.server_context, &ops);
param.call->PerformOps(&ops);
param.call->cq()->Pluck(&ops);
+ // We also have to destroy any request payload in the handler parameter
+ ByteBuffer* payload = param.request.bbuf_ptr();
+ if (payload != nullptr) {
+ payload->Clear();
+ }
}
};
+typedef ErrorMethodHandler<StatusCode::UNIMPLEMENTED> UnknownMethodHandler;
+typedef ErrorMethodHandler<StatusCode::RESOURCE_EXHAUSTED>
+ ResourceExhaustedHandler;
+
} // namespace internal
} // namespace grpc