aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/secure_credentials.cc15
-rw-r--r--src/cpp/proto/proto_utils.cc21
-rw-r--r--src/cpp/server/secure_server_credentials.cc24
-rw-r--r--src/cpp/server/secure_server_credentials.h2
-rw-r--r--src/cpp/util/time.cc8
5 files changed, 42 insertions, 28 deletions
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index 1693cf740b..8299ebeb8a 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -154,10 +154,10 @@ void MetadataCredentialsPluginWrapper::Destroy(void* wrapper) {
void MetadataCredentialsPluginWrapper::GetMetadata(
void* wrapper, const char* service_url,
grpc_credentials_plugin_metadata_cb cb, void* user_data) {
- GPR_ASSERT(wrapper != nullptr);
+ GPR_ASSERT(wrapper);
MetadataCredentialsPluginWrapper* w =
reinterpret_cast<MetadataCredentialsPluginWrapper*>(wrapper);
- if (w->plugin_ == nullptr) {
+ if (!w->plugin_) {
cb(user_data, NULL, 0, GRPC_STATUS_OK, NULL);
return;
}
@@ -177,11 +177,12 @@ void MetadataCredentialsPluginWrapper::InvokePlugin(
Status status = plugin_->GetMetadata(service_url, &metadata);
std::vector<grpc_metadata> md;
for (auto it = metadata.begin(); it != metadata.end(); ++it) {
- md.push_back({it->first.c_str(),
- it->second.data(),
- it->second.size(),
- 0,
- {{nullptr, nullptr, nullptr, nullptr}}});
+ grpc_metadata md_entry;
+ md_entry.key = it->first.c_str();
+ md_entry.value = it->second.data();
+ md_entry.value_length = it->second.size();
+ md_entry.flags = 0;
+ md.push_back(md_entry);
}
cb(user_data, md.empty() ? nullptr : &md[0], md.size(),
static_cast<grpc_status_code>(status.error_code()),
diff --git a/src/cpp/proto/proto_utils.cc b/src/cpp/proto/proto_utils.cc
index be84c222a0..3c0be58919 100644
--- a/src/cpp/proto/proto_utils.cc
+++ b/src/cpp/proto/proto_utils.cc
@@ -36,6 +36,7 @@
#include <grpc/grpc.h>
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
+#include <grpc/support/log.h>
#include <grpc/support/slice.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/port_platform.h>
@@ -111,7 +112,8 @@ class GrpcBufferReader GRPC_FINAL
if (backup_count_ > 0) {
*data = GPR_SLICE_START_PTR(slice_) + GPR_SLICE_LENGTH(slice_) -
backup_count_;
- *size = backup_count_;
+ GPR_ASSERT(backup_count_ <= INT_MAX);
+ *size = (int)backup_count_;
backup_count_ = 0;
return true;
}
@@ -156,10 +158,19 @@ namespace grpc {
Status SerializeProto(const grpc::protobuf::Message& msg,
grpc_byte_buffer** bp) {
- GrpcBufferWriter writer(bp);
- return msg.SerializeToZeroCopyStream(&writer)
- ? Status::OK
- : Status(StatusCode::INTERNAL, "Failed to serialize message");
+ int byte_size = msg.ByteSize();
+ if (byte_size <= kMaxBufferLength) {
+ gpr_slice slice = gpr_slice_malloc(byte_size);
+ GPR_ASSERT(GPR_SLICE_END_PTR(slice) == msg.SerializeWithCachedSizesToArray(GPR_SLICE_START_PTR(slice)));
+ *bp = grpc_raw_byte_buffer_create(&slice, 1);
+ gpr_slice_unref(slice);
+ return Status::OK;
+ } else {
+ GrpcBufferWriter writer(bp);
+ return msg.SerializeToZeroCopyStream(&writer)
+ ? Status::OK
+ : Status(StatusCode::INTERNAL, "Failed to serialize message");
+ }
}
Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc
index 90afebfd2e..7c828cb125 100644
--- a/src/cpp/server/secure_server_credentials.cc
+++ b/src/cpp/server/secure_server_credentials.cc
@@ -52,7 +52,7 @@ void AuthMetadataProcessorAyncWrapper::Process(
void* wrapper, grpc_auth_context* context, const grpc_metadata* md,
size_t num_md, grpc_process_auth_metadata_done_cb cb, void* user_data) {
auto* w = reinterpret_cast<AuthMetadataProcessorAyncWrapper*>(wrapper);
- if (w->processor_ == nullptr) {
+ if (!w->processor_) {
// Early exit.
cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_OK, nullptr);
return;
@@ -86,20 +86,22 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
std::vector<grpc_metadata> consumed_md;
for (auto it = consumed_metadata.begin(); it != consumed_metadata.end();
++it) {
- consumed_md.push_back({it->first.c_str(),
- it->second.data(),
- it->second.size(),
- 0,
- {{nullptr, nullptr, nullptr, nullptr}}});
+ grpc_metadata md_entry;
+ md_entry.key = it->first.c_str();
+ md_entry.value = it->second.data();
+ md_entry.value_length = it->second.size();
+ md_entry.flags = 0;
+ consumed_md.push_back(md_entry);
}
std::vector<grpc_metadata> response_md;
for (auto it = response_metadata.begin(); it != response_metadata.end();
++it) {
- response_md.push_back({it->first.c_str(),
- it->second.data(),
- it->second.size(),
- 0,
- {{nullptr, nullptr, nullptr, nullptr}}});
+ grpc_metadata md_entry;
+ md_entry.key = it->first.c_str();
+ md_entry.value = it->second.data();
+ md_entry.value_length = it->second.size();
+ md_entry.flags = 0;
+ response_md.push_back(md_entry);
}
auto consumed_md_data = consumed_md.empty() ? nullptr : &consumed_md[0];
auto response_md_data = response_md.empty() ? nullptr : &response_md[0];
diff --git a/src/cpp/server/secure_server_credentials.h b/src/cpp/server/secure_server_credentials.h
index 4f003c6b7e..5460f4a02c 100644
--- a/src/cpp/server/secure_server_credentials.h
+++ b/src/cpp/server/secure_server_credentials.h
@@ -46,7 +46,7 @@ namespace grpc {
class AuthMetadataProcessorAyncWrapper GRPC_FINAL {
public:
- static void Destroy(void *wrapper);
+ static void Destroy(void* wrapper);
static void Process(void* wrapper, grpc_auth_context* context,
const grpc_metadata* md, size_t num_md,
diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc
index b3401eb26b..6157a37745 100644
--- a/src/cpp/util/time.cc
+++ b/src/cpp/util/time.cc
@@ -57,8 +57,8 @@ void Timepoint2Timespec(const system_clock::time_point& from,
return;
}
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
- to->tv_sec = secs.count();
- to->tv_nsec = nsecs.count();
+ to->tv_sec = (time_t)secs.count();
+ to->tv_nsec = (int)nsecs.count();
to->clock_type = GPR_CLOCK_REALTIME;
}
@@ -73,8 +73,8 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from,
return;
}
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
- to->tv_sec = secs.count();
- to->tv_nsec = nsecs.count();
+ to->tv_sec = (time_t)secs.count();
+ to->tv_nsec = (int)nsecs.count();
to->clock_type = GPR_CLOCK_REALTIME;
}