GRPC C++  1.46.2
server_callback.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2019 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H
19 #define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H
20 
21 // IWYU pragma: private, include <grpcpp/support/server_callback.h>
22 
23 #include <atomic>
24 #include <functional>
25 #include <type_traits>
26 
35 
36 namespace grpc {
37 
38 // Declare base class of all reactors as internal
39 namespace internal {
40 
41 // Forward declarations
42 template <class Request, class Response>
43 class CallbackUnaryHandler;
44 template <class Request, class Response>
46 template <class Request, class Response>
48 template <class Request, class Response>
50 
52  public:
53  virtual ~ServerReactor() = default;
54  virtual void OnDone() = 0;
55  virtual void OnCancel() = 0;
56 
57  // The following is not API. It is for internal use only and specifies whether
58  // all reactions of this Reactor can be run without an extra executor
59  // scheduling. This should only be used for internally-defined reactors with
60  // trivial reactions.
61  virtual bool InternalInlineable() { return false; }
62 
63  private:
64  template <class Request, class Response>
65  friend class CallbackUnaryHandler;
66  template <class Request, class Response>
68  template <class Request, class Response>
70  template <class Request, class Response>
71  friend class CallbackBidiHandler;
72 };
73 
76  public:
77  virtual ~ServerCallbackCall() {}
78 
79  // This object is responsible for tracking when it is safe to call OnDone and
80  // OnCancel. OnDone should not be called until the method handler is complete,
81  // Finish has been called, the ServerContext CompletionOp (which tracks
82  // cancellation or successful completion) has completed, and all outstanding
83  // Read/Write actions have seen their reactions. OnCancel should not be called
84  // until after the method handler is done and the RPC has completed with a
85  // cancellation. This is tracked by counting how many of these conditions have
86  // been met and calling OnCancel when none remain unmet.
87 
88  // Public versions of MaybeDone: one where we don't know the reactor in
89  // advance (used for the ServerContext CompletionOp), and one for where we
90  // know the inlineability of the OnDone reaction. You should set the inline
91  // flag to true if either the Reactor is InternalInlineable() or if this
92  // callback is already being forced to run dispatched to an executor
93  // (typically because it contains additional work than just the MaybeDone).
94 
95  void MaybeDone() {
96  if (GPR_UNLIKELY(Unref() == 1)) {
97  ScheduleOnDone(reactor()->InternalInlineable());
98  }
99  }
100 
101  void MaybeDone(bool inline_ondone) {
102  if (GPR_UNLIKELY(Unref() == 1)) {
103  ScheduleOnDone(inline_ondone);
104  }
105  }
106 
107  // Fast version called with known reactor passed in, used from derived
108  // classes, typically in non-cancel case
110  if (GPR_UNLIKELY(UnblockCancellation())) {
111  CallOnCancel(reactor);
112  }
113  }
114 
115  // Slower version called from object that doesn't know the reactor a priori
116  // (such as the ServerContext CompletionOp which is formed before the
117  // reactor). This is used in cancel cases only, so it's ok to be slower and
118  // invoke a virtual function.
120  if (GPR_UNLIKELY(UnblockCancellation())) {
121  CallOnCancel(reactor());
122  }
123  }
124 
125  protected:
127  void Ref() { callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed); }
128 
129  private:
130  virtual ServerReactor* reactor() = 0;
131 
132  // CallOnDone performs the work required at completion of the RPC: invoking
133  // the OnDone function and doing all necessary cleanup. This function is only
134  // ever invoked on a fully-Unref'fed ServerCallbackCall.
135  virtual void CallOnDone() = 0;
136 
137  // If the OnDone reaction is inlineable, execute it inline. Otherwise send it
138  // to an executor.
139  void ScheduleOnDone(bool inline_ondone);
140 
141  // If the OnCancel reaction is inlineable, execute it inline. Otherwise send
142  // it to an executor.
143  void CallOnCancel(ServerReactor* reactor);
144 
145  // Implement the cancellation constraint counter. Return true if OnCancel
146  // should be called, false otherwise.
147  bool UnblockCancellation() {
148  return on_cancel_conditions_remaining_.fetch_sub(
149  1, std::memory_order_acq_rel) == 1;
150  }
151 
153  int Unref() {
154  return callbacks_outstanding_.fetch_sub(1, std::memory_order_acq_rel);
155  }
156 
157  std::atomic_int on_cancel_conditions_remaining_{2};
158  std::atomic_int callbacks_outstanding_{
159  3}; // reserve for start, Finish, and CompletionOp
160 };
161 
162 template <class Request, class Response>
163 class DefaultMessageHolder : public MessageHolder<Request, Response> {
164  public:
166  this->set_request(&request_obj_);
167  this->set_response(&response_obj_);
168  }
169  void Release() override {
170  // the object is allocated in the call arena.
172  }
173 
174  private:
175  Request request_obj_;
176  Response response_obj_;
177 };
178 
179 } // namespace internal
180 
181 // Forward declarations
182 class ServerUnaryReactor;
183 template <class Request>
185 template <class Response>
187 template <class Request, class Response>
189 
190 // NOTE: The actual call/stream object classes are provided as API only to
191 // support mocking. There are no implementations of these class interfaces in
192 // the API.
194  public:
195  ~ServerCallbackUnary() override {}
196  virtual void Finish(grpc::Status s) = 0;
197  virtual void SendInitialMetadata() = 0;
198 
199  protected:
200  // Use a template rather than explicitly specifying ServerUnaryReactor to
201  // delay binding and avoid a circular forward declaration issue
202  template <class Reactor>
203  void BindReactor(Reactor* reactor) {
204  reactor->InternalBindCall(this);
205  }
206 };
207 
208 template <class Request>
210  public:
211  ~ServerCallbackReader() override {}
212  virtual void Finish(grpc::Status s) = 0;
213  virtual void SendInitialMetadata() = 0;
214  virtual void Read(Request* msg) = 0;
215 
216  protected:
218  reactor->InternalBindReader(this);
219  }
220 };
221 
222 template <class Response>
224  public:
225  ~ServerCallbackWriter() override {}
226 
227  virtual void Finish(grpc::Status s) = 0;
228  virtual void SendInitialMetadata() = 0;
229  virtual void Write(const Response* msg, grpc::WriteOptions options) = 0;
230  virtual void WriteAndFinish(const Response* msg, grpc::WriteOptions options,
231  grpc::Status s) = 0;
232 
233  protected:
235  reactor->InternalBindWriter(this);
236  }
237 };
238 
239 template <class Request, class Response>
241  public:
243 
244  virtual void Finish(grpc::Status s) = 0;
245  virtual void SendInitialMetadata() = 0;
246  virtual void Read(Request* msg) = 0;
247  virtual void Write(const Response* msg, grpc::WriteOptions options) = 0;
248  virtual void WriteAndFinish(const Response* msg, grpc::WriteOptions options,
249  grpc::Status s) = 0;
250 
251  protected:
253  reactor->InternalBindStream(this);
254  }
255 };
256 
257 // The following classes are the reactor interfaces that are to be implemented
258 // by the user, returned as the output parameter of the method handler for a
259 // callback method. Note that none of the classes are pure; all reactions have a
260 // default empty reaction so that the user class only needs to override those
261 // reactions that it cares about. The reaction methods will be invoked by the
262 // library in response to the completion of various operations. Reactions must
263 // not include blocking operations (such as blocking I/O, starting synchronous
264 // RPCs, or waiting on condition variables). Reactions may be invoked
265 // concurrently, except that OnDone is called after all others (assuming proper
266 // API usage). The reactor may not be deleted until OnDone is called.
267 
269 template <class Request, class Response>
270 class ServerBidiReactor : public internal::ServerReactor {
271  public:
272  // NOTE: Initializing stream_ as a constructor initializer rather than a
273  // default initializer because gcc-4.x requires a copy constructor for
274  // default initializing a templated member, which isn't ok for atomic.
275  // TODO(vjpai): Switch to default constructor and default initializer when
276  // gcc-4.x is no longer supported
277  ServerBidiReactor() : stream_(nullptr) {}
278  ~ServerBidiReactor() override = default;
279 
283  void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(stream_mu_) {
285  stream_.load(std::memory_order_acquire);
286  if (stream == nullptr) {
287  grpc::internal::MutexLock l(&stream_mu_);
288  stream = stream_.load(std::memory_order_relaxed);
289  if (stream == nullptr) {
290  backlog_.send_initial_metadata_wanted = true;
291  return;
292  }
293  }
294  stream->SendInitialMetadata();
295  }
296 
301  void StartRead(Request* req) ABSL_LOCKS_EXCLUDED(stream_mu_) {
303  stream_.load(std::memory_order_acquire);
304  if (stream == nullptr) {
305  grpc::internal::MutexLock l(&stream_mu_);
306  stream = stream_.load(std::memory_order_relaxed);
307  if (stream == nullptr) {
308  backlog_.read_wanted = req;
309  return;
310  }
311  }
312  stream->Read(req);
313  }
314 
320  void StartWrite(const Response* resp) {
322  }
323 
330  void StartWrite(const Response* resp, grpc::WriteOptions options)
331  ABSL_LOCKS_EXCLUDED(stream_mu_) {
333  stream_.load(std::memory_order_acquire);
334  if (stream == nullptr) {
335  grpc::internal::MutexLock l(&stream_mu_);
336  stream = stream_.load(std::memory_order_relaxed);
337  if (stream == nullptr) {
338  backlog_.write_wanted = resp;
339  backlog_.write_options_wanted = options;
340  return;
341  }
342  }
343  stream->Write(resp, options);
344  }
345 
359  void StartWriteAndFinish(const Response* resp, grpc::WriteOptions options,
360  grpc::Status s) ABSL_LOCKS_EXCLUDED(stream_mu_) {
362  stream_.load(std::memory_order_acquire);
363  if (stream == nullptr) {
364  grpc::internal::MutexLock l(&stream_mu_);
365  stream = stream_.load(std::memory_order_relaxed);
366  if (stream == nullptr) {
367  backlog_.write_and_finish_wanted = true;
368  backlog_.write_wanted = resp;
369  backlog_.write_options_wanted = options;
370  backlog_.status_wanted = std::move(s);
371  return;
372  }
373  }
374  stream->WriteAndFinish(resp, options, std::move(s));
375  }
376 
385  void StartWriteLast(const Response* resp, grpc::WriteOptions options) {
386  StartWrite(resp, options.set_last_message());
387  }
388 
395  void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(stream_mu_) {
397  stream_.load(std::memory_order_acquire);
398  if (stream == nullptr) {
399  grpc::internal::MutexLock l(&stream_mu_);
400  stream = stream_.load(std::memory_order_relaxed);
401  if (stream == nullptr) {
402  backlog_.finish_wanted = true;
403  backlog_.status_wanted = std::move(s);
404  return;
405  }
406  }
407  stream->Finish(std::move(s));
408  }
409 
416  virtual void OnSendInitialMetadataDone(bool /*ok*/) {}
417 
422  virtual void OnReadDone(bool /*ok*/) {}
423 
429  virtual void OnWriteDone(bool /*ok*/) {}
430 
434  void OnDone() override = 0;
435 
439  void OnCancel() override {}
440 
441  private:
442  friend class ServerCallbackReaderWriter<Request, Response>;
443  // May be overridden by internal implementation details. This is not a public
444  // customization point.
445  virtual void InternalBindStream(
447  grpc::internal::MutexLock l(&stream_mu_);
448 
449  if (GPR_UNLIKELY(backlog_.send_initial_metadata_wanted)) {
450  stream->SendInitialMetadata();
451  }
452  if (GPR_UNLIKELY(backlog_.read_wanted != nullptr)) {
453  stream->Read(backlog_.read_wanted);
454  }
455  if (GPR_UNLIKELY(backlog_.write_and_finish_wanted)) {
456  stream->WriteAndFinish(backlog_.write_wanted,
457  std::move(backlog_.write_options_wanted),
458  std::move(backlog_.status_wanted));
459  } else {
460  if (GPR_UNLIKELY(backlog_.write_wanted != nullptr)) {
461  stream->Write(backlog_.write_wanted,
462  std::move(backlog_.write_options_wanted));
463  }
464  if (GPR_UNLIKELY(backlog_.finish_wanted)) {
465  stream->Finish(std::move(backlog_.status_wanted));
466  }
467  }
468  // Set stream_ last so that other functions can use it lock-free
469  stream_.store(stream, std::memory_order_release);
470  }
471 
472  grpc::internal::Mutex stream_mu_;
473  // TODO(vjpai): Make stream_or_backlog_ into a std::variant or absl::variant
474  // once C++17 or ABSL is supported since stream and backlog are
475  // mutually exclusive in this class. Do likewise with the
476  // remaining reactor classes and their backlogs as well.
477  std::atomic<ServerCallbackReaderWriter<Request, Response>*> stream_{nullptr};
478  struct PreBindBacklog {
479  bool send_initial_metadata_wanted = false;
480  bool write_and_finish_wanted = false;
481  bool finish_wanted = false;
482  Request* read_wanted = nullptr;
483  const Response* write_wanted = nullptr;
484  grpc::WriteOptions write_options_wanted;
485  grpc::Status status_wanted;
486  };
487  PreBindBacklog backlog_ ABSL_GUARDED_BY(stream_mu_);
488 };
489 
491 template <class Request>
492 class ServerReadReactor : public internal::ServerReactor {
493  public:
494  ServerReadReactor() : reader_(nullptr) {}
495  ~ServerReadReactor() override = default;
496 
498  void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(reader_mu_) {
500  reader_.load(std::memory_order_acquire);
501  if (reader == nullptr) {
502  grpc::internal::MutexLock l(&reader_mu_);
503  reader = reader_.load(std::memory_order_relaxed);
504  if (reader == nullptr) {
505  backlog_.send_initial_metadata_wanted = true;
506  return;
507  }
508  }
509  reader->SendInitialMetadata();
510  }
511  void StartRead(Request* req) ABSL_LOCKS_EXCLUDED(reader_mu_) {
513  reader_.load(std::memory_order_acquire);
514  if (reader == nullptr) {
515  grpc::internal::MutexLock l(&reader_mu_);
516  reader = reader_.load(std::memory_order_relaxed);
517  if (reader == nullptr) {
518  backlog_.read_wanted = req;
519  return;
520  }
521  }
522  reader->Read(req);
523  }
524  void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(reader_mu_) {
526  reader_.load(std::memory_order_acquire);
527  if (reader == nullptr) {
528  grpc::internal::MutexLock l(&reader_mu_);
529  reader = reader_.load(std::memory_order_relaxed);
530  if (reader == nullptr) {
531  backlog_.finish_wanted = true;
532  backlog_.status_wanted = std::move(s);
533  return;
534  }
535  }
536  reader->Finish(std::move(s));
537  }
538 
540  virtual void OnSendInitialMetadataDone(bool /*ok*/) {}
541  virtual void OnReadDone(bool /*ok*/) {}
542  void OnDone() override = 0;
543  void OnCancel() override {}
544 
545  private:
546  friend class ServerCallbackReader<Request>;
547 
548  // May be overridden by internal implementation details. This is not a public
549  // customization point.
550  virtual void InternalBindReader(ServerCallbackReader<Request>* reader)
551  ABSL_LOCKS_EXCLUDED(reader_mu_) {
552  grpc::internal::MutexLock l(&reader_mu_);
553 
554  if (GPR_UNLIKELY(backlog_.send_initial_metadata_wanted)) {
555  reader->SendInitialMetadata();
556  }
557  if (GPR_UNLIKELY(backlog_.read_wanted != nullptr)) {
558  reader->Read(backlog_.read_wanted);
559  }
560  if (GPR_UNLIKELY(backlog_.finish_wanted)) {
561  reader->Finish(std::move(backlog_.status_wanted));
562  }
563  // Set reader_ last so that other functions can use it lock-free
564  reader_.store(reader, std::memory_order_release);
565  }
566 
567  grpc::internal::Mutex reader_mu_;
568  std::atomic<ServerCallbackReader<Request>*> reader_{nullptr};
569  struct PreBindBacklog {
570  bool send_initial_metadata_wanted = false;
571  bool finish_wanted = false;
572  Request* read_wanted = nullptr;
573  grpc::Status status_wanted;
574  };
575  PreBindBacklog backlog_ ABSL_GUARDED_BY(reader_mu_);
576 };
577 
579 template <class Response>
580 class ServerWriteReactor : public internal::ServerReactor {
581  public:
582  ServerWriteReactor() : writer_(nullptr) {}
583  ~ServerWriteReactor() override = default;
584 
586  void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(writer_mu_) {
588  writer_.load(std::memory_order_acquire);
589  if (writer == nullptr) {
590  grpc::internal::MutexLock l(&writer_mu_);
591  writer = writer_.load(std::memory_order_relaxed);
592  if (writer == nullptr) {
593  backlog_.send_initial_metadata_wanted = true;
594  return;
595  }
596  }
597  writer->SendInitialMetadata();
598  }
599  void StartWrite(const Response* resp) {
601  }
602  void StartWrite(const Response* resp, grpc::WriteOptions options)
603  ABSL_LOCKS_EXCLUDED(writer_mu_) {
605  writer_.load(std::memory_order_acquire);
606  if (writer == nullptr) {
607  grpc::internal::MutexLock l(&writer_mu_);
608  writer = writer_.load(std::memory_order_relaxed);
609  if (writer == nullptr) {
610  backlog_.write_wanted = resp;
611  backlog_.write_options_wanted = options;
612  return;
613  }
614  }
615  writer->Write(resp, options);
616  }
617  void StartWriteAndFinish(const Response* resp, grpc::WriteOptions options,
618  grpc::Status s) ABSL_LOCKS_EXCLUDED(writer_mu_) {
620  writer_.load(std::memory_order_acquire);
621  if (writer == nullptr) {
622  grpc::internal::MutexLock l(&writer_mu_);
623  writer = writer_.load(std::memory_order_relaxed);
624  if (writer == nullptr) {
625  backlog_.write_and_finish_wanted = true;
626  backlog_.write_wanted = resp;
627  backlog_.write_options_wanted = options;
628  backlog_.status_wanted = std::move(s);
629  return;
630  }
631  }
632  writer->WriteAndFinish(resp, options, std::move(s));
633  }
634  void StartWriteLast(const Response* resp, grpc::WriteOptions options) {
635  StartWrite(resp, options.set_last_message());
636  }
637  void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(writer_mu_) {
639  writer_.load(std::memory_order_acquire);
640  if (writer == nullptr) {
641  grpc::internal::MutexLock l(&writer_mu_);
642  writer = writer_.load(std::memory_order_relaxed);
643  if (writer == nullptr) {
644  backlog_.finish_wanted = true;
645  backlog_.status_wanted = std::move(s);
646  return;
647  }
648  }
649  writer->Finish(std::move(s));
650  }
651 
653  virtual void OnSendInitialMetadataDone(bool /*ok*/) {}
654  virtual void OnWriteDone(bool /*ok*/) {}
655  void OnDone() override = 0;
656  void OnCancel() override {}
657 
658  private:
659  friend class ServerCallbackWriter<Response>;
660  // May be overridden by internal implementation details. This is not a public
661  // customization point.
662  virtual void InternalBindWriter(ServerCallbackWriter<Response>* writer)
663  ABSL_LOCKS_EXCLUDED(writer_mu_) {
664  grpc::internal::MutexLock l(&writer_mu_);
665 
666  if (GPR_UNLIKELY(backlog_.send_initial_metadata_wanted)) {
667  writer->SendInitialMetadata();
668  }
669  if (GPR_UNLIKELY(backlog_.write_and_finish_wanted)) {
670  writer->WriteAndFinish(backlog_.write_wanted,
671  std::move(backlog_.write_options_wanted),
672  std::move(backlog_.status_wanted));
673  } else {
674  if (GPR_UNLIKELY(backlog_.write_wanted != nullptr)) {
675  writer->Write(backlog_.write_wanted,
676  std::move(backlog_.write_options_wanted));
677  }
678  if (GPR_UNLIKELY(backlog_.finish_wanted)) {
679  writer->Finish(std::move(backlog_.status_wanted));
680  }
681  }
682  // Set writer_ last so that other functions can use it lock-free
683  writer_.store(writer, std::memory_order_release);
684  }
685 
686  grpc::internal::Mutex writer_mu_;
687  std::atomic<ServerCallbackWriter<Response>*> writer_{nullptr};
688  struct PreBindBacklog {
689  bool send_initial_metadata_wanted = false;
690  bool write_and_finish_wanted = false;
691  bool finish_wanted = false;
692  const Response* write_wanted = nullptr;
693  grpc::WriteOptions write_options_wanted;
694  grpc::Status status_wanted;
695  };
696  PreBindBacklog backlog_ ABSL_GUARDED_BY(writer_mu_);
697 };
698 
700  public:
701  ServerUnaryReactor() : call_(nullptr) {}
702  ~ServerUnaryReactor() override = default;
703 
705  void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(call_mu_) {
706  ServerCallbackUnary* call = call_.load(std::memory_order_acquire);
707  if (call == nullptr) {
708  grpc::internal::MutexLock l(&call_mu_);
709  call = call_.load(std::memory_order_relaxed);
710  if (call == nullptr) {
711  backlog_.send_initial_metadata_wanted = true;
712  return;
713  }
714  }
715  call->SendInitialMetadata();
716  }
720  void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(call_mu_) {
721  ServerCallbackUnary* call = call_.load(std::memory_order_acquire);
722  if (call == nullptr) {
723  grpc::internal::MutexLock l(&call_mu_);
724  call = call_.load(std::memory_order_relaxed);
725  if (call == nullptr) {
726  backlog_.finish_wanted = true;
727  backlog_.status_wanted = std::move(s);
728  return;
729  }
730  }
731  call->Finish(std::move(s));
732  }
733 
735  virtual void OnSendInitialMetadataDone(bool /*ok*/) {}
736  void OnDone() override = 0;
737  void OnCancel() override {}
738 
739  private:
740  friend class ServerCallbackUnary;
741  // May be overridden by internal implementation details. This is not a public
742  // customization point.
743  virtual void InternalBindCall(ServerCallbackUnary* call)
744  ABSL_LOCKS_EXCLUDED(call_mu_) {
745  grpc::internal::MutexLock l(&call_mu_);
746 
747  if (GPR_UNLIKELY(backlog_.send_initial_metadata_wanted)) {
748  call->SendInitialMetadata();
749  }
750  if (GPR_UNLIKELY(backlog_.finish_wanted)) {
751  call->Finish(std::move(backlog_.status_wanted));
752  }
753  // Set call_ last so that other functions can use it lock-free
754  call_.store(call, std::memory_order_release);
755  }
756 
757  grpc::internal::Mutex call_mu_;
758  std::atomic<ServerCallbackUnary*> call_{nullptr};
759  struct PreBindBacklog {
760  bool send_initial_metadata_wanted = false;
761  bool finish_wanted = false;
762  grpc::Status status_wanted;
763  };
764  PreBindBacklog backlog_ ABSL_GUARDED_BY(call_mu_);
765 };
766 
767 namespace internal {
768 
769 template <class Base>
770 class FinishOnlyReactor : public Base {
771  public:
772  explicit FinishOnlyReactor(grpc::Status s) { this->Finish(std::move(s)); }
773  void OnDone() override { this->~FinishOnlyReactor(); }
774 };
775 
777 template <class Request>
779 template <class Response>
782 template <class Request, class Response>
785 
786 } // namespace internal
787 
788 // TODO(vjpai): Remove namespace experimental when last known users are migrated
789 // off.
790 namespace experimental {
791 
792 template <class Request, class Response>
794 
795 } // namespace experimental
796 
797 } // namespace grpc
798 
799 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H
grpc::ServerReadReactor
ServerReadReactor is the interface for a client-streaming RPC.
Definition: server_callback.h:184
grpc::ServerCallbackReaderWriter::SendInitialMetadata
virtual void SendInitialMetadata()=0
grpc::ServerCallbackReader::~ServerCallbackReader
~ServerCallbackReader() override
Definition: server_callback.h:211
grpc::MessageHolder< Request, Response >::set_response
void set_response(Response *response)
Definition: message_allocator.h:52
grpc::ServerReadReactor::OnCancel
void OnCancel() override
Definition: server_callback.h:543
grpc::ServerBidiReactor::StartSendInitialMetadata
void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(stream_mu_)
Send any initial metadata stored in the RPC context.
Definition: server_callback.h:283
grpc::MessageHolder< Request, Response >::set_request
void set_request(Request *request)
Definition: message_allocator.h:51
grpc::ServerReadReactor::ServerReadReactor
ServerReadReactor()
Definition: server_callback.h:494
grpc::ServerReadReactor::OnDone
void OnDone() override=0
grpc::ServerCallbackReaderWriter::Finish
virtual void Finish(grpc::Status s)=0
grpc::ServerWriteReactor::StartWrite
void StartWrite(const Response *resp)
Definition: server_callback.h:599
grpc::ServerCallbackWriter::Finish
virtual void Finish(grpc::Status s)=0
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::ServerUnaryReactor::OnDone
void OnDone() override=0
grpc::ServerBidiReactor::StartWriteAndFinish
void StartWriteAndFinish(const Response *resp, grpc::WriteOptions options, grpc::Status s) ABSL_LOCKS_EXCLUDED(stream_mu_)
Initiate a write operation with specified options and final RPC Status, which also causes any trailin...
Definition: server_callback.h:359
status.h
grpc::WriteOptions::set_last_message
WriteOptions & set_last_message()
last-message bit: indicates this is the last message in a stream client-side: makes Write the equival...
Definition: call_op_set.h:158
grpc::internal::ServerReactor::~ServerReactor
virtual ~ServerReactor()=default
grpc::internal::ServerCallbackCall::MaybeCallOnCancel
void MaybeCallOnCancel()
Definition: server_callback.h:119
grpc::ServerWriteReactor::StartWrite
void StartWrite(const Response *resp, grpc::WriteOptions options) ABSL_LOCKS_EXCLUDED(writer_mu_)
Definition: server_callback.h:602
config.h
grpc::ServerWriteReactor::OnWriteDone
virtual void OnWriteDone(bool)
Definition: server_callback.h:654
grpc::ServerBidiReactor::ServerBidiReactor
ServerBidiReactor()
Definition: server_callback.h:277
grpc::ServerWriteReactor::OnSendInitialMetadataDone
virtual void OnSendInitialMetadataDone(bool)
The following notifications are exactly like ServerBidiReactor.
Definition: server_callback.h:653
grpc::ServerCallbackReader::Finish
virtual void Finish(grpc::Status s)=0
grpc::ServerReadReactor::StartRead
void StartRead(Request *req) ABSL_LOCKS_EXCLUDED(reader_mu_)
Definition: server_callback.h:511
grpc::internal::DefaultMessageHolder::DefaultMessageHolder
DefaultMessageHolder()
Definition: server_callback.h:165
grpc::ServerCallbackReaderWriter::~ServerCallbackReaderWriter
~ServerCallbackReaderWriter() override
Definition: server_callback.h:242
core_codegen_interface.h
grpc::ServerCallbackUnary::BindReactor
void BindReactor(Reactor *reactor)
Definition: server_callback.h:203
grpc::internal::ServerCallbackCall::MaybeCallOnCancel
void MaybeCallOnCancel(ServerReactor *reactor)
Definition: server_callback.h:109
grpc::ServerWriteReactor::StartWriteLast
void StartWriteLast(const Response *resp, grpc::WriteOptions options)
Definition: server_callback.h:634
grpc::ServerReadReactor::~ServerReadReactor
~ServerReadReactor() override=default
grpc::ServerCallbackReaderWriter
Definition: server_callback.h:240
grpc::ServerBidiReactor::StartWrite
void StartWrite(const Response *resp)
Initiate a write operation.
Definition: server_callback.h:320
grpc::ServerBidiReactor::OnCancel
void OnCancel() override
Notifies the application that this RPC has been cancelled.
Definition: server_callback.h:439
grpc::ServerCallbackReaderWriter::Write
virtual void Write(const Response *msg, grpc::WriteOptions options)=0
grpc::ServerBidiReactor::StartRead
void StartRead(Request *req) ABSL_LOCKS_EXCLUDED(stream_mu_)
Initiate a read operation.
Definition: server_callback.h:301
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:33
grpc::ServerWriteReactor::OnDone
void OnDone() override=0
grpc::ServerCallbackUnary::~ServerCallbackUnary
~ServerCallbackUnary() override
Definition: server_callback.h:195
grpc::ServerUnaryReactor::OnSendInitialMetadataDone
virtual void OnSendInitialMetadataDone(bool)
The following notifications are exactly like ServerBidiReactor.
Definition: server_callback.h:735
grpc::internal::ServerCallbackCall
The base class of ServerCallbackUnary etc.
Definition: server_callback.h:75
grpc::ServerBidiReactor::OnWriteDone
virtual void OnWriteDone(bool)
Notifies the application that a StartWrite (or StartWriteLast) operation completed.
Definition: server_callback.h:429
grpc::ServerBidiReactor::StartWrite
void StartWrite(const Response *resp, grpc::WriteOptions options) ABSL_LOCKS_EXCLUDED(stream_mu_)
Initiate a write operation with specified options.
Definition: server_callback.h:330
grpc::ServerCallbackReaderWriter::WriteAndFinish
virtual void WriteAndFinish(const Response *msg, grpc::WriteOptions options, grpc::Status s)=0
GPR_UNLIKELY
#define GPR_UNLIKELY(x)
Definition: port_platform.h:688
grpc::ServerBidiReactor::OnDone
void OnDone() override=0
Notifies the application that all operations associated with this RPC have completed.
grpc::ServerBidiReactor
ServerBidiReactor is the interface for a bidirectional streaming RPC.
Definition: server_callback.h:188
grpc::internal::CallbackUnaryHandler
Definition: byte_buffer.h:41
grpc::ServerCallbackWriter::SendInitialMetadata
virtual void SendInitialMetadata()=0
grpc::ServerBidiReactor::~ServerBidiReactor
~ServerBidiReactor() override=default
grpc::internal::DefaultMessageHolder
Definition: server_callback.h:163
grpc::internal::FinishOnlyReactor::FinishOnlyReactor
FinishOnlyReactor(grpc::Status s)
Definition: server_callback.h:772
grpc::ServerBidiReactor::OnReadDone
virtual void OnReadDone(bool)
Notifies the application that a StartRead operation completed.
Definition: server_callback.h:422
grpc::internal::ServerReactor::OnDone
virtual void OnDone()=0
grpc::ServerWriteReactor::StartWriteAndFinish
void StartWriteAndFinish(const Response *resp, grpc::WriteOptions options, grpc::Status s) ABSL_LOCKS_EXCLUDED(writer_mu_)
Definition: server_callback.h:617
grpc::internal::CallbackServerStreamingHandler
Definition: byte_buffer.h:43
grpc::ServerCallbackReaderWriter::Read
virtual void Read(Request *msg)=0
sync.h
grpc::ServerBidiReactor::Finish
void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(stream_mu_)
Indicate that the stream is to be finished and the trailing metadata and RPC status are to be sent.
Definition: server_callback.h:395
grpc::ServerCallbackReader::BindReactor
void BindReactor(ServerReadReactor< Request > *reactor)
Definition: server_callback.h:217
grpc::ServerCallbackWriter::BindReactor
void BindReactor(ServerWriteReactor< Response > *reactor)
Definition: server_callback.h:234
grpc::internal::FinishOnlyReactor
Definition: server_callback.h:770
grpc::ServerCallbackWriter::~ServerCallbackWriter
~ServerCallbackWriter() override
Definition: server_callback.h:225
grpc::ServerReadReactor::StartSendInitialMetadata
void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(reader_mu_)
The following operation initiations are exactly like ServerBidiReactor.
Definition: server_callback.h:498
grpc::internal::ServerCallbackCall::~ServerCallbackCall
virtual ~ServerCallbackCall()
Definition: server_callback.h:77
grpc::WriteOptions
Per-message write options.
Definition: call_op_set.h:81
grpc::internal::ServerCallbackCall::MaybeDone
void MaybeDone(bool inline_ondone)
Definition: server_callback.h:101
grpc::ServerWriteReactor
ServerWriteReactor is the interface for a server-streaming RPC.
Definition: server_callback.h:186
grpc::ServerReadReactor::OnReadDone
virtual void OnReadDone(bool)
Definition: server_callback.h:541
callback_common.h
grpc::ServerCallbackReader::Read
virtual void Read(Request *msg)=0
grpc::internal::CallbackBidiHandler
Definition: server_callback.h:49
grpc::internal::MutexLock
Definition: sync.h:86
grpc::ServerWriteReactor::OnCancel
void OnCancel() override
Definition: server_callback.h:656
grpc::ServerWriteReactor::~ServerWriteReactor
~ServerWriteReactor() override=default
grpc::ServerCallbackReaderWriter::BindReactor
void BindReactor(ServerBidiReactor< Request, Response > *reactor)
Definition: server_callback.h:252
grpc::ServerCallbackWriter
Definition: server_callback.h:223
call.h
grpc::ServerWriteReactor::StartSendInitialMetadata
void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(writer_mu_)
The following operation initiations are exactly like ServerBidiReactor.
Definition: server_callback.h:586
call_op_set.h
grpc::internal::ServerReactor::InternalInlineable
virtual bool InternalInlineable()
Definition: server_callback.h:61
grpc::ServerCallbackUnary::SendInitialMetadata
virtual void SendInitialMetadata()=0
grpc::ServerReadReactor::OnSendInitialMetadataDone
virtual void OnSendInitialMetadataDone(bool)
The following notifications are exactly like ServerBidiReactor.
Definition: server_callback.h:540
grpc::ServerBidiReactor::StartWriteLast
void StartWriteLast(const Response *resp, grpc::WriteOptions options)
Inform system of a planned write operation with specified options, but allow the library to schedule ...
Definition: server_callback.h:385
grpc::internal::FinishOnlyReactor::OnDone
void OnDone() override
Definition: server_callback.h:773
grpc::internal::ServerReactor
Definition: server_callback.h:51
grpc::internal::CallbackClientStreamingHandler
Definition: server_callback.h:45
grpc::ServerUnaryReactor::OnCancel
void OnCancel() override
Definition: server_callback.h:737
grpc::internal::ServerCallbackCall::Ref
void Ref()
Increases the reference count.
Definition: server_callback.h:127
grpc::internal::ServerReactor::OnCancel
virtual void OnCancel()=0
grpc::ServerCallbackReader
Definition: server_callback.h:209
grpc::ServerReadReactor::Finish
void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(reader_mu_)
Definition: server_callback.h:524
grpc::ServerCallbackWriter::Write
virtual void Write(const Response *msg, grpc::WriteOptions options)=0
grpc::MessageHolder
Definition: message_allocator.h:41
grpc::internal::Mutex
Definition: sync.h:59
grpc::ServerUnaryReactor::StartSendInitialMetadata
void StartSendInitialMetadata() ABSL_LOCKS_EXCLUDED(call_mu_)
StartSendInitialMetadata is exactly like ServerBidiReactor.
Definition: server_callback.h:705
grpc::ServerWriteReactor::Finish
void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(writer_mu_)
Definition: server_callback.h:637
grpc::ServerUnaryReactor::Finish
void Finish(grpc::Status s) ABSL_LOCKS_EXCLUDED(call_mu_)
Finish is similar to ServerBidiReactor except for one detail.
Definition: server_callback.h:720
grpc::ServerBidiReactor::OnSendInitialMetadataDone
virtual void OnSendInitialMetadataDone(bool)
Notifies the application that an explicit StartSendInitialMetadata operation completed.
Definition: server_callback.h:416
grpc::ServerUnaryReactor::~ServerUnaryReactor
~ServerUnaryReactor() override=default
grpc::ServerCallbackUnary
Definition: server_callback.h:193
grpc::ServerUnaryReactor::ServerUnaryReactor
ServerUnaryReactor()
Definition: server_callback.h:701
grpc::ServerWriteReactor::ServerWriteReactor
ServerWriteReactor()
Definition: server_callback.h:582
grpc::ServerUnaryReactor
Definition: server_callback.h:699
message_allocator.h
grpc::ServerCallbackWriter::WriteAndFinish
virtual void WriteAndFinish(const Response *msg, grpc::WriteOptions options, grpc::Status s)=0
grpc::ServerCallbackUnary::Finish
virtual void Finish(grpc::Status s)=0
grpc::ServerCallbackReader::SendInitialMetadata
virtual void SendInitialMetadata()=0
grpc::internal::ServerCallbackCall::MaybeDone
void MaybeDone()
Definition: server_callback.h:95
grpc::internal::DefaultMessageHolder::Release
void Release() override
Definition: server_callback.h:169
grpc::experimental::ServerBidiReactor
::grpc::ServerBidiReactor< Request, Response > ServerBidiReactor
Definition: server_callback.h:793