From 8ae189bbab2a401f93ce5109a746ea46b4cc55c8 Mon Sep 17 00:00:00 2001 From: zeliard Date: Thu, 23 Apr 2015 16:26:05 +0900 Subject: 64bit support on Windows --- src/core/support/alloc.c | 5 +++++ src/core/support/slice_buffer.c | 2 +- src/core/support/time.c | 4 ++-- src/core/support/time_win32.c | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/support/alloc.c b/src/core/support/alloc.c index a19a0141d4..acd2432efb 100644 --- a/src/core/support/alloc.c +++ b/src/core/support/alloc.c @@ -55,7 +55,12 @@ void *gpr_realloc(void *p, size_t size) { } void *gpr_malloc_aligned(size_t size, size_t alignment_log) { +#if defined(GPR_WIN32) && defined(GPR_ARCH_64) + size_t alignment = 1ULL << alignment_log; +#else size_t alignment = 1 << alignment_log; +#endif + size_t extra = alignment - 1 + sizeof(void *); void *p = gpr_malloc(size + extra); void **ret = (void **)(((gpr_uintptr)p + extra) & ~(alignment - 1)); diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 3b1daa07c5..a26dc1eefb 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -117,7 +117,7 @@ void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice s) { s.data.inlined.bytes, s.data.inlined.length); back->data.inlined.length += s.data.inlined.length; } else { - size_t cp1 = GPR_SLICE_INLINED_SIZE - back->data.inlined.length; + gpr_uint32 cp1 = GPR_SLICE_INLINED_SIZE - back->data.inlined.length; memcpy(back->data.inlined.bytes + back->data.inlined.length, s.data.inlined.bytes, cp1); back->data.inlined.length = GPR_SLICE_INLINED_SIZE; diff --git a/src/core/support/time.c b/src/core/support/time.c index 7dbf95059f..9af81b742d 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -237,7 +237,7 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { gpr_int32 gpr_time_to_millis(gpr_timespec t) { if (t.tv_sec >= 2147483) { if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) { - return 2147483 * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS; + return 2147483 * GPR_MS_PER_SEC + (gpr_int32)t.tv_nsec / GPR_NS_PER_MS; } return 2147483647; } else if (t.tv_sec <= -2147483) { @@ -245,7 +245,7 @@ gpr_int32 gpr_time_to_millis(gpr_timespec t) { care?) */ return -2147483647; } else { - return t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS; + return (gpr_int32)t.tv_sec * GPR_MS_PER_SEC + (gpr_int32)t.tv_nsec / GPR_NS_PER_MS; } } diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index 539470bccf..0ca84565a2 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -64,7 +64,7 @@ void gpr_sleep_until(gpr_timespec until) { } delta = gpr_time_sub(until, now); - sleep_millis = delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; + sleep_millis = (DWORD)delta.tv_sec * GPR_MS_PER_SEC + (DWORD)delta.tv_nsec / GPR_NS_PER_MS; Sleep(sleep_millis); } } -- cgit v1.2.3 From 81f750e7b2dc609e99f6568678a1fe877703ca85 Mon Sep 17 00:00:00 2001 From: zeliard Date: Mon, 27 Apr 2015 14:41:02 +0900 Subject: undo time_t type casting --- include/grpc/support/time.h | 4 ---- src/core/support/alloc.c | 7 +------ src/core/support/slice_buffer.c | 2 +- src/core/support/time.c | 2 +- src/core/support/time_win32.c | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) (limited to 'src/core') diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h index 3e40f2b81e..1fd3181859 100644 --- a/include/grpc/support/time.h +++ b/include/grpc/support/time.h @@ -47,11 +47,7 @@ extern "C" { typedef struct gpr_timespec { time_t tv_sec; -#if defined(GPR_WIN32) && defined(GPR_ARCH_64) - __int64 tv_nsec; -#else int tv_nsec; -#endif } gpr_timespec; /* Time constants. */ diff --git a/src/core/support/alloc.c b/src/core/support/alloc.c index acd2432efb..d2ed82e771 100644 --- a/src/core/support/alloc.c +++ b/src/core/support/alloc.c @@ -55,12 +55,7 @@ void *gpr_realloc(void *p, size_t size) { } void *gpr_malloc_aligned(size_t size, size_t alignment_log) { -#if defined(GPR_WIN32) && defined(GPR_ARCH_64) - size_t alignment = 1ULL << alignment_log; -#else - size_t alignment = 1 << alignment_log; -#endif - + size_t alignment = ((size_t)1) << alignment_log; size_t extra = alignment - 1 + sizeof(void *); void *p = gpr_malloc(size + extra); void **ret = (void **)(((gpr_uintptr)p + extra) & ~(alignment - 1)); diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index a26dc1eefb..3b1daa07c5 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -117,7 +117,7 @@ void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice s) { s.data.inlined.bytes, s.data.inlined.length); back->data.inlined.length += s.data.inlined.length; } else { - gpr_uint32 cp1 = GPR_SLICE_INLINED_SIZE - back->data.inlined.length; + size_t cp1 = GPR_SLICE_INLINED_SIZE - back->data.inlined.length; memcpy(back->data.inlined.bytes + back->data.inlined.length, s.data.inlined.bytes, cp1); back->data.inlined.length = GPR_SLICE_INLINED_SIZE; diff --git a/src/core/support/time.c b/src/core/support/time.c index 9af81b742d..60a3c23422 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -237,7 +237,7 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { gpr_int32 gpr_time_to_millis(gpr_timespec t) { if (t.tv_sec >= 2147483) { if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) { - return 2147483 * GPR_MS_PER_SEC + (gpr_int32)t.tv_nsec / GPR_NS_PER_MS; + return 2147483 * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS; } return 2147483647; } else if (t.tv_sec <= -2147483) { diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index 0ca84565a2..f4443b5c2d 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -64,7 +64,7 @@ void gpr_sleep_until(gpr_timespec until) { } delta = gpr_time_sub(until, now); - sleep_millis = (DWORD)delta.tv_sec * GPR_MS_PER_SEC + (DWORD)delta.tv_nsec / GPR_NS_PER_MS; + sleep_millis = (DWORD)delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; Sleep(sleep_millis); } } -- cgit v1.2.3 From 179be50ad39a7c0a19ab38b5ff865d656facc3a9 Mon Sep 17 00:00:00 2001 From: zeliard Date: Mon, 27 Apr 2015 14:52:00 +0900 Subject: merge VS solutions file from upstream master --- include/grpc++/client_context.h | 23 ++-- include/grpc++/completion_queue.h | 18 ++-- include/grpc++/credentials.h | 22 ++-- include/grpc++/impl/grpc_library.h | 50 +++++++++ include/grpc++/server.h | 4 +- include/grpc++/server_context.h | 13 ++- include/grpc++/stream.h | 2 +- include/grpc++/time.h | 106 +++++++++++++++++++ src/core/support/histogram.c | 2 +- src/cpp/client/channel.cc | 5 +- src/cpp/client/channel.h | 4 +- src/cpp/client/client_context.cc | 15 +-- src/cpp/client/secure_credentials.cc | 12 +-- src/cpp/common/completion_queue.cc | 12 +-- src/cpp/server/server.cc | 4 +- src/cpp/server/server_context.cc | 8 +- src/cpp/util/time.cc | 7 +- src/cpp/util/time.h | 51 --------- vsprojects/grpc++/grpc++.vcxproj | 5 +- vsprojects/grpc++/grpc++.vcxproj.filters | 9 +- vsprojects/grpc.sln | 44 +++----- .../grpc_test_util_unsecure.vcxproj | 117 +++++++++++++++++++++ 22 files changed, 374 insertions(+), 159 deletions(-) create mode 100644 include/grpc++/impl/grpc_library.h create mode 100644 include/grpc++/time.h delete mode 100644 src/cpp/util/time.h create mode 100644 vsprojects/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj (limited to 'src/core') diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 4e7f5a7be0..19630c9b54 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -34,15 +34,13 @@ #ifndef GRPCXX_CLIENT_CONTEXT_H #define GRPCXX_CLIENT_CONTEXT_H -#include #include #include #include #include #include - -using std::chrono::system_clock; +#include struct grpc_call; struct grpc_completion_queue; @@ -87,8 +85,19 @@ class ClientContext { return trailing_metadata_; } - void set_absolute_deadline(const system_clock::time_point& deadline); - system_clock::time_point absolute_deadline(); + template + void set_deadline(const T& deadline) { + TimePoint deadline_tp(deadline); + deadline_ = deadline_tp.raw_time(); + } + +#ifndef GRPC_CXX0X_NO_CHRONO + std::chrono::system_clock::time_point deadline() { + return Timespec2Timepoint(deadline_); + } +#endif // !GRPC_CXX0X_NO_CHRONO + + gpr_timespec raw_deadline() { return deadline_; } void set_authority(const grpc::string& authority) { authority_ = authority; } @@ -125,14 +134,12 @@ class ClientContext { grpc_completion_queue* cq() { return cq_; } void set_cq(grpc_completion_queue* cq) { cq_ = cq; } - gpr_timespec RawDeadline() { return absolute_deadline_; } - grpc::string authority() { return authority_; } bool initial_metadata_received_; grpc_call* call_; grpc_completion_queue* cq_; - gpr_timespec absolute_deadline_; + gpr_timespec deadline_; grpc::string authority_; std::multimap send_initial_metadata_; std::multimap recv_initial_metadata_; diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index e6a8c6fe55..5c2b1cce93 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -34,9 +34,10 @@ #ifndef GRPCXX_COMPLETION_QUEUE_H #define GRPCXX_COMPLETION_QUEUE_H -#include -#include #include +#include +#include +#include struct grpc_completion_queue; @@ -71,21 +72,24 @@ class CompletionQueueTag { }; // grpc_completion_queue wrapper class -class CompletionQueue { +class CompletionQueue : public GrpcLibrary { public: CompletionQueue(); explicit CompletionQueue(grpc_completion_queue* take); - ~CompletionQueue(); + ~CompletionQueue() GRPC_OVERRIDE; // Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT }; // Nonblocking (until deadline) read from queue. // Cannot rely on result of tag or ok if return is TIMEOUT - NextStatus AsyncNext(void** tag, bool* ok, - std::chrono::system_clock::time_point deadline); + template + NextStatus AsyncNext(void** tag, bool* ok, const T& deadline) { + TimePoint deadline_tp(deadline); + return AsyncNextInternal(tag, ok, deadline_tp.raw_time()); + } - // Blocking (until deadline) read from queue. + // Blocking read from queue. // Returns false if the queue is ready for destruction, true if event bool Next(void** tag, bool* ok) { diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h index 2ac3eec95c..61c4094691 100644 --- a/include/grpc++/credentials.h +++ b/include/grpc++/credentials.h @@ -34,19 +34,19 @@ #ifndef GRPCXX_CREDENTIALS_H #define GRPCXX_CREDENTIALS_H -#include #include #include +#include namespace grpc { class ChannelArguments; class ChannelInterface; class SecureCredentials; -class Credentials { +class Credentials : public GrpcLibrary { public: - virtual ~Credentials(); + ~Credentials() GRPC_OVERRIDE; protected: friend std::unique_ptr CompositeCredentials( @@ -98,20 +98,20 @@ std::unique_ptr ComputeEngineCredentials(); // Builds service account credentials. // json_key is the JSON key string containing the client's private key. // scope is a space-delimited list of the requested permissions. -// token_lifetime is the lifetime of each token acquired through this service -// account credentials. It should be positive and should not exceed -// grpc_max_auth_token_lifetime or will be cropped to this value. +// token_lifetime_seconds is the lifetime in seconds of each token acquired +// through this service account credentials. It should be positive and should +// not exceed grpc_max_auth_token_lifetime or will be cropped to this value. std::unique_ptr ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - std::chrono::seconds token_lifetime); + long token_lifetime_seconds); // Builds JWT credentials. // json_key is the JSON key string containing the client's private key. -// token_lifetime is the lifetime of each Json Web Token (JWT) created with -// this credentials. It should not exceed grpc_max_auth_token_lifetime or -// will be cropped to this value. +// token_lifetime_seconds is the lifetime in seconds of each Json Web Token +// (JWT) created with this credentials. It should not exceed +// grpc_max_auth_token_lifetime or will be cropped to this value. std::unique_ptr JWTCredentials( - const grpc::string& json_key, std::chrono::seconds token_lifetime); + const grpc::string& json_key, long token_lifetime_seconds); // Builds refresh token credentials. // json_refresh_token is the JSON string containing the refresh token along diff --git a/include/grpc++/impl/grpc_library.h b/include/grpc++/impl/grpc_library.h new file mode 100644 index 0000000000..f9fa677901 --- /dev/null +++ b/include/grpc++/impl/grpc_library.h @@ -0,0 +1,50 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPCXX_IMPL_GRPC_LIBRARY_H +#define GRPCXX_IMPL_GRPC_LIBRARY_H + +#include + +namespace grpc { + +class GrpcLibrary { + public: + GrpcLibrary() { grpc_init(); } + virtual ~GrpcLibrary() { grpc_shutdown(); } +}; + +} // namespace grpc + + +#endif // GRPCXX_IMPL_GRPC_LIBRARY_H diff --git a/include/grpc++/server.h b/include/grpc++/server.h index eb50611573..0ae27e9e9f 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,8 @@ class ServerCredentials; class ThreadPoolInterface; // Currently it only supports handling rpcs in a single thread. -class Server GRPC_FINAL : private CallHook, +class Server GRPC_FINAL : public GrpcLibrary, + private CallHook, private AsynchronousService::DispatchImpl { public: ~Server(); diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 9e3b80c641..a62babd931 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -34,10 +34,11 @@ #ifndef GRPCXX_SERVER_CONTEXT_H #define GRPCXX_SERVER_CONTEXT_H -#include #include +#include #include +#include struct gpr_timespec; struct grpc_metadata; @@ -71,9 +72,13 @@ class ServerContext { ServerContext(); // for async calls ~ServerContext(); - std::chrono::system_clock::time_point absolute_deadline() { - return deadline_; +#ifndef GRPC_CXX0X_NO_CHRONO + std::chrono::system_clock::time_point deadline() { + return Timespec2Timepoint(deadline_); } +#endif // !GRPC_CXX0X_NO_CHRONO + + gpr_timespec raw_deadline() { return deadline_; } void AddInitialMetadata(const grpc::string& key, const grpc::string& value); void AddTrailingMetadata(const grpc::string& key, const grpc::string& value); @@ -110,7 +115,7 @@ class ServerContext { CompletionOp* completion_op_; - std::chrono::system_clock::time_point deadline_; + gpr_timespec deadline_; grpc_call* call_; CompletionQueue* cq_; bool sent_initial_metadata_; diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index 7625bcc38d..6647e345c0 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -173,7 +173,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface, buf.AddRecvMessage(response_); buf.AddClientRecvStatus(context_, &status); call_.PerformOps(&buf); - GPR_ASSERT(cq_.Pluck(&buf) && buf.got_message); + GPR_ASSERT(cq_.Pluck(&buf)); return status; } diff --git a/include/grpc++/time.h b/include/grpc++/time.h new file mode 100644 index 0000000000..f9b2ce5cab --- /dev/null +++ b/include/grpc++/time.h @@ -0,0 +1,106 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPCXX_TIME_H +#define GRPCXX_TIME_H + +#include + +namespace grpc { + +/* If you are trying to use CompletionQueue::AsyncNext with a time class that + isn't either gpr_timespec or std::chrono::system_clock::time_point, you + will most likely be looking at this comment as your compiler will have + fired an error below. In order to fix this issue, you have two potential + solutions: + + 1. Use gpr_timespec or std::chrono::system_clock::time_point instead + 2. Specialize the TimePoint class with whichever time class that you + want to use here. See below for two examples of how to do this. + */ + +template +class TimePoint { + public: + TimePoint(const T& time) { + you_need_a_specialization_of_TimePoint(); + } + gpr_timespec raw_time() { + gpr_timespec t; + return t; + } + private: + void you_need_a_specialization_of_TimePoint(); +}; + +template<> +class TimePoint { + public: + TimePoint(const gpr_timespec& time) : time_(time) { } + gpr_timespec raw_time() { return time_; } + private: + gpr_timespec time_; +}; + +} // namespace grpc + +#ifndef GRPC_CXX0X_NO_CHRONO + +#include + +#include + +namespace grpc { + +// from and to should be absolute time. +void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, + gpr_timespec* to); + +std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); + +template <> +class TimePoint { + public: + TimePoint(const std::chrono::system_clock::time_point& time) { + Timepoint2Timespec(time, &time_); + } + gpr_timespec raw_time() const { return time_; } + private: + gpr_timespec time_; +}; + +} // namespace grpc + +#endif // !GRPC_CXX0X_NO_CHRONO + +#endif // GRPCXX_TIME_H diff --git a/src/core/support/histogram.c b/src/core/support/histogram.c index ed344b43e8..673affde71 100644 --- a/src/core/support/histogram.c +++ b/src/core/support/histogram.c @@ -76,7 +76,7 @@ static size_t bucket_for_unchecked(gpr_histogram *h, double x) { /* bounds checked version of the above */ static size_t bucket_for(gpr_histogram *h, double x) { - size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible)); + size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 1.0, h->max_possible)); GPR_ASSERT(bucket < h->num_buckets); return bucket; } diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 478f223322..ba8882278f 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -33,7 +33,6 @@ #include "src/cpp/client/channel.h" -#include #include #include @@ -65,12 +64,12 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, method.channel_tag() ? grpc_channel_create_registered_call(c_channel_, cq->cq(), method.channel_tag(), - context->RawDeadline()) + context->raw_deadline()) : grpc_channel_create_call(c_channel_, cq->cq(), method.name(), context->authority().empty() ? target_.c_str() : context->authority().c_str(), - context->RawDeadline()); + context->raw_deadline()); GRPC_TIMER_MARK(CALL_CREATED, c_call); context->set_call(c_call); return Call(c_call, this, cq); diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index aaf4dbe10d..cd239247c8 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -38,6 +38,7 @@ #include #include +#include struct grpc_channel; @@ -49,7 +50,8 @@ class CompletionQueue; class Credentials; class StreamContextInterface; -class Channel GRPC_FINAL : public ChannelInterface { +class Channel GRPC_FINAL : public GrpcLibrary, + public ChannelInterface { public: Channel(const grpc::string& target, grpc_channel* c_channel); ~Channel() GRPC_OVERRIDE; diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index de9f8c7201..70c9cb4c3b 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -34,9 +34,7 @@ #include #include -#include "src/cpp/util/time.h" - -using std::chrono::system_clock; +#include namespace grpc { @@ -44,7 +42,7 @@ ClientContext::ClientContext() : initial_metadata_received_(false), call_(nullptr), cq_(nullptr), - absolute_deadline_(gpr_inf_future) {} + deadline_(gpr_inf_future) {} ClientContext::~ClientContext() { if (call_) { @@ -64,15 +62,6 @@ ClientContext::~ClientContext() { } } -void ClientContext::set_absolute_deadline( - const system_clock::time_point& deadline) { - Timepoint2Timespec(deadline, &absolute_deadline_); -} - -system_clock::time_point ClientContext::absolute_deadline() { - return Timespec2Timepoint(absolute_deadline_); -} - void ClientContext::AddMetadata(const grpc::string& meta_key, const grpc::string& meta_value) { send_initial_metadata_.insert(std::make_pair(meta_key, meta_value)); diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 0a73b2c0f6..48bf7430b2 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -81,27 +81,27 @@ std::unique_ptr ComputeEngineCredentials() { // Builds service account credentials. std::unique_ptr ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 0) { + long token_lifetime_seconds) { + if (token_lifetime_seconds <= 0) { gpr_log(GPR_ERROR, "Trying to create ServiceAccountCredentials " "with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); return WrapCredentials(grpc_service_account_credentials_create( json_key.c_str(), scope.c_str(), lifetime)); } // Builds JWT credentials. std::unique_ptr JWTCredentials( - const grpc::string& json_key, std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 0) { + const grpc::string& json_key, long token_lifetime_seconds) { + if (token_lifetime_seconds <= 0) { gpr_log(GPR_ERROR, "Trying to create JWTCredentials with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); return WrapCredentials( grpc_jwt_credentials_create(json_key.c_str(), lifetime)); } diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index cea2d24831..07122db4a5 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -36,7 +36,7 @@ #include #include -#include "src/cpp/util/time.h" +#include namespace grpc { @@ -77,13 +77,6 @@ CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( } } -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; @@ -92,7 +85,8 @@ bool CompletionQueue::Pluck(CompletionQueueTag* tag) { void* ignored = tag; GPR_ASSERT(tag->FinalizeResult(&ignored, &ok)); GPR_ASSERT(ignored == tag); - return ok; + // Ignore mutations by FinalizeResult: Pluck returns the C API status + return ev->data.op_complete == GRPC_OP_OK; } void CompletionQueue::TryPluck(CompletionQueueTag* tag) { diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index b3cd1fdd74..1d39378595 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -45,10 +45,10 @@ #include #include #include +#include #include "src/core/profiling/timers.h" #include "src/cpp/proto/proto_utils.h" -#include "src/cpp/util/time.h" namespace grpc { @@ -353,7 +353,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { ServerContext* ctx = ctx_ ? ctx_ : generic_ctx_; GPR_ASSERT(ctx); if (*status) { - ctx->deadline_ = Timespec2Timepoint(call_details_.deadline); + ctx->deadline_ = call_details_.deadline; for (size_t i = 0; i < array_.count; i++) { ctx->client_metadata_.insert(std::make_pair( grpc::string(array_.metadata[i].key), diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index ffd6d30d5d..6b5e41d0a8 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -33,11 +33,11 @@ #include -#include -#include #include #include -#include "src/cpp/util/time.h" +#include +#include +#include namespace grpc { @@ -99,7 +99,7 @@ ServerContext::ServerContext() ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) : completion_op_(nullptr), - deadline_(Timespec2Timepoint(deadline)), + deadline_(deadline), call_(nullptr), cq_(nullptr), sent_initial_metadata_(false) { diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index 059ea72abf..1fef2a56de 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -31,9 +31,12 @@ * */ -#include "src/cpp/util/time.h" +#include + +#ifndef GRPC_CXX0X_NO_CHRONO #include +#include using std::chrono::duration_cast; using std::chrono::nanoseconds; @@ -68,3 +71,5 @@ system_clock::time_point Timespec2Timepoint(gpr_timespec t) { } } // namespace grpc + +#endif // !GRPC_CXX0X_NO_CHRONO diff --git a/src/cpp/util/time.h b/src/cpp/util/time.h deleted file mode 100644 index 8b7fcf55f7..0000000000 --- a/src/cpp/util/time.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_INTERNAL_CPP_UTIL_TIME_H -#define GRPC_INTERNAL_CPP_UTIL_TIME_H - -#include - -#include - -namespace grpc { - -// from and to should be absolute time. -void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, - gpr_timespec* to); - -std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); - -} // namespace grpc - -#endif // GRPC_INTERNAL_CPP_UTIL_TIME_H diff --git a/vsprojects/grpc++/grpc++.vcxproj b/vsprojects/grpc++/grpc++.vcxproj index 5a3005d7a4..e9d54b5d3c 100644 --- a/vsprojects/grpc++/grpc++.vcxproj +++ b/vsprojects/grpc++/grpc++.vcxproj @@ -159,6 +159,7 @@ + @@ -178,6 +179,7 @@ + @@ -185,7 +187,6 @@ - @@ -252,4 +253,4 @@ - \ No newline at end of file + diff --git a/vsprojects/grpc++/grpc++.vcxproj.filters b/vsprojects/grpc++/grpc++.vcxproj.filters index 6466a0fa26..d5eeb71790 100644 --- a/vsprojects/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/grpc++/grpc++.vcxproj.filters @@ -120,6 +120,9 @@ include\grpc++\impl + + include\grpc++\impl + include\grpc++\impl @@ -177,6 +180,9 @@ include\grpc++ + + include\grpc++ + @@ -194,9 +200,6 @@ src\cpp\server - - src\cpp\util - diff --git a/vsprojects/grpc.sln b/vsprojects/grpc.sln index 84895cf3c8..1f286f51b2 100644 --- a/vsprojects/grpc.sln +++ b/vsprojects/grpc.sln @@ -1,6 +1,7 @@ + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr", "gpr\gpr.vcxproj", "{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}" EndProject @@ -21,6 +22,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpc_test_util", "grpc_test {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpc_test_util_unsecure", "grpc_test_util_unsecure\grpc_test_util_unsecure.vcxproj", "{0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}" + ProjectSection(ProjectDependencies) = postProject + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpc_unsecure", "grpc_unsecure\grpc_unsecure.vcxproj", "{46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}" ProjectSection(ProjectDependencies) = postProject {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} @@ -41,67 +49,41 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 - Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Debug|Win32.ActiveCfg = Debug|Win32 {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Debug|Win32.Build.0 = Debug|Win32 - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Debug|x64.ActiveCfg = Debug|x64 - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Debug|x64.Build.0 = Debug|x64 {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Release|Win32.ActiveCfg = Release|Win32 {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Release|Win32.Build.0 = Release|Win32 - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Release|x64.ActiveCfg = Release|x64 - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}.Release|x64.Build.0 = Release|x64 {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Debug|Win32.ActiveCfg = Debug|Win32 {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Debug|Win32.Build.0 = Debug|Win32 - {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Debug|x64.ActiveCfg = Debug|x64 - {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Debug|x64.Build.0 = Debug|x64 {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Release|Win32.ActiveCfg = Release|Win32 {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Release|Win32.Build.0 = Release|Win32 - {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Release|x64.ActiveCfg = Release|x64 - {EAB0A629-17A9-44DB-B5FF-E91A721FE037}.Release|x64.Build.0 = Release|x64 {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Debug|Win32.ActiveCfg = Debug|Win32 {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Debug|Win32.Build.0 = Debug|Win32 - {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Debug|x64.ActiveCfg = Debug|x64 - {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Debug|x64.Build.0 = Debug|x64 {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Release|Win32.ActiveCfg = Release|Win32 {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Release|Win32.Build.0 = Release|Win32 - {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Release|x64.ActiveCfg = Release|x64 - {29D16885-7228-4C31-81ED-5F9187C7F2A9}.Release|x64.Build.0 = Release|x64 {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Debug|Win32.ActiveCfg = Debug|Win32 {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Debug|Win32.Build.0 = Debug|Win32 - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Debug|x64.ActiveCfg = Debug|x64 - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Debug|x64.Build.0 = Debug|x64 {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Release|Win32.ActiveCfg = Release|Win32 {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Release|Win32.Build.0 = Release|Win32 - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Release|x64.ActiveCfg = Release|x64 - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}.Release|x64.Build.0 = Release|x64 + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}.Debug|Win32.ActiveCfg = Debug|Win32 + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}.Debug|Win32.Build.0 = Debug|Win32 + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}.Release|Win32.ActiveCfg = Release|Win32 + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF}.Release|Win32.Build.0 = Release|Win32 {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Debug|Win32.ActiveCfg = Debug|Win32 {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Debug|Win32.Build.0 = Debug|Win32 - {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Debug|x64.ActiveCfg = Debug|x64 - {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Debug|x64.Build.0 = Debug|x64 {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Release|Win32.ActiveCfg = Release|Win32 {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Release|Win32.Build.0 = Release|Win32 - {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Release|x64.ActiveCfg = Release|x64 - {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5}.Release|x64.Build.0 = Release|x64 {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Debug|Win32.ActiveCfg = Debug|Win32 {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Debug|Win32.Build.0 = Debug|Win32 - {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Debug|x64.ActiveCfg = Debug|x64 - {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Debug|x64.Build.0 = Debug|x64 {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Release|Win32.ActiveCfg = Release|Win32 {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Release|Win32.Build.0 = Release|Win32 - {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Release|x64.ActiveCfg = Release|x64 - {C187A093-A0FE-489D-A40A-6E33DE0F9FEB}.Release|x64.Build.0 = Release|x64 {D64C6D63-4458-4A88-AB38-35678384A7E4}.Debug|Win32.ActiveCfg = Debug|Win32 {D64C6D63-4458-4A88-AB38-35678384A7E4}.Debug|Win32.Build.0 = Debug|Win32 - {D64C6D63-4458-4A88-AB38-35678384A7E4}.Debug|x64.ActiveCfg = Debug|x64 - {D64C6D63-4458-4A88-AB38-35678384A7E4}.Debug|x64.Build.0 = Debug|x64 {D64C6D63-4458-4A88-AB38-35678384A7E4}.Release|Win32.ActiveCfg = Release|Win32 {D64C6D63-4458-4A88-AB38-35678384A7E4}.Release|Win32.Build.0 = Release|Win32 - {D64C6D63-4458-4A88-AB38-35678384A7E4}.Release|x64.ActiveCfg = Release|x64 - {D64C6D63-4458-4A88-AB38-35678384A7E4}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/vsprojects/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj b/vsprojects/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj new file mode 100644 index 0000000000..d42940933a --- /dev/null +++ b/vsprojects/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj @@ -0,0 +1,117 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF} + + + + v100 + + + v110 + + + v120 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + grpc_test_util_unsecure + + + grpc_test_util_unsecure + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + + + + -- cgit v1.2.3 From 28d051d9baf49382158f2ced7d9b2f11b6d8f608 Mon Sep 17 00:00:00 2001 From: zeliard Date: Mon, 27 Apr 2015 15:51:31 +0900 Subject: remove type casting on gpr_time_to_millis --- src/core/support/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/support/time.c b/src/core/support/time.c index 60a3c23422..7dbf95059f 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -245,7 +245,7 @@ gpr_int32 gpr_time_to_millis(gpr_timespec t) { care?) */ return -2147483647; } else { - return (gpr_int32)t.tv_sec * GPR_MS_PER_SEC + (gpr_int32)t.tv_nsec / GPR_NS_PER_MS; + return t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS; } } -- cgit v1.2.3