blob: f121b481c5bc2937305016c50eb0d67133e5c70d [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
Craig Tiller6169d5f2016-03-31 07:46:18 -07002 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33#include <grpc++/server.h>
yang-g9e2f90c2015-08-21 15:35:03 -070034
Yuchen Zenga42ec212016-04-29 13:03:06 -070035#include <sstream>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036#include <utility>
37
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038#include <grpc++/completion_queue.h>
yang-g9e2f90c2015-08-21 15:35:03 -070039#include <grpc++/generic/async_generic_service.h>
yang-g50993b72016-12-29 10:00:27 -080040#include <grpc++/impl/codegen/async_unary_call.h>
David Garcia Quintase1300de2016-01-27 18:41:26 -080041#include <grpc++/impl/codegen/completion_queue_tag.h>
42#include <grpc++/impl/grpc_library.h>
Craig Tiller15f383c2016-01-07 12:45:32 -080043#include <grpc++/impl/method_handler_impl.h>
yangg1b151092015-01-09 15:31:05 -080044#include <grpc++/impl/rpc_service_method.h>
Yuchen Zenga42ec212016-04-29 13:03:06 -070045#include <grpc++/impl/server_initializer.h>
Craig Tiller8c8d0aa2015-02-12 11:38:36 -080046#include <grpc++/impl/service_type.h>
Julien Boeuf5be92a32015-08-28 16:28:18 -070047#include <grpc++/security/server_credentials.h>
David Garcia Quintase1300de2016-01-27 18:41:26 -080048#include <grpc++/server_context.h>
yang-g9e2f90c2015-08-21 15:35:03 -070049#include <grpc++/support/time.h>
David Garcia Quintase1300de2016-01-27 18:41:26 -080050#include <grpc/grpc.h>
51#include <grpc/support/alloc.h>
52#include <grpc/support/log.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080053
Craig Tiller9533d042016-03-25 17:11:06 -070054#include "src/core/lib/profiling/timers.h"
yang-gc3c475f2016-12-27 10:37:26 -080055#include "src/cpp/server/health/default_health_check_service.h"
Sree Kuchibhotlaf72ec6b2016-10-24 11:09:43 -070056#include "src/cpp/thread_manager/thread_manager.h"
Craig Tillerc4165772015-02-11 10:51:04 -080057
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080058namespace grpc {
59
Vijay Paic0b2acb2016-11-01 16:31:56 -070060class DefaultGlobalCallbacks final : public Server::GlobalCallbacks {
Craig Tiller7221d992015-11-24 06:59:33 -080061 public:
Vijay Paic0b2acb2016-11-01 16:31:56 -070062 ~DefaultGlobalCallbacks() override {}
63 void PreSynchronousRequest(ServerContext* context) override {}
64 void PostSynchronousRequest(ServerContext* context) override {}
Craig Tiller7221d992015-11-24 06:59:33 -080065};
66
Craig Tiller64616492016-01-26 14:16:20 -080067static std::shared_ptr<Server::GlobalCallbacks> g_callbacks = nullptr;
Craig Tiller8352b9e2015-12-02 11:43:40 -080068static gpr_once g_once_init_callbacks = GPR_ONCE_INIT;
69
Craig Tiller8352b9e2015-12-02 11:43:40 -080070static void InitGlobalCallbacks() {
Vijay Paib645a2d2016-06-09 18:39:06 -070071 if (!g_callbacks) {
Craig Tiller64616492016-01-26 14:16:20 -080072 g_callbacks.reset(new DefaultGlobalCallbacks());
Craig Tiller8352b9e2015-12-02 11:43:40 -080073 }
74}
Craig Tiller7221d992015-11-24 06:59:33 -080075
Craig Tiller8f7bff72015-08-17 13:23:14 -070076class Server::UnimplementedAsyncRequestContext {
77 protected:
78 UnimplementedAsyncRequestContext() : generic_stream_(&server_context_) {}
79
80 GenericServerContext server_context_;
81 GenericServerAsyncReaderWriter generic_stream_;
82};
83
Vijay Paic0b2acb2016-11-01 16:31:56 -070084class Server::UnimplementedAsyncRequest final
Craig Tiller8f7bff72015-08-17 13:23:14 -070085 : public UnimplementedAsyncRequestContext,
86 public GenericAsyncRequest {
87 public:
88 UnimplementedAsyncRequest(Server* server, ServerCompletionQueue* cq)
89 : GenericAsyncRequest(server, &server_context_, &generic_stream_, cq, cq,
90 NULL, false),
91 server_(server),
92 cq_(cq) {}
93
Vijay Paic0b2acb2016-11-01 16:31:56 -070094 bool FinalizeResult(void** tag, bool* status) override;
Craig Tiller8f7bff72015-08-17 13:23:14 -070095
96 ServerContext* context() { return &server_context_; }
97 GenericServerAsyncReaderWriter* stream() { return &generic_stream_; }
98
99 private:
100 Server* const server_;
101 ServerCompletionQueue* const cq_;
102};
103
104typedef SneakyCallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus>
105 UnimplementedAsyncResponseOp;
Vijay Paic0b2acb2016-11-01 16:31:56 -0700106class Server::UnimplementedAsyncResponse final
Craig Tiller8f7bff72015-08-17 13:23:14 -0700107 : public UnimplementedAsyncResponseOp {
108 public:
109 UnimplementedAsyncResponse(UnimplementedAsyncRequest* request);
110 ~UnimplementedAsyncResponse() { delete request_; }
111
Vijay Paic0b2acb2016-11-01 16:31:56 -0700112 bool FinalizeResult(void** tag, bool* status) override {
Craig Tiller8f7bff72015-08-17 13:23:14 -0700113 bool r = UnimplementedAsyncResponseOp::FinalizeResult(tag, status);
114 delete this;
115 return r;
116 }
117
118 private:
119 UnimplementedAsyncRequest* const request_;
120};
121
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -0700122class ShutdownTag : public CompletionQueueTag {
123 public:
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700124 bool FinalizeResult(void** tag, bool* status) { return false; }
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -0700125};
126
Sree Kuchibhotla982a6f22017-03-03 02:19:31 -0800127class DummyTag : public CompletionQueueTag {
128 public:
129 bool FinalizeResult(void** tag, bool* status) {
130 *status = true;
131 return true;
132 }
133};
134
Vijay Paic0b2acb2016-11-01 16:31:56 -0700135class Server::SyncRequest final : public CompletionQueueTag {
Craig Tillerc4165772015-02-11 10:51:04 -0800136 public:
Craig Tiller1c9a2a92015-02-12 14:10:25 -0800137 SyncRequest(RpcServiceMethod* method, void* tag)
Craig Tillerc4165772015-02-11 10:51:04 -0800138 : method_(method),
139 tag_(tag),
Craig Tillercf133f42015-02-26 14:05:56 -0800140 in_flight_(false),
Craig Tillerc4165772015-02-11 10:51:04 -0800141 has_request_payload_(method->method_type() == RpcMethod::NORMAL_RPC ||
142 method->method_type() ==
143 RpcMethod::SERVER_STREAMING),
yang-g9b7757d2015-08-13 11:15:53 -0700144 call_details_(nullptr),
Vijay Paiced73bd2015-06-17 10:23:28 -0700145 cq_(nullptr) {
Craig Tillerc4165772015-02-11 10:51:04 -0800146 grpc_metadata_array_init(&request_metadata_);
147 }
148
yang-g9b7757d2015-08-13 11:15:53 -0700149 ~SyncRequest() {
150 if (call_details_) {
151 delete call_details_;
152 }
153 grpc_metadata_array_destroy(&request_metadata_);
154 }
Yang Gao7b49a772015-05-28 14:07:54 -0700155
Sree Kuchibhotlaf2c32152017-03-22 03:01:24 -0700156 void SetupRequest() { cq_ = grpc_completion_queue_create_for_pluck(nullptr); }
Vijay Paiced73bd2015-06-17 10:23:28 -0700157
158 void TeardownRequest() {
159 grpc_completion_queue_destroy(cq_);
160 cq_ = nullptr;
161 }
162
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700163 void Request(grpc_server* server, grpc_completion_queue* notify_cq) {
Vijay Paiced73bd2015-06-17 10:23:28 -0700164 GPR_ASSERT(cq_ && !in_flight_);
Craig Tillerc4165772015-02-11 10:51:04 -0800165 in_flight_ = true;
yang-g9b7757d2015-08-13 11:15:53 -0700166 if (tag_) {
167 GPR_ASSERT(GRPC_CALL_OK ==
168 grpc_server_request_registered_call(
169 server, tag_, &call_, &deadline_, &request_metadata_,
170 has_request_payload_ ? &request_payload_ : nullptr, cq_,
171 notify_cq, this));
172 } else {
173 if (!call_details_) {
174 call_details_ = new grpc_call_details;
175 grpc_call_details_init(call_details_);
176 }
177 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
178 server, &call_, call_details_,
179 &request_metadata_, cq_, notify_cq, this));
180 }
Craig Tillerc4165772015-02-11 10:51:04 -0800181 }
182
Vijay Paic0b2acb2016-11-01 16:31:56 -0700183 bool FinalizeResult(void** tag, bool* status) override {
Craig Tillerec3257c2015-02-12 15:59:43 -0800184 if (!*status) {
185 grpc_completion_queue_destroy(cq_);
186 }
yang-g9b7757d2015-08-13 11:15:53 -0700187 if (call_details_) {
188 deadline_ = call_details_->deadline;
189 grpc_call_details_destroy(call_details_);
190 grpc_call_details_init(call_details_);
191 }
Craig Tiller645466e2015-02-18 09:18:33 -0800192 return true;
Craig Tillerec3257c2015-02-12 15:59:43 -0800193 }
Craig Tillerc4165772015-02-11 10:51:04 -0800194
Vijay Paic0b2acb2016-11-01 16:31:56 -0700195 class CallData final {
Craig Tillerc4165772015-02-11 10:51:04 -0800196 public:
Craig Tiller1c9a2a92015-02-12 14:10:25 -0800197 explicit CallData(Server* server, SyncRequest* mrd)
Craig Tillerc4165772015-02-11 10:51:04 -0800198 : cq_(mrd->cq_),
yang-gf07ed452017-02-16 23:01:28 -0800199 call_(mrd->call_, server, &cq_, server->max_receive_message_size()),
yang-gc42d8442017-02-15 00:05:00 -0800200 ctx_(mrd->deadline_, &mrd->request_metadata_),
Craig Tillerc4165772015-02-11 10:51:04 -0800201 has_request_payload_(mrd->has_request_payload_),
Craig Tillerc4165772015-02-11 10:51:04 -0800202 request_payload_(mrd->request_payload_),
203 method_(mrd->method_) {
yang-g85c04f92015-07-07 17:47:31 -0700204 ctx_.set_call(mrd->call_);
Yang Gao1205f6f2015-03-22 15:18:14 -0700205 ctx_.cq_ = &cq_;
Craig Tillerc4165772015-02-11 10:51:04 -0800206 GPR_ASSERT(mrd->in_flight_);
207 mrd->in_flight_ = false;
208 mrd->request_metadata_.count = 0;
209 }
210
Craig Tillerec3257c2015-02-12 15:59:43 -0800211 ~CallData() {
212 if (has_request_payload_ && request_payload_) {
213 grpc_byte_buffer_destroy(request_payload_);
214 }
215 }
216
Craig Tiller64616492016-01-26 14:16:20 -0800217 void Run(std::shared_ptr<GlobalCallbacks> global_callbacks) {
Craig Tiller492968f2015-02-18 13:14:03 -0800218 ctx_.BeginCompletionOp(&call_);
Craig Tiller64616492016-01-26 14:16:20 -0800219 global_callbacks->PreSynchronousRequest(&ctx_);
Craig Tiller62f28bf2017-01-19 10:05:13 -0800220 method_->handler()->RunHandler(
221 MethodHandler::HandlerParameter(&call_, &ctx_, request_payload_));
Craig Tiller64616492016-01-26 14:16:20 -0800222 global_callbacks->PostSynchronousRequest(&ctx_);
Craig Tiller928ec8e2015-06-05 08:45:45 -0700223 request_payload_ = nullptr;
Sree Kuchibhotlafa71f6f2017-04-01 17:32:34 -0700224
Craig Tiller492968f2015-02-18 13:14:03 -0800225 cq_.Shutdown();
Sree Kuchibhotlafa71f6f2017-04-01 17:32:34 -0700226
227 CompletionQueueTag* op_tag = ctx_.GetCompletionOpTag();
228 cq_.TryPluck(op_tag, gpr_inf_future(GPR_CLOCK_REALTIME));
229
Sree Kuchibhotla44268002017-04-01 17:33:50 -0700230 /* Ensure the cq_ is shutdown */
Sree Kuchibhotlafa71f6f2017-04-01 17:32:34 -0700231 DummyTag ignored_tag;
Sree Kuchibhotla982a6f22017-03-03 02:19:31 -0800232 GPR_ASSERT(cq_.Pluck(&ignored_tag) == false);
Craig Tillerc4165772015-02-11 10:51:04 -0800233 }
234
235 private:
236 CompletionQueue cq_;
237 Call call_;
238 ServerContext ctx_;
239 const bool has_request_payload_;
Craig Tiller8c8d0aa2015-02-12 11:38:36 -0800240 grpc_byte_buffer* request_payload_;
241 RpcServiceMethod* const method_;
Craig Tillerc4165772015-02-11 10:51:04 -0800242 };
243
244 private:
Craig Tiller8c8d0aa2015-02-12 11:38:36 -0800245 RpcServiceMethod* const method_;
246 void* const tag_;
Craig Tillercf133f42015-02-26 14:05:56 -0800247 bool in_flight_;
Craig Tillerc4165772015-02-11 10:51:04 -0800248 const bool has_request_payload_;
Craig Tiller8c8d0aa2015-02-12 11:38:36 -0800249 grpc_call* call_;
yang-g9b7757d2015-08-13 11:15:53 -0700250 grpc_call_details* call_details_;
Craig Tillerc4165772015-02-11 10:51:04 -0800251 gpr_timespec deadline_;
252 grpc_metadata_array request_metadata_;
Craig Tiller8c8d0aa2015-02-12 11:38:36 -0800253 grpc_byte_buffer* request_payload_;
254 grpc_completion_queue* cq_;
Craig Tillerc4165772015-02-11 10:51:04 -0800255};
256
Sree Kuchibhotla8f7739b2016-10-13 15:12:55 -0700257// Implementation of ThreadManager. Each instance of SyncRequestThreadManager
258// manages a pool of threads that poll for incoming Sync RPCs and call the
259// appropriate RPC handlers
260class Server::SyncRequestThreadManager : public ThreadManager {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700261 public:
Sree Kuchibhotla8f7739b2016-10-13 15:12:55 -0700262 SyncRequestThreadManager(Server* server, CompletionQueue* server_cq,
263 std::shared_ptr<GlobalCallbacks> global_callbacks,
264 int min_pollers, int max_pollers,
265 int cq_timeout_msec)
266 : ThreadManager(min_pollers, max_pollers),
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700267 server_(server),
268 server_cq_(server_cq),
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700269 cq_timeout_msec_(cq_timeout_msec),
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700270 global_callbacks_(global_callbacks) {}
271
Vijay Paic0b2acb2016-11-01 16:31:56 -0700272 WorkStatus PollForWork(void** tag, bool* ok) override {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700273 *tag = nullptr;
274 gpr_timespec deadline =
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700275 gpr_time_from_millis(cq_timeout_msec_, GPR_TIMESPAN);
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700276
277 switch (server_cq_->AsyncNext(tag, ok, deadline)) {
278 case CompletionQueue::TIMEOUT:
279 return TIMEOUT;
280 case CompletionQueue::SHUTDOWN:
281 return SHUTDOWN;
282 case CompletionQueue::GOT_EVENT:
283 return WORK_FOUND;
284 }
285
286 GPR_UNREACHABLE_CODE(return TIMEOUT);
287 }
288
Vijay Paic0b2acb2016-11-01 16:31:56 -0700289 void DoWork(void* tag, bool ok) override {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700290 SyncRequest* sync_req = static_cast<SyncRequest*>(tag);
Sree Kuchibhotla4306eee2016-09-21 09:56:29 -0700291
292 if (!sync_req) {
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700293 // No tag. Nothing to work on. This is an unlikley scenario and possibly a
294 // bug in RPC Manager implementation.
295 gpr_log(GPR_ERROR, "Sync server. DoWork() was called with NULL tag");
Sree Kuchibhotla4306eee2016-09-21 09:56:29 -0700296 return;
297 }
298
299 if (ok) {
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700300 // Calldata takes ownership of the completion queue inside sync_req
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700301 SyncRequest::CallData cd(server_, sync_req);
302 {
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700303 // Prepare for the next request
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700304 if (!IsShutdown()) {
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700305 sync_req->SetupRequest(); // Create new completion queue for sync_req
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700306 sync_req->Request(server_->c_server(), server_cq_->cq());
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700307 }
308 }
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700309
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700310 GPR_TIMER_SCOPE("cd.Run()", 0);
311 cd.Run(global_callbacks_);
312 }
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700313 // TODO (sreek) If ok is false here (which it isn't in case of
314 // grpc_request_registered_call), we should still re-queue the request
315 // object
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700316 }
317
318 void AddSyncMethod(RpcServiceMethod* method, void* tag) {
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700319 sync_requests_.emplace_back(new SyncRequest(method, tag));
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700320 }
321
322 void AddUnknownSyncMethod() {
Sree Kuchibhotlada069a52016-10-19 11:22:29 -0700323 if (!sync_requests_.empty()) {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700324 unknown_method_.reset(new RpcServiceMethod(
325 "unknown", RpcMethod::BIDI_STREAMING, new UnknownMethodHandler));
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700326 sync_requests_.emplace_back(
327 new SyncRequest(unknown_method_.get(), nullptr));
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700328 }
329 }
330
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700331 void ShutdownAndDrainCompletionQueue() {
332 server_cq_->Shutdown();
333
334 // Drain any pending items from the queue
335 void* tag;
336 bool ok;
337 while (server_cq_->Next(&tag, &ok)) {
338 // Nothing to be done here
339 }
340 }
341
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700342 void Start() {
Sree Kuchibhotlada069a52016-10-19 11:22:29 -0700343 if (!sync_requests_.empty()) {
344 for (auto m = sync_requests_.begin(); m != sync_requests_.end(); m++) {
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700345 (*m)->SetupRequest();
346 (*m)->Request(server_->c_server(), server_cq_->cq());
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700347 }
348
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700349 Initialize(); // ThreadManager's Initialize()
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700350 }
351 }
352
353 private:
354 Server* server_;
355 CompletionQueue* server_cq_;
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700356 int cq_timeout_msec_;
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700357 std::vector<std::unique_ptr<SyncRequest>> sync_requests_;
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700358 std::unique_ptr<RpcServiceMethod> unknown_method_;
yang-g8d668d82016-12-01 15:09:28 -0800359 std::unique_ptr<RpcServiceMethod> health_check_;
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700360 std::shared_ptr<Server::GlobalCallbacks> global_callbacks_;
361};
362
David Garcia Quintasd79ef3a2016-01-28 00:21:27 -0800363static internal::GrpcLibraryInitializer g_gli_initializer;
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700364Server::Server(
Sree Kuchibhotlae4eb51f2016-10-18 11:51:28 -0700365 int max_receive_message_size, ChannelArguments* args,
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -0700366 std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue>>>
367 sync_server_cqs,
Sree Kuchibhotlae4eb51f2016-10-18 11:51:28 -0700368 int min_pollers, int max_pollers, int sync_cq_timeout_msec)
Mark D. Roth69803622016-09-06 08:15:36 -0700369 : max_receive_message_size_(max_receive_message_size),
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700370 sync_server_cqs_(sync_server_cqs),
Yang Gao3921c562015-04-30 16:07:06 -0700371 started_(false),
vjpaicad5f0a2015-02-18 22:02:52 -0800372 shutdown_(false),
yang-g6ec11f22016-07-14 14:53:35 -0700373 shutdown_notified_(false),
yang-g9b7757d2015-08-13 11:15:53 -0700374 has_generic_service_(false),
yang-geb62c942016-02-17 15:37:25 -0800375 server_(nullptr),
yang-gad327642016-12-12 14:32:09 -0800376 server_initializer_(new ServerInitializer(this)),
377 health_check_service_disabled_(false) {
David Garcia Quintasd79ef3a2016-01-28 00:21:27 -0800378 g_gli_initializer.summon();
Craig Tiller8352b9e2015-12-02 11:43:40 -0800379 gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
Craig Tiller64616492016-01-26 14:16:20 -0800380 global_callbacks_ = g_callbacks;
yang-geb62c942016-02-17 15:37:25 -0800381 global_callbacks_->UpdateArguments(args);
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700382
383 for (auto it = sync_server_cqs_->begin(); it != sync_server_cqs_->end();
384 it++) {
Sree Kuchibhotla8f7739b2016-10-13 15:12:55 -0700385 sync_req_mgrs_.emplace_back(new SyncRequestThreadManager(
386 this, (*it).get(), global_callbacks_, min_pollers, max_pollers,
387 sync_cq_timeout_msec));
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700388 }
389
yang-geb62c942016-02-17 15:37:25 -0800390 grpc_channel_args channel_args;
391 args->SetChannelArgs(&channel_args);
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700392
yang-g8d668d82016-12-01 15:09:28 -0800393 for (size_t i = 0; i < channel_args.num_args; i++) {
yang-gb90631d2016-12-29 14:08:13 -0800394 if (0 ==
395 strcmp(channel_args.args[i].key, kHealthCheckServiceInterfaceArg)) {
yang-g6d0fbfa2016-12-06 16:49:04 -0800396 if (channel_args.args[i].value.pointer.p == nullptr) {
yang-gad327642016-12-12 14:32:09 -0800397 health_check_service_disabled_ = true;
yang-g8d668d82016-12-01 15:09:28 -0800398 } else {
yang-g6d0fbfa2016-12-06 16:49:04 -0800399 health_check_service_.reset(static_cast<HealthCheckServiceInterface*>(
400 channel_args.args[i].value.pointer.p));
yang-g8d668d82016-12-01 15:09:28 -0800401 }
402 break;
403 }
404 }
405
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700406 server_ = grpc_server_create(&channel_args, nullptr);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700407}
vjpaicad5f0a2015-02-18 22:02:52 -0800408
409Server::~Server() {
Ruyi Wangb486ba62015-03-14 22:19:44 +0800410 {
Vijay Pai320ed132016-11-01 17:16:55 -0700411 std::unique_lock<std::mutex> lock(mu_);
Ruyi Wangb486ba62015-03-14 22:19:44 +0800412 if (started_ && !shutdown_) {
413 lock.unlock();
414 Shutdown();
yang-gb9711732016-01-15 16:53:08 -0800415 } else if (!started_) {
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700416 // Shutdown the completion queues
417 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
418 (*it)->ShutdownAndDrainCompletionQueue();
Sree Kuchibhotla4306eee2016-09-21 09:56:29 -0700419 }
Ruyi Wangb486ba62015-03-14 22:19:44 +0800420 }
vjpaicad5f0a2015-02-18 22:02:52 -0800421 }
Sree Kuchibhotlabb5519f2016-07-19 11:00:39 -0700422
vjpaicad5f0a2015-02-18 22:02:52 -0800423 grpc_server_destroy(server_);
vjpaicad5f0a2015-02-18 22:02:52 -0800424}
425
Craig Tiller7221d992015-11-24 06:59:33 -0800426void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) {
Vijay Paib645a2d2016-06-09 18:39:06 -0700427 GPR_ASSERT(!g_callbacks);
428 GPR_ASSERT(callbacks);
Craig Tiller64616492016-01-26 14:16:20 -0800429 g_callbacks.reset(callbacks);
Craig Tiller7221d992015-11-24 06:59:33 -0800430}
431
Adam Michalik4ad746e2016-06-07 15:02:59 -0700432grpc_server* Server::c_server() { return server_; }
Adam Michalikb97e2d12016-06-02 12:12:55 -0700433
Craig Tiller06cb1a92016-04-04 08:10:47 -0700434static grpc_server_register_method_payload_handling PayloadHandlingForMethod(
435 RpcServiceMethod* method) {
436 switch (method->method_type()) {
437 case RpcMethod::NORMAL_RPC:
438 case RpcMethod::SERVER_STREAMING:
439 return GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER;
440 case RpcMethod::CLIENT_STREAMING:
441 case RpcMethod::BIDI_STREAMING:
442 return GRPC_SRM_PAYLOAD_NONE;
443 }
444 GPR_UNREACHABLE_CODE(return GRPC_SRM_PAYLOAD_NONE;);
445}
446
Craig Tiller15f383c2016-01-07 12:45:32 -0800447bool Server::RegisterService(const grpc::string* host, Service* service) {
448 bool has_async_methods = service->has_async_methods();
449 if (has_async_methods) {
450 GPR_ASSERT(service->server_ == nullptr &&
451 "Can only register an asynchronous service against one server.");
452 service->server_ = this;
453 }
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700454
Yuchen Zenga42ec212016-04-29 13:03:06 -0700455 const char* method_name = nullptr;
Craig Tiller15f383c2016-01-07 12:45:32 -0800456 for (auto it = service->methods_.begin(); it != service->methods_.end();
457 ++it) {
yang-g269b8be2016-01-15 10:46:26 -0800458 if (it->get() == nullptr) { // Handled by generic service if any.
459 continue;
460 }
Sree Kuchibhotlada069a52016-10-19 11:22:29 -0700461
Craig Tiller15f383c2016-01-07 12:45:32 -0800462 RpcServiceMethod* method = it->get();
Craig Tiller06cb1a92016-04-04 08:10:47 -0700463 void* tag = grpc_server_register_method(
464 server_, method->name(), host ? host->c_str() : nullptr,
465 PayloadHandlingForMethod(method), 0);
Craig Tiller15f383c2016-01-07 12:45:32 -0800466 if (tag == nullptr) {
vjpaicad5f0a2015-02-18 22:02:52 -0800467 gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
468 method->name());
469 return false;
470 }
Sree Kuchibhotlada069a52016-10-19 11:22:29 -0700471
Sree Kuchibhotlacb18d7a2016-10-20 12:39:30 -0700472 if (method->handler() == nullptr) { // Async method
Craig Tiller15f383c2016-01-07 12:45:32 -0800473 method->set_server_tag(tag);
474 } else {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700475 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
476 (*it)->AddSyncMethod(method, tag);
477 }
vjpaicad5f0a2015-02-18 22:02:52 -0800478 }
Sree Kuchibhotlada069a52016-10-19 11:22:29 -0700479
Yuchen Zenga42ec212016-04-29 13:03:06 -0700480 method_name = method->name();
481 }
482
483 // Parse service name.
484 if (method_name != nullptr) {
485 std::stringstream ss(method_name);
486 grpc::string service_name;
487 if (std::getline(ss, service_name, '/') &&
488 std::getline(ss, service_name, '/')) {
489 services_.push_back(service_name);
490 }
vjpaicad5f0a2015-02-18 22:02:52 -0800491 }
492 return true;
493}
494
Yang Gao49996492015-03-12 16:40:19 -0700495void Server::RegisterAsyncGenericService(AsyncGenericService* service) {
Yang Gao1c402332015-03-05 16:39:25 -0800496 GPR_ASSERT(service->server_ == nullptr &&
Yang Gao1ad253d2015-03-16 13:11:29 -0700497 "Can only register an async generic service against one server.");
Yang Gao1c402332015-03-05 16:39:25 -0800498 service->server_ = this;
yang-g9b7757d2015-08-13 11:15:53 -0700499 has_generic_service_ = true;
Yang Gao1c402332015-03-05 16:39:25 -0800500}
501
Nicolas Noblecfd60732015-03-18 16:27:43 -0700502int Server::AddListeningPort(const grpc::string& addr,
503 ServerCredentials* creds) {
vjpaicad5f0a2015-02-18 22:02:52 -0800504 GPR_ASSERT(!started_);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800505 return creds->AddPortToServer(addr, server_);
vjpaicad5f0a2015-02-18 22:02:52 -0800506}
507
Craig Tiller8f7bff72015-08-17 13:23:14 -0700508bool Server::Start(ServerCompletionQueue** cqs, size_t num_cqs) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800509 GPR_ASSERT(!started_);
yang-gf2fe4f72017-02-07 12:47:22 -0800510 global_callbacks_->PreServerStart(this);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800511 started_ = true;
yang-gad327642016-12-12 14:32:09 -0800512
513 // Only create default health check service when user did not provide an
514 // explicit one.
515 if (health_check_service_ == nullptr && !health_check_service_disabled_ &&
516 DefaultHealthCheckServiceEnabled()) {
yang-g076bac02017-02-07 13:50:36 -0800517 if (sync_server_cqs_->empty()) {
518 gpr_log(GPR_ERROR,
519 "Default health check service disabled at async-only server.");
520 } else {
521 auto* default_hc_service = new DefaultHealthCheckService;
522 health_check_service_.reset(default_hc_service);
523 RegisterService(nullptr, default_hc_service->GetHealthCheckService());
524 }
yang-gad327642016-12-12 14:32:09 -0800525 }
526
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800527 grpc_server_start(server_);
528
yang-g9b7757d2015-08-13 11:15:53 -0700529 if (!has_generic_service_) {
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700530 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
531 (*it)->AddUnknownSyncMethod();
Craig Tiller86d31772015-08-19 12:52:50 -0700532 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700533
Craig Tiller8f7bff72015-08-17 13:23:14 -0700534 for (size_t i = 0; i < num_cqs; i++) {
Craig Tillere0049582016-05-20 10:31:09 -0700535 if (cqs[i]->IsFrequentlyPolled()) {
536 new UnimplementedAsyncRequest(this, cqs[i]);
537 }
Craig Tillercbd04852015-02-10 17:39:54 -0800538 }
yang-g9b7757d2015-08-13 11:15:53 -0700539 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700540
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700541 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
542 (*it)->Start();
543 }
544
Craig Tiller0db1bef2015-02-09 13:47:39 -0800545 return true;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800546}
547
Craig Tillere50e5cb2015-08-18 12:44:57 -0700548void Server::ShutdownInternal(gpr_timespec deadline) {
Vijay Pai320ed132016-11-01 17:16:55 -0700549 std::unique_lock<std::mutex> lock(mu_);
Craig Tiller12352b22017-01-10 15:16:14 -0800550 if (!shutdown_) {
Craig Tiller6e57b9e2015-02-24 15:46:22 -0800551 shutdown_ = true;
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700552
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700553 /// The completion queue to use for server shutdown completion notification
554 CompletionQueue shutdown_cq;
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -0700555 ShutdownTag shutdown_tag; // Dummy shutdown tag
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700556 grpc_server_shutdown_and_notify(server_, shutdown_cq.cq(), &shutdown_tag);
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700557
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700558 shutdown_cq.Shutdown();
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700559
560 void* tag;
561 bool ok;
562 CompletionQueue::NextStatus status =
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700563 shutdown_cq.AsyncNext(&tag, &ok, deadline);
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700564
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700565 // If this timed out, it means we are done with the grace period for a clean
566 // shutdown. We should force a shutdown now by cancelling all inflight calls
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700567 if (status == CompletionQueue::NextStatus::TIMEOUT) {
568 grpc_server_cancel_all_calls(server_);
569 }
570 // Else in case of SHUTDOWN or GOT_EVENT, it means that the server has
571 // successfully shutdown
572
Craig Tiller9c5318a2016-12-05 15:07:04 -0800573 // Shutdown all ThreadManagers. This will try to gracefully stop all the
574 // threads in the ThreadManagers (once they process any inflight requests)
575 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
576 (*it)->Shutdown(); // ThreadManager's Shutdown()
577 }
578
Sree Kuchibhotla8f7739b2016-10-13 15:12:55 -0700579 // Wait for threads in all ThreadManagers to terminate
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700580 for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
581 (*it)->Wait();
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700582 (*it)->ShutdownAndDrainCompletionQueue();
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700583 }
584
Sree Kuchibhotla862acb92016-09-26 09:48:48 -0700585 // Drain the shutdown queue (if the previous call to AsyncNext() timed out
586 // and we didn't remove the tag from the queue yet)
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700587 while (shutdown_cq.Next(&tag, &ok)) {
Sree Kuchibhotla33382d02016-10-03 15:08:48 -0700588 // Nothing to be done here. Just ignore ok and tag values
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700589 }
590
yang-g6ec11f22016-07-14 14:53:35 -0700591 shutdown_notified_ = true;
yang-ge89dc6c2016-07-11 15:48:01 -0700592 shutdown_cv_.notify_all();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800593 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800594}
595
Craig Tiller6e57b9e2015-02-24 15:46:22 -0800596void Server::Wait() {
Vijay Pai320ed132016-11-01 17:16:55 -0700597 std::unique_lock<std::mutex> lock(mu_);
yang-g6ec11f22016-07-14 14:53:35 -0700598 while (started_ && !shutdown_notified_) {
599 shutdown_cv_.wait(lock);
600 }
Craig Tiller6e57b9e2015-02-24 15:46:22 -0800601}
602
Craig Tiller50a7a682015-06-04 12:53:40 -0700603void Server::PerformOpsOnCall(CallOpSetInterface* ops, Call* call) {
Craig Tillerbb5227f2015-02-11 13:34:48 -0800604 static const size_t MAX_OPS = 8;
Craig Tiller50a7a682015-06-04 12:53:40 -0700605 size_t nops = 0;
606 grpc_op cops[MAX_OPS];
607 ops->FillOps(cops, &nops);
Nicolas "Pixel" Nobleebb51402015-07-23 02:41:33 +0200608 auto result = grpc_call_start_batch(call->call(), cops, nops, ops, nullptr);
609 GPR_ASSERT(GRPC_CALL_OK == result);
Craig Tillerbb5227f2015-02-11 13:34:48 -0800610}
611
David Garcia Quintas44f32492016-01-14 18:00:04 -0800612ServerInterface::BaseAsyncRequest::BaseAsyncRequest(
613 ServerInterface* server, ServerContext* context,
Craig Tiller8f7bff72015-08-17 13:23:14 -0700614 ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag,
615 bool delete_on_finalize)
Craig Tillerce40de52015-06-05 07:14:58 -0700616 : server_(server),
617 context_(context),
618 stream_(stream),
619 call_cq_(call_cq),
Craig Tiller50955812015-06-05 08:03:17 -0700620 tag_(tag),
Craig Tiller8f7bff72015-08-17 13:23:14 -0700621 delete_on_finalize_(delete_on_finalize),
Craig Tillerce40de52015-06-05 07:14:58 -0700622 call_(nullptr) {
Vijay Paibf24dd92016-12-05 13:59:09 -0800623 call_cq_->RegisterAvalanching(); // This op will trigger more ops
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700624}
625
Vijay Paicbe15992016-12-05 13:56:29 -0800626ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() {
627 call_cq_->CompleteAvalanching();
628}
629
David Garcia Quintasf3ddb7c2016-01-20 16:02:22 -0800630bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag,
631 bool* status) {
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700632 if (*status) {
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800633 context_->client_metadata_.FillMap();
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700634 }
yang-g85c04f92015-07-07 17:47:31 -0700635 context_->set_call(call_);
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700636 context_->cq_ = call_cq_;
yang-gf07ed452017-02-16 23:01:28 -0800637 Call call(call_, server_, call_cq_, server_->max_receive_message_size());
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700638 if (*status && call_) {
639 context_->BeginCompletionOp(&call);
640 }
641 // just the pointers inside call are copied here
642 stream_->BindCall(&call);
Craig Tiller50955812015-06-05 08:03:17 -0700643 *tag = tag_;
Craig Tiller8f7bff72015-08-17 13:23:14 -0700644 if (delete_on_finalize_) {
645 delete this;
646 }
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700647 return true;
648}
649
David Garcia Quintas44f32492016-01-14 18:00:04 -0800650ServerInterface::RegisteredAsyncRequest::RegisteredAsyncRequest(
651 ServerInterface* server, ServerContext* context,
yang-g076bac02017-02-07 13:50:36 -0800652 ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag)
653 : BaseAsyncRequest(server, context, stream, call_cq, tag, true) {}
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700654
David Garcia Quintas44f32492016-01-14 18:00:04 -0800655void ServerInterface::RegisteredAsyncRequest::IssueRequest(
Craig Tillerce40de52015-06-05 07:14:58 -0700656 void* registered_method, grpc_byte_buffer** payload,
657 ServerCompletionQueue* notification_cq) {
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700658 grpc_server_request_registered_call(
David Garcia Quintas44f32492016-01-14 18:00:04 -0800659 server_->server(), registered_method, &call_, &context_->deadline_,
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800660 context_->client_metadata_.arr(), payload, call_cq_->cq(),
661 notification_cq->cq(), this);
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700662}
663
David Garcia Quintas44f32492016-01-14 18:00:04 -0800664ServerInterface::GenericAsyncRequest::GenericAsyncRequest(
665 ServerInterface* server, GenericServerContext* context,
Craig Tillerce40de52015-06-05 07:14:58 -0700666 ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq,
Craig Tiller8f7bff72015-08-17 13:23:14 -0700667 ServerCompletionQueue* notification_cq, void* tag, bool delete_on_finalize)
668 : BaseAsyncRequest(server, context, stream, call_cq, tag,
669 delete_on_finalize) {
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700670 grpc_call_details_init(&call_details_);
671 GPR_ASSERT(notification_cq);
672 GPR_ASSERT(call_cq);
David Garcia Quintas44f32492016-01-14 18:00:04 -0800673 grpc_server_request_call(server->server(), &call_, &call_details_,
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800674 context->client_metadata_.arr(), call_cq->cq(),
Craig Tillerce40de52015-06-05 07:14:58 -0700675 notification_cq->cq(), this);
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700676}
677
David Garcia Quintasf3ddb7c2016-01-20 16:02:22 -0800678bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag,
679 bool* status) {
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700680 // TODO(yangg) remove the copy here.
yang-g3deb0062015-06-23 14:06:08 -0700681 if (*status) {
yang-ga58cab32015-06-23 14:37:15 -0700682 static_cast<GenericServerContext*>(context_)->method_ =
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800683 StringFromCopiedSlice(call_details_.method);
684 static_cast<GenericServerContext*>(context_)->host_ =
685 StringFromCopiedSlice(call_details_.host);
yang-g3deb0062015-06-23 14:06:08 -0700686 }
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800687 grpc_slice_unref(call_details_.method);
688 grpc_slice_unref(call_details_.host);
Craig Tiller7bc97bc2015-06-04 17:22:54 -0700689 return BaseAsyncRequest::FinalizeResult(tag, status);
690}
691
Craig Tiller8f7bff72015-08-17 13:23:14 -0700692bool Server::UnimplementedAsyncRequest::FinalizeResult(void** tag,
693 bool* status) {
694 if (GenericAsyncRequest::FinalizeResult(tag, status) && *status) {
695 new UnimplementedAsyncRequest(server_, cq_);
696 new UnimplementedAsyncResponse(this);
697 } else {
698 delete this;
699 }
700 return false;
701}
702
703Server::UnimplementedAsyncResponse::UnimplementedAsyncResponse(
704 UnimplementedAsyncRequest* request)
705 : request_(request) {
706 Status status(StatusCode::UNIMPLEMENTED, "");
707 UnknownMethodHandler::FillOps(request_->context(), this);
708 request_->stream()->call_.PerformOps(this);
709}
710
Yuchen Zenga42ec212016-04-29 13:03:06 -0700711ServerInitializer* Server::initializer() { return server_initializer_.get(); }
712
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800713} // namespace grpc