From cfd6073a66fda3db150998ef40dbbc76c198c02e Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Wed, 18 Mar 2015 16:27:43 -0700 Subject: Various Windows fixes. -) using dupenv_s instead of getenv_s and calling strdup ourselves. -) few impossible-to-obtain if checks. -) various signed/unsigned casting. -) using time_t instead of time32_t -) checking output of FormatMessage for failures. -) don't redefine _WIN32_WINNT without undefining it first. -) fixed msvc's interlocked casting. -) renamed AddPort to AddListeningPort. -) added protobuf's third_party includes to search path. -) added a missing definition for inet_ntop in mingw32. -) removed useless declarations. --- src/cpp/common/call.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/cpp/common') diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index ebe7deec70..5c26a1ad7c 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -48,7 +48,6 @@ CallOpBuffer::CallOpBuffer() initial_metadata_count_(0), initial_metadata_(nullptr), recv_initial_metadata_(nullptr), - recv_initial_metadata_arr_{0, 0, nullptr}, send_message_(nullptr), send_message_buffer_(nullptr), send_buf_(nullptr), @@ -58,7 +57,6 @@ CallOpBuffer::CallOpBuffer() client_send_close_(false), recv_trailing_metadata_(nullptr), recv_status_(nullptr), - recv_trailing_metadata_arr_{0, 0, nullptr}, status_code_(GRPC_STATUS_OK), status_details_(nullptr), status_details_capacity_(0), @@ -66,7 +64,12 @@ CallOpBuffer::CallOpBuffer() trailing_metadata_count_(0), trailing_metadata_(nullptr), cancelled_buf_(0), - recv_closed_(nullptr) {} + recv_closed_(nullptr) { + memset(&recv_trailing_metadata_arr_, 0, sizeof(recv_trailing_metadata_arr_)); + memset(&recv_initial_metadata_arr_, 0, sizeof(recv_initial_metadata_arr_)); + recv_trailing_metadata_arr_.metadata = nullptr; + recv_initial_metadata_arr_.metadata = nullptr; +} void CallOpBuffer::Reset(void* next_return_tag) { return_tag_ = next_return_tag; -- cgit v1.2.3 From b7b965c842c4cd238b54a1c8e00fba3edb6a3dc7 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Fri, 20 Mar 2015 15:27:51 -0700 Subject: Make Next free of time_point to timespec conversion --- include/grpc++/completion_queue.h | 7 ++++--- src/cpp/common/completion_queue.cc | 17 ++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/cpp/common') diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index f4619a1060..e6a8c6fe55 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -36,6 +36,7 @@ #include #include +#include struct grpc_completion_queue; @@ -88,9 +89,7 @@ class CompletionQueue { // Returns false if the queue is ready for destruction, true if event bool Next(void** tag, bool* ok) { - return ( - AsyncNext(tag, ok, (std::chrono::system_clock::time_point::max)()) != - SHUTDOWN); + return (AsyncNextInternal(tag, ok, gpr_inf_future) != SHUTDOWN); } // Shutdown has to be called, and the CompletionQueue can only be @@ -122,6 +121,8 @@ class CompletionQueue { const grpc::protobuf::Message& request, grpc::protobuf::Message* result); + NextStatus AsyncNextInternal(void** tag, bool* ok, gpr_timespec deadline); + // Wraps grpc_completion_queue_pluck. // Cannot be mixed with calls to Next(). bool Pluck(CompletionQueueTag* tag); diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index fede2da016..cea2d24831 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -36,7 +36,6 @@ #include #include -#include #include "src/cpp/util/time.h" namespace grpc { @@ -57,15 +56,12 @@ class EventDeleter { } }; -CompletionQueue::NextStatus -CompletionQueue::AsyncNext(void** tag, bool* ok, - std::chrono::system_clock::time_point deadline) { +CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( + void** tag, bool* ok, gpr_timespec deadline) { std::unique_ptr ev; - gpr_timespec gpr_deadline; - Timepoint2Timespec(deadline, &gpr_deadline); for (;;) { - ev.reset(grpc_completion_queue_next(cq_, gpr_deadline)); + ev.reset(grpc_completion_queue_next(cq_, deadline)); if (!ev) { /* got a NULL back because deadline passed */ return TIMEOUT; } @@ -81,6 +77,13 @@ CompletionQueue::AsyncNext(void** tag, bool* ok, } } +CompletionQueue::NextStatus CompletionQueue::AsyncNext( + void** tag, bool* ok, std::chrono::system_clock::time_point deadline) { + gpr_timespec gpr_deadline; + Timepoint2Timespec(deadline, &gpr_deadline); + return AsyncNextInternal(tag, ok, gpr_deadline); +} + bool CompletionQueue::Pluck(CompletionQueueTag* tag) { std::unique_ptr ev; -- cgit v1.2.3 From 82dd80abc6fffab0f0bcff406dbd0750a6a45b37 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 24 Mar 2015 10:36:08 -0700 Subject: Elminate range-based fors and work around some other limitations in older compilers --- src/compiler/python_generator.cc | 22 +++++++++------ src/cpp/common/call.cc | 2 +- src/cpp/server/secure_server_credentials.cc | 9 ++++-- src/cpp/server/server.cc | 4 +-- src/cpp/server/server_builder.cc | 18 ++++++------ src/cpp/server/thread_pool.cc | 4 +-- test/cpp/end2end/generic_end2end_test.cc | 4 +-- test/cpp/qps/client_async.cc | 11 ++++---- test/cpp/qps/driver.cc | 44 ++++++++++++++--------------- test/cpp/qps/server_async.cc | 4 +-- test/cpp/qps/stats.h | 4 +-- 11 files changed, 69 insertions(+), 57 deletions(-) (limited to 'src/cpp/common') diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc index c2d4cda31a..748417e477 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -309,17 +309,20 @@ bool PrintServerFactory(const grpc::string& package_qualified_service_name, make_pair(method->name(), output_message_module_and_class)); } out->Print("method_service_descriptions = {\n"); - for (auto& name_and_description_constructor : - method_description_constructors) { + for (auto name_and_description_constructor = + method_description_constructors.begin(); + name_and_description_constructor != + method_description_constructors.end(); + name_and_description_constructor++) { IndentScope raii_descriptions_indent(out); - const grpc::string method_name = name_and_description_constructor.first; + const grpc::string method_name = name_and_description_constructor->first; auto input_message_module_and_class = input_message_modules_and_classes.find(method_name); auto output_message_module_and_class = output_message_modules_and_classes.find(method_name); out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method", method_name, "Constructor", - name_and_description_constructor.second); + name_and_description_constructor->second); { IndentScope raii_description_arguments_indent(out); out->Print("servicer.$Method$,\n", "Method", method_name); @@ -387,17 +390,20 @@ bool PrintStubFactory(const grpc::string& package_qualified_service_name, make_pair(method->name(), output_message_module_and_class)); } out->Print("method_invocation_descriptions = {\n"); - for (auto& name_and_description_constructor : - method_description_constructors) { + for (auto name_and_description_constructor = + method_description_constructors.begin(); + name_and_description_constructor != + method_description_constructors.end(); + name_and_description_constructor++) { IndentScope raii_descriptions_indent(out); - const grpc::string method_name = name_and_description_constructor.first; + const grpc::string method_name = name_and_description_constructor->first; auto input_message_module_and_class = input_message_modules_and_classes.find(method_name); auto output_message_module_and_class = output_message_modules_and_classes.find(method_name); out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method", method_name, "Constructor", - name_and_description_constructor.second); + name_and_description_constructor->second); { IndentScope raii_description_arguments_indent(out); out->Print( diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index 5c26a1ad7c..311e0d01b0 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -148,7 +148,7 @@ void FillMetadataMap(grpc_metadata_array* arr, // TODO(yangg) handle duplicates? metadata->insert(std::pair( arr->metadata[i].key, - {arr->metadata[i].value, arr->metadata[i].value_length})); + grpc::string(arr->metadata[i].value, arr->metadata[i].value_length))); } grpc_metadata_array_destroy(arr); grpc_metadata_array_init(arr); diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 88f7a9b1a9..49d69a3fb9 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -59,9 +59,12 @@ class SecureServerCredentials GRPC_FINAL : public ServerCredentials { std::shared_ptr SslServerCredentials( const SslServerCredentialsOptions& options) { std::vector pem_key_cert_pairs; - for (const auto& key_cert_pair : options.pem_key_cert_pairs) { - pem_key_cert_pairs.push_back( - {key_cert_pair.private_key.c_str(), key_cert_pair.cert_chain.c_str()}); + for (auto key_cert_pair = options.pem_key_cert_pairs.begin(); + key_cert_pair != options.pem_key_cert_pairs.end(); + key_cert_pair++) { + grpc_ssl_pem_key_cert_pair p = {key_cert_pair->private_key.c_str(), + key_cert_pair->cert_chain.c_str()}; + pem_key_cert_pairs.push_back(p); } grpc_server_credentials* c_creds = grpc_ssl_server_credentials_create( options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(), diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 5a4ca6915a..8e6a6cf40a 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -247,8 +247,8 @@ bool Server::Start() { // Start processing rpcs. if (!sync_methods_.empty()) { - for (auto& m : sync_methods_) { - m.Request(server_); + for (auto m = sync_methods_.begin(); m != sync_methods_.end(); m++) { + m->Request(server_); } ScheduleCallback(); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 58bf9d937f..c5e115f396 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -86,24 +86,26 @@ std::unique_ptr ServerBuilder::BuildAndStart() { thread_pool_owned = true; } std::unique_ptr server(new Server(thread_pool_, thread_pool_owned)); - for (auto* service : services_) { - if (!server->RegisterService(service)) { + for (auto service = services_.begin(); service != services_.end(); + service++) { + if (!server->RegisterService(*service)) { return nullptr; } } - for (auto* service : async_services_) { - if (!server->RegisterAsyncService(service)) { + for (auto service = async_services_.begin(); + service != async_services_.end(); service++) { + if (!server->RegisterAsyncService(*service)) { return nullptr; } } if (generic_service_) { server->RegisterAsyncGenericService(generic_service_); } - for (auto& port : ports_) { - int r = server->AddListeningPort(port.addr, port.creds.get()); + for (auto port = ports_.begin(); port != ports_.end(); port++) { + int r = server->AddListeningPort(port->addr, port->creds.get()); if (!r) return nullptr; - if (port.selected_port != nullptr) { - *port.selected_port = r; + if (port->selected_port != nullptr) { + *port->selected_port = r; } } if (!server->Start()) { diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc index d3013b806c..2c0f4da812 100644 --- a/src/cpp/server/thread_pool.cc +++ b/src/cpp/server/thread_pool.cc @@ -66,8 +66,8 @@ ThreadPool::~ThreadPool() { shutdown_ = true; cv_.notify_all(); } - for (auto& t : threads_) { - t.join(); + for (auto t = threads_.begin(); t != threads_.end(); t++) { + t->join(); } } diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 711f1b9540..11998a7cb7 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -83,8 +83,8 @@ bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) { buffer->Dump(&slices); grpc::string buf; buf.reserve(buffer->Length()); - for (const Slice& s : slices) { - buf.append(reinterpret_cast(s.begin()), s.size()); + for (auto s = slices.begin(); s != slices.end(); s++) { + buf.append(reinterpret_cast(s->begin()), s->size()); } return message->ParseFromString(buf); } diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 526f37a1fd..f995a63f49 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -144,7 +144,8 @@ class AsyncClient GRPC_FINAL : public Client { int t = 0; for (int i = 0; i < config.outstanding_rpcs_per_channel(); i++) { - for (auto& channel : channels_) { + for (auto channel = channels_.begin(); channel != channels_.end(); + channel++) { auto* cq = cli_cqs_[t].get(); t = (t + 1) % cli_cqs_.size(); auto start_req = [cq](TestService::Stub* stub, grpc::ClientContext* ctx, @@ -152,7 +153,7 @@ class AsyncClient GRPC_FINAL : public Client { return stub->AsyncUnaryCall(ctx, request, cq, tag); }; - TestService::Stub* stub = channel.get_stub(); + TestService::Stub* stub = channel->get_stub(); const SimpleRequest& request = request_; new ClientRpcContextUnaryImpl( stub, request, start_req, check_done); @@ -165,11 +166,11 @@ class AsyncClient GRPC_FINAL : public Client { ~AsyncClient() GRPC_OVERRIDE { EndThreads(); - for (auto& cq : cli_cqs_) { - cq->Shutdown(); + for (auto cq = cli_cqs_.begin(); cq != cli_cqs_.end(); cq++) { + (*cq)->Shutdown(); void* got_tag; bool ok; - while (cq->Next(&got_tag, &ok)) { + while ((*cq)->Next(&got_tag, &ok)) { delete ClientRpcContext::detag(got_tag); } } diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index d29ca1de94..64a53496ae 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -154,19 +154,19 @@ ScenarioResult RunScenario(const ClientConfig& initial_client_config, server_mark.mutable_mark(); ClientArgs client_mark; client_mark.mutable_mark(); - for (auto& server : servers) { - GPR_ASSERT(server.stream->Write(server_mark)); + for (auto server = servers.begin(); server != servers.end(); server++) { + GPR_ASSERT(server->stream->Write(server_mark)); } - for (auto& client : clients) { - GPR_ASSERT(client.stream->Write(client_mark)); + for (auto client = clients.begin(); client != clients.end(); client++) { + GPR_ASSERT(client->stream->Write(client_mark)); } ServerStatus server_status; ClientStatus client_status; - for (auto& server : servers) { - GPR_ASSERT(server.stream->Read(&server_status)); + for (auto server = servers.begin(); server != servers.end(); server++) { + GPR_ASSERT(server->stream->Read(&server_status)); } - for (auto& client : clients) { - GPR_ASSERT(client.stream->Read(&client_status)); + for (auto client = clients.begin(); client != clients.end(); client++) { + GPR_ASSERT(client->stream->Read(&client_status)); } // Wait some time @@ -176,33 +176,33 @@ ScenarioResult RunScenario(const ClientConfig& initial_client_config, // Finish a run ScenarioResult result; gpr_log(GPR_INFO, "Finishing"); - for (auto& server : servers) { - GPR_ASSERT(server.stream->Write(server_mark)); + for (auto server = servers.begin(); server != servers.end(); server++) { + GPR_ASSERT(server->stream->Write(server_mark)); } - for (auto& client : clients) { - GPR_ASSERT(client.stream->Write(client_mark)); + for (auto client = clients.begin(); client != clients.end(); client++) { + GPR_ASSERT(client->stream->Write(client_mark)); } - for (auto& server : servers) { - GPR_ASSERT(server.stream->Read(&server_status)); + for (auto server = servers.begin(); server != servers.end(); server++) { + GPR_ASSERT(server->stream->Read(&server_status)); const auto& stats = server_status.stats(); result.server_resources.push_back(ResourceUsage{ stats.time_elapsed(), stats.time_user(), stats.time_system()}); } - for (auto& client : clients) { - GPR_ASSERT(client.stream->Read(&client_status)); + for (auto client = clients.begin(); client != clients.end(); client++) { + GPR_ASSERT(client->stream->Read(&client_status)); const auto& stats = client_status.stats(); result.latencies.MergeProto(stats.latencies()); result.client_resources.push_back(ResourceUsage{ stats.time_elapsed(), stats.time_user(), stats.time_system()}); } - for (auto& client : clients) { - GPR_ASSERT(client.stream->WritesDone()); - GPR_ASSERT(client.stream->Finish().IsOk()); + for (auto client = clients.begin(); client != clients.end(); client++) { + GPR_ASSERT(client->stream->WritesDone()); + GPR_ASSERT(client->stream->Finish().IsOk()); } - for (auto& server : servers) { - GPR_ASSERT(server.stream->WritesDone()); - GPR_ASSERT(server.stream->Finish().IsOk()); + for (auto server = servers.begin(); server != servers.end(); server++) { + GPR_ASSERT(server->stream->WritesDone()); + GPR_ASSERT(server->stream->Finish().IsOk()); } return result; } diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 586b6e7abe..7b81bd35a2 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -105,8 +105,8 @@ class AsyncQpsServerTest : public Server { ~AsyncQpsServerTest() { server_->Shutdown(); srv_cq_.Shutdown(); - for (auto& thr : threads_) { - thr.join(); + for (auto thr = threads_.begin(); thr != threads_.end(); thr++) { + thr->join(); } while (!contexts_.empty()) { delete contexts_.front(); diff --git a/test/cpp/qps/stats.h b/test/cpp/qps/stats.h index ca59390ad7..82dc03e3da 100644 --- a/test/cpp/qps/stats.h +++ b/test/cpp/qps/stats.h @@ -43,8 +43,8 @@ namespace testing { template double sum(const T& container, F functor) { double r = 0; - for (auto v : container) { - r += functor(v); + for (auto v = container.begin(); v != container.end(); v++) { + r += functor(*v); } return r; } -- cgit v1.2.3