GRPC C++  1.62.0
call_op_set.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2018 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 
19 #ifndef GRPCPP_IMPL_CALL_OP_SET_H
20 #define GRPCPP_IMPL_CALL_OP_SET_H
21 
22 #include <cstring>
23 #include <map>
24 #include <memory>
25 
26 #include <grpc/grpc.h>
28 #include <grpc/impl/grpc_types.h>
29 #include <grpc/slice.h>
30 #include <grpc/support/alloc.h>
31 #include <grpc/support/log.h>
32 #include <grpcpp/client_context.h>
34 #include <grpcpp/impl/call.h>
35 #include <grpcpp/impl/call_hook.h>
42 #include <grpcpp/support/config.h>
43 #include <grpcpp/support/slice.h>
45 
46 namespace grpc {
47 
48 namespace internal {
49 class Call;
50 class CallHook;
51 
52 // TODO(yangg) if the map is changed before we send, the pointers will be a
53 // mess. Make sure it does not happen.
55  const std::multimap<std::string, std::string>& metadata,
56  size_t* metadata_count, const std::string& optional_error_details) {
57  *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1);
58  if (*metadata_count == 0) {
59  return nullptr;
60  }
61  grpc_metadata* metadata_array = static_cast<grpc_metadata*>(
62  gpr_malloc((*metadata_count) * sizeof(grpc_metadata)));
63  size_t i = 0;
64  for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) {
65  metadata_array[i].key = SliceReferencingString(iter->first);
66  metadata_array[i].value = SliceReferencingString(iter->second);
67  }
68  if (!optional_error_details.empty()) {
69  metadata_array[i].key = grpc_slice_from_static_buffer(
71  metadata_array[i].value = SliceReferencingString(optional_error_details);
72  }
73  return metadata_array;
74 }
75 } // namespace internal
76 
78 class WriteOptions {
79  public:
80  WriteOptions() : flags_(0), last_message_(false) {}
81 
83  inline void Clear() { flags_ = 0; }
84 
86  inline uint32_t flags() const { return flags_; }
87 
92  SetBit(GRPC_WRITE_NO_COMPRESS);
93  return *this;
94  }
95 
100  ClearBit(GRPC_WRITE_NO_COMPRESS);
101  return *this;
102  }
103 
108  inline bool get_no_compression() const {
109  return GetBit(GRPC_WRITE_NO_COMPRESS);
110  }
111 
117  SetBit(GRPC_WRITE_BUFFER_HINT);
118  return *this;
119  }
120 
126  ClearBit(GRPC_WRITE_BUFFER_HINT);
127  return *this;
128  }
129 
134  inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); }
135 
139  SetBit(GRPC_WRITE_BUFFER_HINT);
140  return *this;
141  }
142 
144  ClearBit(GRPC_WRITE_BUFFER_HINT);
145  return *this;
146  }
147 
148  inline bool is_corked() const { return GetBit(GRPC_WRITE_BUFFER_HINT); }
149 
156  last_message_ = true;
157  return *this;
158  }
159 
163  last_message_ = false;
164  return *this;
165  }
166 
171  bool is_last_message() const { return last_message_; }
172 
176  SetBit(GRPC_WRITE_THROUGH);
177  return *this;
178  }
179 
181  ClearBit(GRPC_WRITE_THROUGH);
182  return *this;
183  }
184 
185  inline bool is_write_through() const { return GetBit(GRPC_WRITE_THROUGH); }
186 
187  private:
188  void SetBit(const uint32_t mask) { flags_ |= mask; }
189 
190  void ClearBit(const uint32_t mask) { flags_ &= ~mask; }
191 
192  bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; }
193 
194  uint32_t flags_;
195  bool last_message_;
196 };
197 
198 namespace internal {
199 
203 template <int Unused>
204 class CallNoOp {
205  protected:
206  void AddOp(grpc_op* /*ops*/, size_t* /*nops*/) {}
207  void FinishOp(bool* /*status*/) {}
209  InterceptorBatchMethodsImpl* /*interceptor_methods*/) {}
211  InterceptorBatchMethodsImpl* /*interceptor_methods*/) {}
212  void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) {
213  }
214 };
215 
217  public:
219  maybe_compression_level_.is_set = false;
220  }
221 
222  void SendInitialMetadata(std::multimap<std::string, std::string>* metadata,
223  uint32_t flags) {
224  maybe_compression_level_.is_set = false;
225  send_ = true;
226  flags_ = flags;
227  metadata_map_ = metadata;
228  }
229 
231  maybe_compression_level_.is_set = true;
233  }
234 
235  protected:
236  void AddOp(grpc_op* ops, size_t* nops) {
237  if (!send_ || hijacked_) return;
238  grpc_op* op = &ops[(*nops)++];
240  op->flags = flags_;
241  op->reserved = nullptr;
248  if (maybe_compression_level_.is_set) {
251  }
252  }
253  void FinishOp(bool* /*status*/) {
254  if (!send_ || hijacked_) return;
256  send_ = false;
257  }
258 
260  InterceptorBatchMethodsImpl* interceptor_methods) {
261  if (!send_) return;
262  interceptor_methods->AddInterceptionHookPoint(
264  interceptor_methods->SetSendInitialMetadata(metadata_map_);
265  }
266 
268  InterceptorBatchMethodsImpl* /*interceptor_methods*/) {}
269 
270  void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) {
271  hijacked_ = true;
272  }
273 
274  bool hijacked_ = false;
275  bool send_;
276  uint32_t flags_;
278  std::multimap<std::string, std::string>* metadata_map_;
280  struct {
281  bool is_set;
284 };
285 
287  public:
288  CallOpSendMessage() : send_buf_() {}
289 
292  template <class M>
293  GRPC_MUST_USE_RESULT Status SendMessage(const M& message,
294  WriteOptions options);
295 
296  template <class M>
297  GRPC_MUST_USE_RESULT Status SendMessage(const M& message);
298 
302  template <class M>
303  GRPC_MUST_USE_RESULT Status SendMessagePtr(const M* message,
304  WriteOptions options);
305 
308  template <class M>
309  GRPC_MUST_USE_RESULT Status SendMessagePtr(const M* message);
310 
311  protected:
312  void AddOp(grpc_op* ops, size_t* nops) {
313  if (msg_ == nullptr && !send_buf_.Valid()) return;
314  if (hijacked_) {
315  serializer_ = nullptr;
316  return;
317  }
318  if (msg_ != nullptr) {
319  GPR_ASSERT(serializer_(msg_).ok());
320  }
321  serializer_ = nullptr;
322  grpc_op* op = &ops[(*nops)++];
323  op->op = GRPC_OP_SEND_MESSAGE;
324  op->flags = write_options_.flags();
325  op->reserved = nullptr;
326  op->data.send_message.send_message = send_buf_.c_buffer();
327  // Flags are per-message: clear them after use.
328  write_options_.Clear();
329  }
330  void FinishOp(bool* status) {
331  if (msg_ == nullptr && !send_buf_.Valid()) return;
332  send_buf_.Clear();
333  if (hijacked_ && failed_send_) {
334  // Hijacking interceptor failed this Op
335  *status = false;
336  } else if (!*status) {
337  // This Op was passed down to core and the Op failed
338  failed_send_ = true;
339  }
340  }
341 
343  InterceptorBatchMethodsImpl* interceptor_methods) {
344  if (msg_ == nullptr && !send_buf_.Valid()) return;
345  interceptor_methods->AddInterceptionHookPoint(
347  interceptor_methods->SetSendMessage(&send_buf_, &msg_, &failed_send_,
348  serializer_);
349  }
350 
352  InterceptorBatchMethodsImpl* interceptor_methods) {
353  if (msg_ != nullptr || send_buf_.Valid()) {
354  interceptor_methods->AddInterceptionHookPoint(
356  }
357  send_buf_.Clear();
358  msg_ = nullptr;
359  // The contents of the SendMessage value that was previously set
360  // has had its references stolen by core's operations
361  interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_,
362  nullptr);
363  }
364 
365  void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) {
366  hijacked_ = true;
367  }
368 
369  private:
370  const void* msg_ = nullptr; // The original non-serialized message
371  bool hijacked_ = false;
372  bool failed_send_ = false;
373  ByteBuffer send_buf_;
374  WriteOptions write_options_;
375  std::function<Status(const void*)> serializer_;
376 };
377 
378 template <class M>
380  write_options_ = options;
381  // Serialize immediately since we do not have access to the message pointer
382  bool own_buf;
384  message, send_buf_.bbuf_ptr(), &own_buf);
385  if (!own_buf) {
386  send_buf_.Duplicate();
387  }
388  return result;
389 }
390 
391 template <class M>
393  return SendMessage(message, WriteOptions());
394 }
395 
396 template <class M>
398  WriteOptions options) {
399  msg_ = message;
400  write_options_ = options;
401  // Store the serializer for later since we have access to the message
402  serializer_ = [this](const void* message) {
403  bool own_buf;
404  // TODO(vjpai): Remove the void below when possible
405  // The void in the template parameter below should not be needed
406  // (since it should be implicit) but is needed due to an observed
407  // difference in behavior between clang and gcc for certain internal users
409  *static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf);
410  if (!own_buf) {
411  send_buf_.Duplicate();
412  }
413  return result;
414  };
415  return Status();
416 }
417 
418 template <class M>
420  return SendMessagePtr(message, WriteOptions());
421 }
422 
423 template <class R>
425  public:
426  void RecvMessage(R* message) { message_ = message; }
427 
428  // Do not change status if no message is received.
429  void AllowNoMessage() { allow_not_getting_message_ = true; }
430 
431  bool got_message = false;
432 
433  protected:
434  void AddOp(grpc_op* ops, size_t* nops) {
435  if (message_ == nullptr || hijacked_) return;
436  grpc_op* op = &ops[(*nops)++];
437  op->op = GRPC_OP_RECV_MESSAGE;
438  op->flags = 0;
439  op->reserved = nullptr;
440  op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr();
441  }
442 
443  void FinishOp(bool* status) {
444  if (message_ == nullptr) return;
445  if (recv_buf_.Valid()) {
446  if (*status) {
447  got_message = *status =
448  SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_)
449  .ok();
450  recv_buf_.Release();
451  } else {
452  got_message = false;
453  recv_buf_.Clear();
454  }
455  } else if (hijacked_) {
456  if (hijacked_recv_message_failed_) {
457  FinishOpRecvMessageFailureHandler(status);
458  } else {
459  // The op was hijacked and it was successful. There is no further action
460  // to be performed since the message is already in its non-serialized
461  // form.
462  }
463  } else {
464  FinishOpRecvMessageFailureHandler(status);
465  }
466  }
467 
469  InterceptorBatchMethodsImpl* interceptor_methods) {
470  if (message_ == nullptr) return;
471  interceptor_methods->SetRecvMessage(message_,
472  &hijacked_recv_message_failed_);
473  }
474 
476  InterceptorBatchMethodsImpl* interceptor_methods) {
477  if (message_ == nullptr) return;
478  interceptor_methods->AddInterceptionHookPoint(
480  if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr);
481  }
482  void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) {
483  hijacked_ = true;
484  if (message_ == nullptr) return;
485  interceptor_methods->AddInterceptionHookPoint(
487  got_message = true;
488  }
489 
490  private:
491  // Sets got_message and \a status for a failed recv message op
492  void FinishOpRecvMessageFailureHandler(bool* status) {
493  got_message = false;
494  if (!allow_not_getting_message_) {
495  *status = false;
496  }
497  }
498 
499  R* message_ = nullptr;
500  ByteBuffer recv_buf_;
501  bool allow_not_getting_message_ = false;
502  bool hijacked_ = false;
503  bool hijacked_recv_message_failed_ = false;
504 };
505 
507  public:
508  virtual Status Deserialize(ByteBuffer* buf) = 0;
509  virtual ~DeserializeFunc() {}
510 };
511 
512 template <class R>
513 class DeserializeFuncType final : public DeserializeFunc {
514  public:
515  explicit DeserializeFuncType(R* message) : message_(message) {}
516  Status Deserialize(ByteBuffer* buf) override {
517  return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_);
518  }
519 
520  ~DeserializeFuncType() override {}
521 
522  private:
523  R* message_; // Not a managed pointer because management is external to this
524 };
525 
527  public:
528  template <class R>
529  void RecvMessage(R* message) {
530  // Use an explicit base class pointer to avoid resolution error in the
531  // following unique_ptr::reset for some old implementations.
532  DeserializeFunc* func = new DeserializeFuncType<R>(message);
533  deserialize_.reset(func);
534  message_ = message;
535  }
536 
537  // Do not change status if no message is received.
538  void AllowNoMessage() { allow_not_getting_message_ = true; }
539 
540  bool got_message = false;
541 
542  protected:
543  void AddOp(grpc_op* ops, size_t* nops) {
544  if (!deserialize_ || hijacked_) return;
545  grpc_op* op = &ops[(*nops)++];
546  op->op = GRPC_OP_RECV_MESSAGE;
547  op->flags = 0;
548  op->reserved = nullptr;
549  op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr();
550  }
551 
552  void FinishOp(bool* status) {
553  if (!deserialize_) return;
554  if (recv_buf_.Valid()) {
555  if (*status) {
556  got_message = true;
557  *status = deserialize_->Deserialize(&recv_buf_).ok();
558  recv_buf_.Release();
559  } else {
560  got_message = false;
561  recv_buf_.Clear();
562  }
563  } else if (hijacked_) {
564  if (hijacked_recv_message_failed_) {
565  FinishOpRecvMessageFailureHandler(status);
566  } else {
567  // The op was hijacked and it was successful. There is no further action
568  // to be performed since the message is already in its non-serialized
569  // form.
570  }
571  } else {
572  got_message = false;
573  if (!allow_not_getting_message_) {
574  *status = false;
575  }
576  }
577  }
578 
580  InterceptorBatchMethodsImpl* interceptor_methods) {
581  if (!deserialize_) return;
582  interceptor_methods->SetRecvMessage(message_,
583  &hijacked_recv_message_failed_);
584  }
585 
587  InterceptorBatchMethodsImpl* interceptor_methods) {
588  if (!deserialize_) return;
589  interceptor_methods->AddInterceptionHookPoint(
591  if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr);
592  deserialize_.reset();
593  }
594  void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) {
595  hijacked_ = true;
596  if (!deserialize_) return;
597  interceptor_methods->AddInterceptionHookPoint(
599  got_message = true;
600  }
601 
602  private:
603  // Sets got_message and \a status for a failed recv message op
604  void FinishOpRecvMessageFailureHandler(bool* status) {
605  got_message = false;
606  if (!allow_not_getting_message_) {
607  *status = false;
608  }
609  }
610 
611  void* message_ = nullptr;
612  std::unique_ptr<DeserializeFunc> deserialize_;
613  ByteBuffer recv_buf_;
614  bool allow_not_getting_message_ = false;
615  bool hijacked_ = false;
616  bool hijacked_recv_message_failed_ = false;
617 };
618 
620  public:
621  CallOpClientSendClose() : send_(false) {}
622 
623  void ClientSendClose() { send_ = true; }
624 
625  protected:
626  void AddOp(grpc_op* ops, size_t* nops) {
627  if (!send_ || hijacked_) return;
628  grpc_op* op = &ops[(*nops)++];
630  op->flags = 0;
631  op->reserved = nullptr;
632  }
633  void FinishOp(bool* /*status*/) { send_ = false; }
634 
636  InterceptorBatchMethodsImpl* interceptor_methods) {
637  if (!send_) return;
638  interceptor_methods->AddInterceptionHookPoint(
640  }
641 
643  InterceptorBatchMethodsImpl* /*interceptor_methods*/) {}
644 
645  void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) {
646  hijacked_ = true;
647  }
648 
649  private:
650  bool hijacked_ = false;
651  bool send_;
652 };
653 
655  public:
656  CallOpServerSendStatus() : send_status_available_(false) {}
657 
659  std::multimap<std::string, std::string>* trailing_metadata,
660  const Status& status) {
661  send_error_details_ = status.error_details();
662  metadata_map_ = trailing_metadata;
663  send_status_available_ = true;
664  send_status_code_ = static_cast<grpc_status_code>(status.error_code());
665  send_error_message_ = status.error_message();
666  }
667 
668  protected:
669  void AddOp(grpc_op* ops, size_t* nops) {
670  if (!send_status_available_ || hijacked_) return;
671  trailing_metadata_ = FillMetadataArray(
672  *metadata_map_, &trailing_metadata_count_, send_error_details_);
673  grpc_op* op = &ops[(*nops)++];
676  trailing_metadata_count_;
677  op->data.send_status_from_server.trailing_metadata = trailing_metadata_;
678  op->data.send_status_from_server.status = send_status_code_;
679  error_message_slice_ = SliceReferencingString(send_error_message_);
681  send_error_message_.empty() ? nullptr : &error_message_slice_;
682  op->flags = 0;
683  op->reserved = nullptr;
684  }
685 
686  void FinishOp(bool* /*status*/) {
687  if (!send_status_available_ || hijacked_) return;
688  gpr_free(trailing_metadata_);
689  send_status_available_ = false;
690  }
691 
693  InterceptorBatchMethodsImpl* interceptor_methods) {
694  if (!send_status_available_) return;
695  interceptor_methods->AddInterceptionHookPoint(
697  interceptor_methods->SetSendTrailingMetadata(metadata_map_);
698  interceptor_methods->SetSendStatus(&send_status_code_, &send_error_details_,
699  &send_error_message_);
700  }
701 
703  InterceptorBatchMethodsImpl* /*interceptor_methods*/) {}
704 
705  void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) {
706  hijacked_ = true;
707  }
708 
709  private:
710  bool hijacked_ = false;
711  bool send_status_available_;
712  grpc_status_code send_status_code_;
713  std::string send_error_details_;
714  std::string send_error_message_;
715  size_t trailing_metadata_count_;
716  std::multimap<std::string, std::string>* metadata_map_;
717  grpc_metadata* trailing_metadata_;
718  grpc_slice error_message_slice_;
719 };
720 
722  public:
723  CallOpRecvInitialMetadata() : metadata_map_(nullptr) {}
724 
726  context->initial_metadata_received_ = true;
727  metadata_map_ = &context->recv_initial_metadata_;
728  }
729 
730  protected:
731  void AddOp(grpc_op* ops, size_t* nops) {
732  if (metadata_map_ == nullptr || hijacked_) return;
733  grpc_op* op = &ops[(*nops)++];
735  op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr();
736  op->flags = 0;
737  op->reserved = nullptr;
738  }
739 
740  void FinishOp(bool* /*status*/) {
741  if (metadata_map_ == nullptr || hijacked_) return;
742  }
743 
745  InterceptorBatchMethodsImpl* interceptor_methods) {
746  interceptor_methods->SetRecvInitialMetadata(metadata_map_);
747  }
748 
750  InterceptorBatchMethodsImpl* interceptor_methods) {
751  if (metadata_map_ == nullptr) return;
752  interceptor_methods->AddInterceptionHookPoint(
754  metadata_map_ = nullptr;
755  }
756 
757  void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) {
758  hijacked_ = true;
759  if (metadata_map_ == nullptr) return;
760  interceptor_methods->AddInterceptionHookPoint(
762  }
763 
764  private:
765  bool hijacked_ = false;
766  MetadataMap* metadata_map_;
767 };
768 
770  public:
772  : recv_status_(nullptr), debug_error_string_(nullptr) {}
773 
774  void ClientRecvStatus(grpc::ClientContext* context, Status* status) {
775  client_context_ = context;
776  metadata_map_ = &client_context_->trailing_metadata_;
777  recv_status_ = status;
778  error_message_ = grpc_empty_slice();
779  }
780 
781  protected:
782  void AddOp(grpc_op* ops, size_t* nops) {
783  if (recv_status_ == nullptr || hijacked_) return;
784  grpc_op* op = &ops[(*nops)++];
786  op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr();
787  op->data.recv_status_on_client.status = &status_code_;
788  op->data.recv_status_on_client.status_details = &error_message_;
789  op->data.recv_status_on_client.error_string = &debug_error_string_;
790  op->flags = 0;
791  op->reserved = nullptr;
792  }
793 
794  void FinishOp(bool* /*status*/) {
795  if (recv_status_ == nullptr || hijacked_) return;
796  if (static_cast<StatusCode>(status_code_) == StatusCode::OK) {
797  *recv_status_ = Status();
798  GPR_DEBUG_ASSERT(debug_error_string_ == nullptr);
799  } else {
800  *recv_status_ =
801  Status(static_cast<StatusCode>(status_code_),
802  GRPC_SLICE_IS_EMPTY(error_message_)
803  ? std::string()
804  : std::string(GRPC_SLICE_START_PTR(error_message_),
805  GRPC_SLICE_END_PTR(error_message_)),
806  metadata_map_->GetBinaryErrorDetails());
807  if (debug_error_string_ != nullptr) {
808  client_context_->set_debug_error_string(debug_error_string_);
809  gpr_free(const_cast<char*>(debug_error_string_));
810  }
811  }
812  // TODO(soheil): Find callers that set debug string even for status OK,
813  // and fix them.
814  grpc_slice_unref(error_message_);
815  }
816 
818  InterceptorBatchMethodsImpl* interceptor_methods) {
819  interceptor_methods->SetRecvStatus(recv_status_);
820  interceptor_methods->SetRecvTrailingMetadata(metadata_map_);
821  }
822 
824  InterceptorBatchMethodsImpl* interceptor_methods) {
825  if (recv_status_ == nullptr) return;
826  interceptor_methods->AddInterceptionHookPoint(
828  recv_status_ = nullptr;
829  }
830 
831  void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) {
832  hijacked_ = true;
833  if (recv_status_ == nullptr) return;
834  interceptor_methods->AddInterceptionHookPoint(
836  }
837 
838  private:
839  bool hijacked_ = false;
840  grpc::ClientContext* client_context_;
841  MetadataMap* metadata_map_;
842  Status* recv_status_;
843  const char* debug_error_string_;
844  grpc_status_code status_code_;
845  grpc_slice error_message_;
846 };
847 
848 template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>,
849  class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>,
850  class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>>
851 class CallOpSet;
852 
859 template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6>
860 class CallOpSet : public CallOpSetInterface,
861  public Op1,
862  public Op2,
863  public Op3,
864  public Op4,
865  public Op5,
866  public Op6 {
867  public:
868  CallOpSet() : core_cq_tag_(this), return_tag_(this) {}
869  // The copy constructor and assignment operator reset the value of
870  // core_cq_tag_, return_tag_, done_intercepting_ and interceptor_methods_
871  // since those are only meaningful on a specific object, not across objects.
872  CallOpSet(const CallOpSet& other)
873  : core_cq_tag_(this),
874  return_tag_(this),
875  call_(other.call_),
876  done_intercepting_(false),
877  interceptor_methods_(InterceptorBatchMethodsImpl()) {}
878 
879  CallOpSet& operator=(const CallOpSet& other) {
880  if (&other == this) {
881  return *this;
882  }
883  core_cq_tag_ = this;
884  return_tag_ = this;
885  call_ = other.call_;
886  done_intercepting_ = false;
887  interceptor_methods_ = InterceptorBatchMethodsImpl();
888  return *this;
889  }
890 
891  void FillOps(Call* call) override {
892  done_intercepting_ = false;
893  grpc_call_ref(call->call());
894  call_ =
895  *call; // It's fine to create a copy of call since it's just pointers
896 
897  if (RunInterceptors()) {
899  } else {
900  // After the interceptors are run, ContinueFillOpsAfterInterception will
901  // be run
902  }
903  }
904 
905  bool FinalizeResult(void** tag, bool* status) override {
906  if (done_intercepting_) {
907  // Complete the avalanching since we are done with this batch of ops
908  call_.cq()->CompleteAvalanching();
909  // We have already finished intercepting and filling in the results. This
910  // round trip from the core needed to be made because interceptors were
911  // run
912  *tag = return_tag_;
913  *status = saved_status_;
914  grpc_call_unref(call_.call());
915  return true;
916  }
917 
918  this->Op1::FinishOp(status);
919  this->Op2::FinishOp(status);
920  this->Op3::FinishOp(status);
921  this->Op4::FinishOp(status);
922  this->Op5::FinishOp(status);
923  this->Op6::FinishOp(status);
924  saved_status_ = *status;
925  if (RunInterceptorsPostRecv()) {
926  *tag = return_tag_;
927  grpc_call_unref(call_.call());
928  return true;
929  }
930  // Interceptors are going to be run, so we can't return the tag just yet.
931  // After the interceptors are run, ContinueFinalizeResultAfterInterception
932  return false;
933  }
934 
935  void set_output_tag(void* return_tag) { return_tag_ = return_tag; }
936 
937  void* core_cq_tag() override { return core_cq_tag_; }
938 
943  void set_core_cq_tag(void* core_cq_tag) { core_cq_tag_ = core_cq_tag; }
944 
945  // This will be called while interceptors are run if the RPC is a hijacked
946  // RPC. This should set hijacking state for each of the ops.
947  void SetHijackingState() override {
948  this->Op1::SetHijackingState(&interceptor_methods_);
949  this->Op2::SetHijackingState(&interceptor_methods_);
950  this->Op3::SetHijackingState(&interceptor_methods_);
951  this->Op4::SetHijackingState(&interceptor_methods_);
952  this->Op5::SetHijackingState(&interceptor_methods_);
953  this->Op6::SetHijackingState(&interceptor_methods_);
954  }
955 
956  // Should be called after interceptors are done running
958  static const size_t MAX_OPS = 6;
959  grpc_op ops[MAX_OPS];
960  size_t nops = 0;
961  this->Op1::AddOp(ops, &nops);
962  this->Op2::AddOp(ops, &nops);
963  this->Op3::AddOp(ops, &nops);
964  this->Op4::AddOp(ops, &nops);
965  this->Op5::AddOp(ops, &nops);
966  this->Op6::AddOp(ops, &nops);
967 
968  grpc_call_error err =
969  grpc_call_start_batch(call_.call(), ops, nops, core_cq_tag(), nullptr);
970 
971  if (err != GRPC_CALL_OK) {
972  // A failure here indicates an API misuse; for example, doing a Write
973  // while another Write is already pending on the same RPC or invoking
974  // WritesDone multiple times
975  gpr_log(GPR_ERROR, "API misuse of type %s observed",
977  GPR_ASSERT(false);
978  }
979  }
980 
981  // Should be called after interceptors are done running on the finalize result
982  // path
984  done_intercepting_ = true;
985  // The following call_start_batch is internally-generated so no need for an
986  // explanatory log on failure.
987  GPR_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(),
988  nullptr) == GRPC_CALL_OK);
989  }
990 
991  private:
992  // Returns true if no interceptors need to be run
993  bool RunInterceptors() {
994  interceptor_methods_.ClearState();
995  interceptor_methods_.SetCallOpSetInterface(this);
996  interceptor_methods_.SetCall(&call_);
997  this->Op1::SetInterceptionHookPoint(&interceptor_methods_);
998  this->Op2::SetInterceptionHookPoint(&interceptor_methods_);
999  this->Op3::SetInterceptionHookPoint(&interceptor_methods_);
1000  this->Op4::SetInterceptionHookPoint(&interceptor_methods_);
1001  this->Op5::SetInterceptionHookPoint(&interceptor_methods_);
1002  this->Op6::SetInterceptionHookPoint(&interceptor_methods_);
1003  if (interceptor_methods_.InterceptorsListEmpty()) {
1004  return true;
1005  }
1006  // This call will go through interceptors and would need to
1007  // schedule new batches, so delay completion queue shutdown
1008  call_.cq()->RegisterAvalanching();
1009  return interceptor_methods_.RunInterceptors();
1010  }
1011  // Returns true if no interceptors need to be run
1012  bool RunInterceptorsPostRecv() {
1013  // Call and OpSet had already been set on the set state.
1014  // SetReverse also clears previously set hook points
1015  interceptor_methods_.SetReverse();
1016  this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_);
1017  this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_);
1018  this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_);
1019  this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_);
1020  this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_);
1021  this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_);
1022  return interceptor_methods_.RunInterceptors();
1023  }
1024 
1025  void* core_cq_tag_;
1026  void* return_tag_;
1027  Call call_;
1028  bool done_intercepting_ = false;
1029  InterceptorBatchMethodsImpl interceptor_methods_;
1030  bool saved_status_;
1031 };
1032 
1033 } // namespace internal
1034 } // namespace grpc
1035 
1036 #endif // GRPCPP_IMPL_CALL_OP_SET_H
grpc::internal::CallOpSendMessage::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:365
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
malloc.
grpc::internal::Call::cq
grpc::CompletionQueue * cq() const
Definition: call.h:71
grpc::internal::CallOpRecvInitialMetadata
Definition: call_op_set.h:721
grpc_op::grpc_op_data::grpc_op_send_message::send_message
struct grpc_byte_buffer * send_message
This op takes ownership of the slices in send_message.
Definition: grpc_types.h:340
grpc_op::flags
uint32_t flags
Write flags bitset for grpc_begin_messages.
Definition: grpc_types.h:316
grpc::internal::CallOpSendInitialMetadata::initial_metadata_
grpc_metadata * initial_metadata_
Definition: call_op_set.h:279
grpc::internal::CallOpRecvMessage::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:475
grpc_empty_slice
GPRAPI grpc_slice grpc_empty_slice(void)
grpc_call_error
grpc_call_error
Result of a grpc call.
Definition: grpc_types.h:141
grpc::WriteOptions::clear_last_message
WriteOptions & clear_last_message()
Clears flag indicating that this is the last message in a stream, disabling coalescing.
Definition: call_op_set.h:162
grpc::WriteOptions::set_corked
WriteOptions & set_corked()
corked bit: aliases set_buffer_hint currently, with the intent that set_buffer_hint will be removed i...
Definition: call_op_set.h:138
grpc::experimental::InterceptionHookPoints::POST_RECV_STATUS
@ POST_RECV_STATUS
grpc::WriteOptions::get_buffer_hint
bool get_buffer_hint() const
Get value for the flag indicating that the write may be buffered and need not go out on the wire imme...
Definition: call_op_set.h:134
grpc::internal::CallOpClientRecvStatus::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:782
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::trailing_metadata
grpc_metadata_array * trailing_metadata
ownership of the array is with the caller, but ownership of the elements stays with the call object (...
Definition: grpc_types.h:373
grpc::internal::CallOpClientSendClose
Definition: call_op_set.h:619
grpc::internal::CallOpSendInitialMetadata::maybe_compression_level_
struct grpc::internal::CallOpSendInitialMetadata::@3 maybe_compression_level_
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status
grpc_status_code * status
Definition: grpc_types.h:374
grpc::experimental::InterceptionHookPoints::PRE_SEND_CLOSE
@ PRE_SEND_CLOSE
grpc::internal::CallOpRecvMessage::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:482
grpc::internal::CallOpClientSendClose::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:645
grpc::internal::CallOpSet::CallOpSet
CallOpSet()
Definition: call_op_set.h:868
grpc::internal::CallOpSendInitialMetadata::flags_
uint32_t flags_
Definition: call_op_set.h:276
grpc::internal::CallOpGenericRecvMessage
Definition: call_op_set.h:526
grpc::internal::CallOpRecvInitialMetadata::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:757
grpc::internal::CallOpServerSendStatus
Definition: call_op_set.h:654
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: slice_type.h:99
grpc::ByteBuffer::Duplicate
void Duplicate()
Make a duplicate copy of the internals of this byte buffer so that we have our own owned version of i...
Definition: byte_buffer.h:140
grpc::internal::CallOpSendInitialMetadata::hijacked_
bool hijacked_
Definition: call_op_set.h:274
grpc::experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA
@ PRE_SEND_INITIAL_METADATA
The first three in this list are for clients and servers.
grpc::internal::CallOpGenericRecvMessage::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:543
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::internal::CallOpSet
Primary implementation of CallOpSetInterface.
Definition: completion_queue.h:96
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: log.h:103
grpc::internal::CallOpSendInitialMetadata::metadata_map_
std::multimap< std::string, std::string > * metadata_map_
Definition: call_op_set.h:278
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::grpc_op_send_initial_metadata_maybe_compression_level::level
grpc_compression_level level
Definition: grpc_types.h:331
grpc::internal::CallOpSendMessage
Definition: call_op_set.h:286
GRPC_SLICE_END_PTR
#define GRPC_SLICE_END_PTR(slice)
Definition: slice_type.h:108
interceptor_common.h
grpc_op::grpc_op_data::send_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
grpc::WriteOptions::get_no_compression
bool get_no_compression() const
Get value for the flag indicating whether compression for the next message write is forcefully disabl...
Definition: call_op_set.h:108
grpc_status_code
grpc_status_code
Definition: status.h:28
grpc::internal::InterceptorBatchMethodsImpl::SetRecvInitialMetadata
void SetRecvInitialMetadata(MetadataMap *map)
Definition: interceptor_common.h:173
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:155
GRPC_MUST_USE_RESULT
#define GRPC_MUST_USE_RESULT
Definition: port_platform.h:656
grpc::experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA
@ POST_RECV_INITIAL_METADATA
The following two are for all clients and servers.
grpc::experimental::InterceptionHookPoints::POST_RECV_MESSAGE
@ POST_RECV_MESSAGE
grpc::internal::CallOpSendMessage::FinishOp
void FinishOp(bool *status)
Definition: call_op_set.h:330
grpc_op::reserved
void * reserved
Reserved for future usage.
Definition: grpc_types.h:318
grpc::internal::InterceptorBatchMethodsImpl::SetCallOpSetInterface
void SetCallOpSetInterface(CallOpSetInterface *ops)
Definition: interceptor_common.h:219
grpc::internal::CallOpGenericRecvMessage::RecvMessage
void RecvMessage(R *message)
Definition: call_op_set.h:529
grpc::experimental::InterceptionHookPoints::PRE_RECV_MESSAGE
@ PRE_RECV_MESSAGE
GPR_ERROR
#define GPR_ERROR
Definition: log.h:55
grpc::WriteOptions::is_write_through
bool is_write_through() const
Definition: call_op_set.h:185
grpc::experimental::InterceptionHookPoints::PRE_RECV_STATUS
@ PRE_RECV_STATUS
grpc::internal::CallOpSet::FillOps
void FillOps(Call *call) override
Definition: call_op_set.h:891
intercepted_channel.h
grpc::internal::InterceptorBatchMethodsImpl::SetCall
void SetCall(Call *call)
Definition: interceptor_common.h:215
grpc::internal::InterceptorBatchMethodsImpl::InterceptorsListEmpty
bool InterceptorsListEmpty()
Definition: interceptor_common.h:223
grpc::internal::CallOpClientRecvStatus::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:831
grpc::internal::InterceptorBatchMethodsImpl::ClearState
void ClearState()
Definition: interceptor_common.h:201
grpc::internal::CallOpSendMessage::CallOpSendMessage
CallOpSendMessage()
Definition: call_op_set.h:288
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: call.h:36
GPR_ASSERT
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:95
grpc::internal::MetadataMap::arr
grpc_metadata_array * arr()
Definition: metadata_map.h:71
GRPC_CALL_OK
@ GRPC_CALL_OK
everything went ok
Definition: grpc_types.h:143
grpc::WriteOptions::WriteOptions
WriteOptions()
Definition: call_op_set.h:80
grpc::WriteOptions::set_write_through
WriteOptions & set_write_through()
Guarantee that all bytes have been written to the socket before completing this write (usually writes...
Definition: call_op_set.h:175
grpc::internal::CallOpClientRecvStatus::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:823
grpc::internal::CallOpSendInitialMetadata
Definition: call_op_set.h:216
completion_queue_tag.h
grpc::internal::CallOpSendInitialMetadata::initial_metadata_count_
size_t initial_metadata_count_
Definition: call_op_set.h:277
grpc::internal::CallOpClientSendClose::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:633
grpc::internal::CallOpServerSendStatus::ServerSendStatus
void ServerSendStatus(std::multimap< std::string, std::string > *trailing_metadata, const Status &status)
Definition: call_op_set.h:658
grpc::internal::CallOpClientRecvStatus::CallOpClientRecvStatus
CallOpClientRecvStatus()
Definition: call_op_set.h:771
grpc::internal::CallNoOp::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:208
grpc_call_ref
GRPCAPI void grpc_call_ref(grpc_call *call)
Ref a call.
GRPC_WRITE_NO_COMPRESS
#define GRPC_WRITE_NO_COMPRESS
Force compression to be disabled for a particular write (start_write/add_metadata).
Definition: grpc_types.h:190
grpc::internal::CallNoOp::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:212
grpc::internal::CallOpRecvMessage::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:468
grpc_op::grpc_op_data::recv_message
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
grpc::internal::MetadataMap
Definition: metadata_map.h:34
grpc::internal::CallOpServerSendStatus::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:669
grpc::experimental::InterceptionHookPoints::PRE_SEND_STATUS
@ PRE_SEND_STATUS
grpc_op::data
union grpc_op::grpc_op_data data
grpc::internal::CallNoOp::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:207
grpc::internal::CallOpSendInitialMetadata::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:267
grpc::internal::CallOpRecvMessage::FinishOp
void FinishOp(bool *status)
Definition: call_op_set.h:443
grpc_types.h
grpc::internal::CallOpSet::CallOpSet
CallOpSet(const CallOpSet &other)
Definition: call_op_set.h:872
grpc::WriteOptions::flags
uint32_t flags() const
Returns raw flags bitset.
Definition: call_op_set.h:86
gpr_free
GPRAPI void gpr_free(void *ptr)
free
grpc::internal::CallNoOp::AddOp
void AddOp(grpc_op *, size_t *)
Definition: call_op_set.h:206
grpc::internal::CallOpServerSendStatus::CallOpServerSendStatus
CallOpServerSendStatus()
Definition: call_op_set.h:656
grpc::internal::CallOpSet::ContinueFillOpsAfterInterception
void ContinueFillOpsAfterInterception() override
Definition: call_op_set.h:957
grpc_op::grpc_op_data::grpc_op_recv_message::recv_message
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:365
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:35
grpc::internal::DeserializeFunc
Definition: call_op_set.h:506
grpc_metadata
A single metadata element.
Definition: grpc_types.h:211
grpc::internal::CallOpSendInitialMetadata::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:270
grpc::internal::CallOpSendMessage::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:312
grpc::internal::InterceptorBatchMethodsImpl::SetSendStatus
void SetSendStatus(grpc_status_code *code, std::string *error_details, std::string *error_message)
Definition: interceptor_common.h:156
grpc::internal::CallOpSet::core_cq_tag
void * core_cq_tag() override
Definition: call_op_set.h:937
grpc::internal::CallOpRecvInitialMetadata::CallOpRecvInitialMetadata
CallOpRecvInitialMetadata()
Definition: call_op_set.h:723
grpc::internal::CallOpGenericRecvMessage::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:594
GRPC_OP_RECV_INITIAL_METADATA
@ GRPC_OP_RECV_INITIAL_METADATA
Receive initial metadata: one and only one MUST be made on the client, must not be made on the server...
Definition: grpc_types.h:289
grpc::internal::CallOpRecvMessage::got_message
bool got_message
Definition: call_op_set.h:431
grpc::internal::CallOpSendMessage::SendMessage
GRPC_MUST_USE_RESULT Status SendMessage(const M &message, WriteOptions options)
Send message using options for the write.
GRPC_OP_SEND_STATUS_FROM_SERVER
@ GRPC_OP_SEND_STATUS_FROM_SERVER
Send status from the server: one and only one instance MUST be sent from the server unless the call w...
Definition: grpc_types.h:284
grpc::internal::CallOpRecvInitialMetadata::RecvInitialMetadata
void RecvInitialMetadata(grpc::ClientContext *context)
Definition: call_op_set.h:725
grpc::internal::CallOpClientRecvStatus::ClientRecvStatus
void ClientRecvStatus(grpc::ClientContext *context, Status *status)
Definition: call_op_set.h:774
log.h
GRPC_SLICE_IS_EMPTY
#define GRPC_SLICE_IS_EMPTY(slice)
Definition: slice_type.h:110
grpc::OK
@ OK
Not an error; returned on success.
Definition: status_code_enum.h:28
grpc::internal::kBinaryErrorDetailsKey
const char kBinaryErrorDetailsKey[]
Definition: metadata_map.h:32
grpc_call_unref
GRPCAPI void grpc_call_unref(grpc_call *call)
Unref a call.
grpc_op::grpc_op_data::grpc_op_send_status_from_server::status
grpc_status_code status
Definition: grpc_types.h:345
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::error_string
const char ** error_string
If this is not nullptr, it will be populated with the full fidelity error string for debugging purpos...
Definition: grpc_types.h:379
completion_queue.h
grpc::WriteOptions::clear_write_through
WriteOptions & clear_write_through()
Definition: call_op_set.h:180
grpc::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:193
grpc::internal::CallOpGenericRecvMessage::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:586
grpc::WriteOptions::is_corked
bool is_corked() const
Definition: call_op_set.h:148
grpc::ByteBuffer::Clear
void Clear()
Remove all data.
Definition: byte_buffer.h:128
grpc_metadata::value
grpc_slice value
Definition: grpc_types.h:215
grpc.h
grpc::internal::DeserializeFuncType
Definition: call_op_set.h:513
grpc::ByteBuffer
A sequence of bytes.
Definition: byte_buffer.h:60
grpc::internal::CallOpSendMessage::SendMessagePtr
GRPC_MUST_USE_RESULT Status SendMessagePtr(const M *message, WriteOptions options)
Send message using options for the write.
GRPC_WRITE_BUFFER_HINT
#define GRPC_WRITE_BUFFER_HINT
Write Flags:
Definition: grpc_types.h:187
grpc::internal::CallOpClientRecvStatus::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:817
grpc::internal::DeserializeFunc::~DeserializeFunc
virtual ~DeserializeFunc()
Definition: call_op_set.h:509
grpc_op
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments)
Definition: grpc_types.h:312
grpc::internal::InterceptorBatchMethodsImpl::SetReverse
void SetReverse()
Definition: interceptor_common.h:208
GRPC_OP_SEND_MESSAGE
@ GRPC_OP_SEND_MESSAGE
Send a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:274
grpc::internal::InterceptorBatchMethodsImpl::SetRecvStatus
void SetRecvStatus(Status *status)
Definition: interceptor_common.h:177
grpc::internal::CallOpClientSendClose::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:635
grpc::internal::CallOpSet::SetHijackingState
void SetHijackingState() override
Definition: call_op_set.h:947
grpc::internal::CallOpSendInitialMetadata::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:236
GRPC_WRITE_THROUGH
#define GRPC_WRITE_THROUGH
Force this message to be written to the socket before completing it.
Definition: grpc_types.h:192
grpc_op::grpc_op_data::grpc_op_send_status_from_server::trailing_metadata
grpc_metadata * trailing_metadata
Definition: grpc_types.h:344
grpc::internal::CallOpSendInitialMetadata::send_
bool send_
Definition: call_op_set.h:275
grpc::internal::CallOpClientRecvStatus::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:794
grpc_slice
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice_type.h:63
grpc::internal::CallOpRecvInitialMetadata::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:740
grpc::Status::error_message
std::string error_message() const
Return the instance's error message.
Definition: status.h:120
grpc::StatusCode
StatusCode
Definition: status_code_enum.h:26
grpc::SerializationTraits
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
grpc::internal::CallOpGenericRecvMessage::FinishOp
void FinishOp(bool *status)
Definition: call_op_set.h:552
grpc::internal::CallOpRecvMessage::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:434
grpc::internal::CallOpSendInitialMetadata::CallOpSendInitialMetadata
CallOpSendInitialMetadata()
Definition: call_op_set.h:218
call_op_set_interface.h
grpc::internal::CallOpSendInitialMetadata::level
grpc_compression_level level
Definition: call_op_set.h:282
grpc::internal::CallOpSendInitialMetadata::set_compression_level
void set_compression_level(grpc_compression_level level)
Definition: call_op_set.h:230
call_hook.h
grpc_op::op
grpc_op_type op
Operation type, as defined by grpc_op_type.
Definition: grpc_types.h:314
alloc.h
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::count
size_t count
Definition: grpc_types.h:325
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status_details
grpc_slice * status_details
Definition: grpc_types.h:375
grpc::internal::DeserializeFuncType::DeserializeFuncType
DeserializeFuncType(R *message)
Definition: call_op_set.h:515
compression_types.h
grpc::experimental::InterceptionHookPoints::PRE_SEND_MESSAGE
@ PRE_SEND_MESSAGE
grpc::internal::InterceptorBatchMethodsImpl::SetRecvMessage
void SetRecvMessage(void *message, bool *hijacked_recv_message_failed)
Definition: interceptor_common.h:168
grpc::Status::error_code
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:118
grpc::internal::DeserializeFuncType::Deserialize
Status Deserialize(ByteBuffer *buf) override
Definition: call_op_set.h:516
grpc::internal::CallOpSet::set_output_tag
void set_output_tag(void *return_tag)
Definition: call_op_set.h:935
GRPC_OP_RECV_MESSAGE
@ GRPC_OP_RECV_MESSAGE
Receive a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:293
grpc::internal::CallOpClientSendClose::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:626
grpc::WriteOptions
Per-message write options.
Definition: call_op_set.h:78
grpc::internal::CallOpClientSendClose::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:642
serialization_traits.h
client_context.h
grpc::internal::CallNoOp::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:210
grpc_op::grpc_op_data::send_status_from_server
struct grpc_op::grpc_op_data::grpc_op_send_status_from_server send_status_from_server
grpc::internal::CallOpRecvInitialMetadata::AddOp
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:731
slice.h
grpc::internal::CallOpServerSendStatus::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:692
grpc::internal::CallOpServerSendStatus::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:702
grpc::experimental::InterceptionHookPoints::POST_SEND_MESSAGE
@ POST_SEND_MESSAGE
grpc::internal::DeserializeFuncType::~DeserializeFuncType
~DeserializeFuncType() override
Definition: call_op_set.h:520
grpc_slice_from_static_buffer
GPRAPI grpc_slice grpc_slice_from_static_buffer(const void *source, size_t len)
Create a slice pointing to constant memory.
GRPC_OP_SEND_INITIAL_METADATA
@ GRPC_OP_SEND_INITIAL_METADATA
Send initial metadata: one and only one instance MUST be sent for each call, unless the call was canc...
Definition: grpc_types.h:270
grpc::WriteOptions::clear_corked
WriteOptions & clear_corked()
Definition: call_op_set.h:143
config.h
grpc_op::grpc_op_data::send_message
struct grpc_op::grpc_op_data::grpc_op_send_message send_message
grpc::internal::InterceptorBatchMethodsImpl::SetSendMessage
void SetSendMessage(ByteBuffer *buf, const void **msg, bool *fail_send_message, std::function< Status(const void *)> serializer)
Definition: interceptor_common.h:142
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
Log a message.
byte_buffer.h
grpc::internal::Call::call
grpc_call * call() const
Definition: call.h:70
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::metadata
grpc_metadata * metadata
Definition: grpc_types.h:326
grpc::internal::CallOpSet::operator=
CallOpSet & operator=(const CallOpSet &other)
Definition: call_op_set.h:879
grpc_op::grpc_op_data::recv_status_on_client
struct grpc_op::grpc_op_data::grpc_op_recv_status_on_client recv_status_on_client
grpc_compression_level
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:72
grpc_op::grpc_op_data::grpc_op_send_status_from_server::trailing_metadata_count
size_t trailing_metadata_count
Definition: grpc_types.h:343
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::maybe_compression_level
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata::grpc_op_send_initial_metadata_maybe_compression_level maybe_compression_level
call.h
grpc::internal::CallOpSet::FinalizeResult
bool FinalizeResult(void **tag, bool *status) override
Definition: call_op_set.h:905
grpc::internal::CallOpClientRecvStatus
Definition: call_op_set.h:769
grpc::WriteOptions::set_buffer_hint
WriteOptions & set_buffer_hint()
Sets flag indicating that the write may be buffered and need not go out on the wire immediately.
Definition: call_op_set.h:116
grpc_call_error_to_string
const GRPCAPI char * grpc_call_error_to_string(grpc_call_error error)
Convert grpc_call_error values to a string.
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::grpc_op_send_initial_metadata_maybe_compression_level::is_set
uint8_t is_set
Definition: grpc_types.h:330
grpc::internal::CallOpGenericRecvMessage::got_message
bool got_message
Definition: call_op_set.h:540
grpc::internal::CallOpClientSendClose::CallOpClientSendClose
CallOpClientSendClose()
Definition: call_op_set.h:621
grpc::WriteOptions::clear_no_compression
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call_op_set.h:99
grpc_slice_unref
GPRAPI void grpc_slice_unref(grpc_slice s)
Decrement the ref count of s.
grpc::ByteBuffer::Valid
bool Valid() const
Is this ByteBuffer valid?
Definition: byte_buffer.h:159
grpc::internal::CallOpGenericRecvMessage::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:579
grpc::internal::MetadataMap::GetBinaryErrorDetails
std::string GetBinaryErrorDetails()
Definition: metadata_map.h:40
grpc::internal::InterceptorBatchMethodsImpl::RunInterceptors
bool RunInterceptors()
Definition: interceptor_common.h:238
grpc::internal::CallOpRecvInitialMetadata::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:744
grpc::WriteOptions::Clear
void Clear()
Clear all flags.
Definition: call_op_set.h:83
grpc::WriteOptions::is_last_message
bool is_last_message() const
Get value for the flag indicating that this is the last message, and should be coalesced with trailin...
Definition: call_op_set.h:171
grpc::internal::DeserializeFunc::Deserialize
virtual Status Deserialize(ByteBuffer *buf)=0
grpc::internal::CallOpRecvMessage
Definition: call_op_set.h:424
grpc::internal::CallOpSendInitialMetadata::SendInitialMetadata
void SendInitialMetadata(std::multimap< std::string, std::string > *metadata, uint32_t flags)
Definition: call_op_set.h:222
grpc::ByteBuffer::Release
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:144
grpc::internal::FillMetadataArray
grpc_metadata * FillMetadataArray(const std::multimap< std::string, std::string > &metadata, size_t *metadata_count, const std::string &optional_error_details)
Definition: call_op_set.h:54
grpc_op::grpc_op_data::recv_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
grpc::internal::CallOpSendInitialMetadata::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:253
grpc_op::grpc_op_data::grpc_op_send_status_from_server::status_details
grpc_slice * status_details
optional: set to NULL if no details need sending, non-NULL if they do pointer will not be retained pa...
Definition: grpc_types.h:349
grpc::internal::CallOpClientSendClose::ClientSendClose
void ClientSendClose()
Definition: call_op_set.h:623
GRPC_OP_RECV_STATUS_ON_CLIENT
@ GRPC_OP_RECV_STATUS_ON_CLIENT
Receive status on the client: one and only one must be made on the client.
Definition: grpc_types.h:299
slice.h
grpc_op::grpc_op_data::grpc_op_recv_initial_metadata::recv_initial_metadata
grpc_metadata_array * recv_initial_metadata
Definition: grpc_types.h:357
grpc::internal::CallOpRecvInitialMetadata::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:749
grpc::internal::InterceptorBatchMethodsImpl::SetRecvTrailingMetadata
void SetRecvTrailingMetadata(MetadataMap *map)
Definition: interceptor_common.h:179
grpc::internal::CallOpGenericRecvMessage::AllowNoMessage
void AllowNoMessage()
Definition: call_op_set.h:538
grpc::internal::InterceptorBatchMethodsImpl::SetSendInitialMetadata
void SetSendInitialMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:151
grpc::internal::CallOpServerSendStatus::FinishOp
void FinishOp(bool *)
Definition: call_op_set.h:686
grpc::protobuf::util::Status
::absl::Status Status
Definition: config_protobuf.h:97
grpc::WriteOptions::set_no_compression
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call_op_set.h:91
grpc::internal::CallOpSet::set_core_cq_tag
void set_core_cq_tag(void *core_cq_tag)
set_core_cq_tag is used to provide a different core CQ tag than "this".
Definition: call_op_set.h:943
grpc::internal::CallOpSendInitialMetadata::is_set
bool is_set
Definition: call_op_set.h:281
grpc_call_start_batch
GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)
Start a batch of operations defined in the array ops; when complete, post a completion of type 'tag' ...
grpc::internal::CallOpSendMessage::SetFinishInterceptionHookPoint
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:351
grpc::internal::InterceptorBatchMethodsImpl
Definition: interceptor_common.h:36
grpc::Status::error_details
std::string error_details() const
Return the (binary) error details.
Definition: status.h:123
grpc::internal::InterceptorBatchMethodsImpl::SetSendTrailingMetadata
void SetSendTrailingMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:163
grpc::internal::CallOpRecvMessage::RecvMessage
void RecvMessage(R *message)
Definition: call_op_set.h:426
grpc_metadata::key
grpc_slice key
the key, value values are expected to line up with grpc_mdelem: if changing them, update metadata....
Definition: grpc_types.h:214
grpc::internal::CallOpSendInitialMetadata::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:259
GRPC_OP_SEND_CLOSE_FROM_CLIENT
@ GRPC_OP_SEND_CLOSE_FROM_CLIENT
Send a close from the client: one and only one instance MUST be sent from the client,...
Definition: grpc_types.h:279
string_ref.h
grpc::WriteOptions::clear_buffer_hint
WriteOptions & clear_buffer_hint()
Clears flag indicating that the write may be buffered and need not go out on the wire immediately.
Definition: call_op_set.h:125
grpc::internal::InterceptorBatchMethodsImpl::AddInterceptionHookPoint
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
grpc::internal::CallNoOp
Default argument for CallOpSet.
Definition: call_op_set.h:204
grpc::internal::CallOpServerSendStatus::SetHijackingState
void SetHijackingState(InterceptorBatchMethodsImpl *)
Definition: call_op_set.h:705
grpc::internal::CallOpRecvMessage::AllowNoMessage
void AllowNoMessage()
Definition: call_op_set.h:429
grpc::SliceReferencingString
grpc_slice SliceReferencingString(const std::string &str)
Definition: slice.h:132
grpc::internal::CallOpSet::ContinueFinalizeResultAfterInterception
void ContinueFinalizeResultAfterInterception() override
Definition: call_op_set.h:983
grpc::internal::CallOpSendMessage::SetInterceptionHookPoint
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:342
grpc::experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA
@ PRE_RECV_INITIAL_METADATA
The following three are for hijacked clients only.