Reduce code paths

pull/24527/head
Vijay Pai 4 years ago
parent 3c9fcac01b
commit 96503e3c72
  1. 48
      include/grpcpp/impl/codegen/call_op_set.h

@ -330,6 +330,7 @@ class CallOpSendMessage {
} }
void FinishOp(bool* status) { void FinishOp(bool* status) {
if (msg_ == nullptr && !send_buf_.Valid()) return; if (msg_ == nullptr && !send_buf_.Valid()) return;
send_buf_.Clear();
if (hijacked_ && failed_send_) { if (hijacked_ && failed_send_) {
// Hijacking interceptor failed this Op // Hijacking interceptor failed this Op
*status = false; *status = false;
@ -378,9 +379,33 @@ class CallOpSendMessage {
template <class M> template <class M>
Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) {
write_options_ = options; write_options_ = options;
// Serialize immediately since we do not have access to the message pointer
bool own_buf;
// TODO(vjpai): Remove the void below when possible
// The void in the template parameter below should not be needed
// (since it should be implicit) but is needed due to an observed
// difference in behavior between clang and gcc for certain internal users
Status result = SerializationTraits<M, void>::Serialize(
message, send_buf_.bbuf_ptr(), &own_buf);
if (!own_buf) {
send_buf_.Duplicate();
}
return result;
}
template <class M>
Status CallOpSendMessage::SendMessage(const M& message) {
return SendMessage(message, WriteOptions());
}
template <class M>
Status CallOpSendMessage::SendMessagePtr(const M* message,
WriteOptions options) {
msg_ = message;
write_options_ = options;
// Store the serializer for later since we have access to the message
serializer_ = [this](const void* message) { serializer_ = [this](const void* message) {
bool own_buf; bool own_buf;
send_buf_.Clear();
// TODO(vjpai): Remove the void below when possible // TODO(vjpai): Remove the void below when possible
// The void in the template parameter below should not be needed // The void in the template parameter below should not be needed
// (since it should be implicit) but is needed due to an observed // (since it should be implicit) but is needed due to an observed
@ -392,31 +417,12 @@ Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) {
} }
return result; return result;
}; };
// Serialize immediately only if we do not have access to the message pointer
if (msg_ == nullptr) {
Status result = serializer_(&message);
serializer_ = nullptr;
return result;
}
return Status(); return Status();
} }
template <class M>
Status CallOpSendMessage::SendMessage(const M& message) {
return SendMessage(message, WriteOptions());
}
template <class M>
Status CallOpSendMessage::SendMessagePtr(const M* message,
WriteOptions options) {
msg_ = message;
return SendMessage(*message, options);
}
template <class M> template <class M>
Status CallOpSendMessage::SendMessagePtr(const M* message) { Status CallOpSendMessage::SendMessagePtr(const M* message) {
msg_ = message; return SendMessagePtr(message, WriteOptions());
return SendMessage(*message, WriteOptions());
} }
template <class R> template <class R>

Loading…
Cancel
Save