aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
authorGravatar Ken Payson <kpayson@google.com>2017-08-29 09:21:22 -0700
committerGravatar Ken Payson <kpayson@google.com>2017-08-29 09:21:22 -0700
commit567e0f1eb62f361f845d5aba7f7b502e98d5b9d6 (patch)
tree020012b5785b113e70c994dec1cf7ca0937a3bc2 /include/grpc++
parent2921e1ea7dbf423c3d17eea89363b63ae1adacae (diff)
Have write ops take ownership over slices
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/impl/codegen/call.h12
-rw-r--r--include/grpc++/impl/codegen/core_codegen.h1
-rw-r--r--include/grpc++/impl/codegen/core_codegen_interface.h1
3 files changed, 10 insertions, 4 deletions
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h
index 0cb11b4cca..3c30ccdb1e 100644
--- a/include/grpc++/impl/codegen/call.h
+++ b/include/grpc++/impl/codegen/call.h
@@ -272,7 +272,7 @@ class CallOpSendInitialMetadata {
class CallOpSendMessage {
public:
- CallOpSendMessage() : send_buf_(nullptr), own_buf_(false) {}
+ CallOpSendMessage() : send_buf_(nullptr) {}
/// Send \a message using \a options for the write. The \a options are cleared
/// after use.
@@ -295,20 +295,24 @@ class CallOpSendMessage {
write_options_.Clear();
}
void FinishOp(bool* status) {
- if (own_buf_) g_core_codegen_interface->grpc_byte_buffer_destroy(send_buf_);
+ g_core_codegen_interface->grpc_byte_buffer_destroy(send_buf_);
send_buf_ = nullptr;
}
private:
grpc_byte_buffer* send_buf_;
WriteOptions write_options_;
- bool own_buf_;
};
template <class M>
Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) {
write_options_ = options;
- return SerializationTraits<M>::Serialize(message, &send_buf_, &own_buf_);
+ bool own_buf;
+ Status result = SerializationTraits<M>::Serialize(message, &send_buf_, &own_buf);
+ if (!own_buf) {
+ send_buf_ = g_core_codegen_interface->grpc_byte_buffer_copy(send_buf_);
+ }
+ return result;
}
template <class M>
diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h
index 2b15a01845..5f96c8345b 100644
--- a/include/grpc++/impl/codegen/core_codegen.h
+++ b/include/grpc++/impl/codegen/core_codegen.h
@@ -68,6 +68,7 @@ class CoreCodegen final : public CoreCodegenInterface {
void grpc_call_unref(grpc_call* call) override;
virtual void* grpc_call_arena_alloc(grpc_call* call, size_t length) override;
+ grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) override;
void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override;
int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h
index b4c771ac93..7556016f27 100644
--- a/include/grpc++/impl/codegen/core_codegen_interface.h
+++ b/include/grpc++/impl/codegen/core_codegen_interface.h
@@ -74,6 +74,7 @@ class CoreCodegenInterface {
virtual void gpr_cv_signal(gpr_cv* cv) = 0;
virtual void gpr_cv_broadcast(gpr_cv* cv) = 0;
+ virtual grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) = 0;
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) = 0;
virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,