• 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 <utility>
19 
20 #include "absl/status/status.h"
21 
22 #include <grpc/grpc.h>
23 #include <grpcpp/support/client_callback.h>
24 #include <grpcpp/support/status.h>
25 
26 #include "src/core/lib/iomgr/closure.h"
27 #include "src/core/lib/iomgr/error.h"
28 #include "src/core/lib/iomgr/exec_ctx.h"
29 #include "src/core/lib/iomgr/executor.h"
30 #include "src/core/lib/surface/call.h"
31 
32 namespace grpc {
33 namespace internal {
34 
InternalScheduleOnDone(grpc::Status s)35 void ClientReactor::InternalScheduleOnDone(grpc::Status s) {
36   // Unlike other uses of closure, do not Ref or Unref here since the reactor
37   // object's lifetime is controlled by user code.
38   grpc_core::ExecCtx exec_ctx;
39   struct ClosureWithArg {
40     grpc_closure closure;
41     ClientReactor* const reactor;
42     const grpc::Status status;
43     ClosureWithArg(ClientReactor* reactor_arg, grpc::Status s)
44         : reactor(reactor_arg), status(std::move(s)) {
45       GRPC_CLOSURE_INIT(
46           &closure,
47           [](void* void_arg, grpc_error_handle) {
48             ClosureWithArg* arg = static_cast<ClosureWithArg*>(void_arg);
49             arg->reactor->OnDone(arg->status);
50             delete arg;
51           },
52           this, grpc_schedule_on_exec_ctx);
53     }
54   };
55   ClosureWithArg* arg = new ClosureWithArg(this, std::move(s));
56   grpc_core::Executor::Run(&arg->closure, absl::OkStatus());
57 }
58 
InternalTrailersOnly(const grpc_call * call) const59 bool ClientReactor::InternalTrailersOnly(const grpc_call* call) const {
60   return grpc_call_is_trailers_only(call);
61 }
62 
63 }  // namespace internal
64 }  // namespace grpc
65