server_callback.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2019 gRPC authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include <grpcpp/impl/codegen/server_callback_impl.h>
  18. #include "src/core/lib/iomgr/closure.h"
  19. #include "src/core/lib/iomgr/exec_ctx.h"
  20. #include "src/core/lib/iomgr/executor.h"
  21. namespace grpc_impl {
  22. namespace internal {
  23. void ServerCallbackCall::CallOnCancel(ServerReactor* reactor) {
  24. if (reactor->InternalInlineable()) {
  25. reactor->OnCancel();
  26. } else {
  27. Ref();
  28. grpc_core::ExecCtx exec_ctx;
  29. struct ClosureArg {
  30. ServerCallbackCall* call;
  31. ServerReactor* reactor;
  32. };
  33. ClosureArg* arg = new ClosureArg{this, reactor};
  34. grpc_core::Executor::Run(GRPC_CLOSURE_CREATE(
  35. [](void* void_arg, grpc_error*) {
  36. ClosureArg* arg =
  37. static_cast<ClosureArg*>(void_arg);
  38. arg->reactor->OnCancel();
  39. arg->call->MaybeDone();
  40. delete arg;
  41. },
  42. arg, nullptr),
  43. GRPC_ERROR_NONE);
  44. }
  45. }
  46. } // namespace internal
  47. } // namespace grpc_impl