• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <grpcpp/impl/codegen/client_callback.h>
19 
20 #include "src/core/lib/iomgr/closure.h"
21 #include "src/core/lib/iomgr/exec_ctx.h"
22 #include "src/core/lib/iomgr/executor.h"
23 
24 namespace grpc {
25 namespace internal {
26 
InternalScheduleOnDone(grpc::Status s)27 void ClientReactor::InternalScheduleOnDone(grpc::Status s) {
28   // Unlike other uses of closure, do not Ref or Unref here since the reactor
29   // object's lifetime is controlled by user code.
30   grpc_core::ExecCtx exec_ctx;
31   struct ClosureWithArg {
32     grpc_closure closure;
33     ClientReactor* const reactor;
34     const grpc::Status status;
35     ClosureWithArg(ClientReactor* reactor_arg, grpc::Status s)
36         : reactor(reactor_arg), status(std::move(s)) {
37       GRPC_CLOSURE_INIT(
38           &closure,
39           [](void* void_arg, grpc_error*) {
40             ClosureWithArg* arg = static_cast<ClosureWithArg*>(void_arg);
41             arg->reactor->OnDone(arg->status);
42             delete arg;
43           },
44           this, grpc_schedule_on_exec_ctx);
45     }
46   };
47   ClosureWithArg* arg = new ClosureWithArg(this, std::move(s));
48   grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE);
49 }
50 
51 }  // namespace internal
52 }  // namespace grpc
53