diff options
author | Yash Tibrewal <yashkt@google.com> | 2019-01-04 17:28:25 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2019-01-04 17:28:25 -0800 |
commit | 059459a9ee082538d79be65dda3a131ef634cef1 (patch) | |
tree | f375e509e895f0d11888c930d44fdaee6f62b8cb /include | |
parent | 6e5eb4e5a3276273d5cf6deb51b1835990ffea0f (diff) | |
parent | 6de81f54bbba10caa79fc72a253c0ea53fa05273 (diff) |
Merge branch 'master' into failhijackedrecv
Diffstat (limited to 'include')
-rw-r--r-- | include/grpcpp/impl/codegen/call_op_set.h | 23 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/interceptor.h | 11 | ||||
-rw-r--r-- | include/grpcpp/impl/codegen/interceptor_common.h | 27 |
3 files changed, 56 insertions, 5 deletions
diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index b8a1c79ddf..1c75560c04 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -326,21 +326,37 @@ class CallOpSendMessage { // Flags are per-message: clear them after use. write_options_.Clear(); } - void FinishOp(bool* status) { send_buf_.Clear(); } + void FinishOp(bool* status) { + if (!send_buf_.Valid()) { + return; + } + if (hijacked_ && failed_send_) { + // Hijacking interceptor failed this Op + *status = false; + } else if (!*status) { + // This Op was passed down to core and the Op failed + failed_send_ = true; + } + } void SetInterceptionHookPoint( InterceptorBatchMethodsImpl* interceptor_methods) { if (!send_buf_.Valid()) return; interceptor_methods->AddInterceptionHookPoint( experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); - interceptor_methods->SetSendMessage(&send_buf_, msg_); + interceptor_methods->SetSendMessage(&send_buf_, msg_, &failed_send_); } void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* interceptor_methods) { + if (send_buf_.Valid()) { + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_SEND_MESSAGE); + } + send_buf_.Clear(); // The contents of the SendMessage value that was previously set // has had its references stolen by core's operations - interceptor_methods->SetSendMessage(nullptr, nullptr); + interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_); } void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { @@ -350,6 +366,7 @@ class CallOpSendMessage { private: const void* msg_ = nullptr; // The original non-serialized message bool hijacked_ = false; + bool failed_send_ = false; ByteBuffer send_buf_; WriteOptions write_options_; }; diff --git a/include/grpcpp/impl/codegen/interceptor.h b/include/grpcpp/impl/codegen/interceptor.h index 9b49983748..a57a3fccbb 100644 --- a/include/grpcpp/impl/codegen/interceptor.h +++ b/include/grpcpp/impl/codegen/interceptor.h @@ -46,9 +46,10 @@ namespace experimental { /// operation has been requested and it is available. POST_RECV means that a /// result is available but has not yet been passed back to the application. enum class InterceptionHookPoints { - /// The first two in this list are for clients and servers + /// The first three in this list are for clients and servers PRE_SEND_INITIAL_METADATA, PRE_SEND_MESSAGE, + POST_SEND_MESSAGE, PRE_SEND_STATUS, // server only PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary /// The following three are for hijacked clients only and can only be @@ -117,6 +118,10 @@ class InterceptorBatchMethods { /// only supported for sync and callback APIs at the present moment. virtual const void* GetSendMessage() = 0; + /// Checks whether the SEND MESSAGE op succeeded. Valid for POST_SEND_MESSAGE + /// interceptions. + virtual bool GetSendMessageStatus() = 0; + /// Returns a modifiable multimap of the initial metadata to be sent. Valid /// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates /// that this field is not valid. @@ -167,6 +172,10 @@ class InterceptorBatchMethods { /// op. This would be a signal to the reader that there will be no more /// messages, or the stream has failed or been cancelled. virtual void FailHijackedRecvMessage() = 0; + + /// On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND + /// MESSAGE op + virtual void FailHijackedSendMessage() = 0; }; /// Interface for an interceptor. Interceptor authors must create a class diff --git a/include/grpcpp/impl/codegen/interceptor_common.h b/include/grpcpp/impl/codegen/interceptor_common.h index d60f9585fc..345127c830 100644 --- a/include/grpcpp/impl/codegen/interceptor_common.h +++ b/include/grpcpp/impl/codegen/interceptor_common.h @@ -83,6 +83,8 @@ class InterceptorBatchMethodsImpl const void* GetSendMessage() override { return orig_send_message_; } + bool GetSendMessageStatus() override { return !*fail_send_message_; } + std::multimap<grpc::string, grpc::string>* GetSendInitialMetadata() override { return send_initial_metadata_; } @@ -112,14 +114,22 @@ class InterceptorBatchMethodsImpl Status* GetRecvStatus() override { return recv_status_; } + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( + experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); + *fail_send_message_ = true; + } + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() override { return recv_trailing_metadata_->map(); } - void SetSendMessage(ByteBuffer* buf, const void* msg) { + void SetSendMessage(ByteBuffer* buf, const void* msg, + bool* fail_send_message) { send_message_ = buf; orig_send_message_ = msg; + fail_send_message_ = fail_send_message; } void SetSendInitialMetadata( @@ -348,6 +358,7 @@ class InterceptorBatchMethodsImpl std::function<void(void)> callback_; ByteBuffer* send_message_ = nullptr; + bool* fail_send_message_ = nullptr; const void* orig_send_message_ = nullptr; std::multimap<grpc::string, grpc::string>* send_initial_metadata_; @@ -402,6 +413,14 @@ class CancelInterceptorBatchMethods return nullptr; } + bool GetSendMessageStatus() override { + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call GetSendMessageStatus on a method which " + "has a Cancel notification"); + return false; + } + const void* GetSendMessage() override { GPR_CODEGEN_ASSERT( false && @@ -481,6 +500,12 @@ class CancelInterceptorBatchMethods "It is illegal to call FailHijackedRecvMessage on a " "method which has a Cancel notification"); } + + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call FailHijackedSendMessage on a " + "method which has a Cancel notification"); + } }; } // namespace internal } // namespace grpc |