diff options
55 files changed, 483 insertions, 217 deletions
@@ -262,6 +262,8 @@ LDFLAGS += -fPIC endif INCLUDES = . include $(GENDIR) +LDFLAGS += -Llibs/$(CONFIG) + ifeq ($(SYSTEM),Darwin) ifneq ($(wildcard /usr/local/ssl/include),) INCLUDES += /usr/local/ssl/include @@ -3073,15 +3075,15 @@ ifeq ($(SYSTEM),MINGW32) $(LIBDIR)/$(CONFIG)/grpc.$(SHARED_EXT): $(LIBGRPC_OBJS) $(ZLIB_DEP) $(LIBDIR)/$(CONFIG)/gpr.$(SHARED_EXT) $(OPENSSL_DEP) $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc.def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc-imp.a -o $(LIBDIR)/$(CONFIG)/grpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr-imp + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc.def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc-imp.a -o $(LIBDIR)/$(CONFIG)/grpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) -lgpr-imp else $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT): $(LIBGRPC_OBJS) $(ZLIB_DEP) $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(OPENSSL_DEP) $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name libgrpc.$(SHARED_EXT) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name libgrpc.$(SHARED_EXT) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) -lgpr else - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc.so.0 -o $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc.so.0 -o $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) -lgpr $(Q) ln -sf libgrpc.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc.so.0 $(Q) ln -sf libgrpc.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc.so endif diff --git a/gRPC.podspec b/gRPC.podspec index 8429357a9e..217d5ca81e 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = 'gRPC' - s.version = '0.0.1' - s.summary = 'Generic gRPC client library for iOS/OSX' - s.homepage = 'https://www.grpc.io' + s.version = '0.5.1' + s.summary = 'gRPC client library for iOS/OSX' + s.homepage = 'http://www.grpc.io' s.license = 'New BSD' - s.authors = { 'Jorge Canizales' => 'jcanizales@google.com', - 'Michael Lumish' => 'mlumish@google.com' } + s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } - # s.source = { :git => 'https://github.com/grpc/grpc.git', :tag => 'release-0_5_0' } + # s.source = { :git => 'https://github.com/grpc/grpc.git', + # :tag => 'release-0_9_1-objectivec-0.5.1' } s.ios.deployment_target = '6.0' s.osx.deployment_target = '10.8' @@ -15,7 +15,6 @@ Pod::Spec.new do |s| s.subspec 'RxLibrary' do |rs| rs.summary = 'Reactive Extensions library for iOS.' - rs.authors = { 'Jorge Canizales' => 'jcanizales@google.com' } rs.source_files = 'src/objective-c/RxLibrary/*.{h,m}', 'src/objective-c/RxLibrary/transformations/*.{h,m}', @@ -25,16 +24,13 @@ Pod::Spec.new do |s| s.subspec 'C-Core' do |cs| cs.summary = 'Core cross-platform gRPC library, written in C.' - cs.authors = { 'Craig Tiller' => 'ctiller@google.com', - 'David Klempner' => 'klempner@google.com', - 'Nicolas Noble' => 'nnoble@google.com', - 'Vijay Pai' => 'vpai@google.com', - 'Yang Gao' => 'yangg@google.com' } cs.source_files = 'src/core/**/*.{h,c}', 'include/grpc/*.h', 'include/grpc/**/*.h' cs.private_header_files = 'src/core/**/*.h' cs.header_mappings_dir = '.' - cs.xcconfig = { 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/Headers/Build/gRPC" "$(PODS_ROOT)/Headers/Build/gRPC/include"' } + cs.xcconfig = { 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/Headers/Build/gRPC" ' + '"$(PODS_ROOT)/Headers/Build/gRPC/include"' } + cs.compiler_flags = '-GCC_WARN_INHIBIT_ALL_WARNINGS', '-w' cs.requires_arc = false cs.libraries = 'z' @@ -67,8 +63,6 @@ Pod::Spec.new do |s| s.subspec 'GRPCClient' do |gs| gs.summary = 'Objective-C wrapper around the core gRPC library.' - gs.authors = { 'Jorge Canizales' => 'jcanizales@google.com', - 'Michael Lumish' => 'mlumish@google.com' } gs.source_files = 'src/objective-c/GRPCClient/*.{h,m}', 'src/objective-c/GRPCClient/private/*.{h,m}' @@ -85,7 +79,6 @@ Pod::Spec.new do |s| s.subspec 'ProtoRPC' do |ps| ps.summary = 'RPC library for ProtocolBuffers, based on gRPC' - ps.authors = { 'Jorge Canizales' => 'jcanizales@google.com' } ps.source_files = 'src/objective-c/ProtoRPC/*.{h,m}' diff --git a/include/grpc++/impl/sync_no_cxx11.h b/include/grpc++/impl/sync_no_cxx11.h index 5636373b81..dda939bf71 100644 --- a/include/grpc++/impl/sync_no_cxx11.h +++ b/include/grpc++/impl/sync_no_cxx11.h @@ -76,9 +76,9 @@ class lock_guard { template <class mutex> class unique_lock : public lock_guard<mutex> { public: - unique_lock(mutex &mu) : lock_guard(mu) { } - void lock() { lock_internal(); } - void unlock() { unlock_internal(); } + unique_lock(mutex &mu) : lock_guard<mutex>(mu) { } + void lock() { this->lock_internal(); } + void unlock() { this->unlock_internal(); } }; class condition_variable { diff --git a/include/grpc++/impl/thd_no_cxx11.h b/include/grpc++/impl/thd_no_cxx11.h index a01b931df8..a6bdd7dfe9 100644 --- a/include/grpc++/impl/thd_no_cxx11.h +++ b/include/grpc++/impl/thd_no_cxx11.h @@ -82,6 +82,10 @@ class thread { thread_function_base *func_; gpr_thd_id thd_; bool joined_; + + // Disallow copy and assign. + thread(const thread&); + void operator=(const thread&); }; } // namespace grpc diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index a62babd931..d88a3ae262 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -106,6 +106,10 @@ class ServerContext { template <class R, class W> friend class ::grpc::ServerReaderWriter; + // Prevent copying. + ServerContext(const ServerContext&); + ServerContext& operator=(const ServerContext&); + class CompletionOp; void BeginCompletionOp(Call* call); diff --git a/src/core/iomgr/endpoint_pair.h b/src/core/iomgr/endpoint_pair.h index dffbd36d4c..25087be0c7 100644 --- a/src/core/iomgr/endpoint_pair.h +++ b/src/core/iomgr/endpoint_pair.h @@ -41,6 +41,7 @@ typedef struct { grpc_endpoint *server; } grpc_endpoint_pair; -grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(size_t read_slice_size); +grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name, + size_t read_slice_size); #endif /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_PAIR_H */ diff --git a/src/core/iomgr/endpoint_pair_posix.c b/src/core/iomgr/endpoint_pair_posix.c index ac511b97b2..9b3b63f1e7 100644 --- a/src/core/iomgr/endpoint_pair_posix.c +++ b/src/core/iomgr/endpoint_pair_posix.c @@ -44,6 +44,8 @@ #include <sys/socket.h> #include "src/core/iomgr/tcp_posix.h" +#include "src/core/support/string.h" +#include <grpc/support/alloc.h> #include <grpc/support/log.h> static void create_sockets(int sv[2]) { @@ -55,12 +57,21 @@ static void create_sockets(int sv[2]) { GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); } -grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(size_t read_slice_size) { +grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name, + size_t read_slice_size) { int sv[2]; grpc_endpoint_pair p; + char *final_name; create_sockets(sv); - p.client = grpc_tcp_create(grpc_fd_create(sv[1]), read_slice_size); - p.server = grpc_tcp_create(grpc_fd_create(sv[0]), read_slice_size); + + gpr_asprintf(&final_name, "%s:client", name); + p.client = + grpc_tcp_create(grpc_fd_create(sv[1], final_name), read_slice_size); + gpr_free(final_name); + gpr_asprintf(&final_name, "%s:server", name); + p.server = + grpc_tcp_create(grpc_fd_create(sv[0], final_name), read_slice_size); + gpr_free(final_name); return p; } diff --git a/src/core/iomgr/endpoint_pair_windows.c b/src/core/iomgr/endpoint_pair_windows.c index 988d622d01..c6790b2937 100644 --- a/src/core/iomgr/endpoint_pair_windows.c +++ b/src/core/iomgr/endpoint_pair_windows.c @@ -77,12 +77,12 @@ static void create_sockets(SOCKET sv[2]) { sv[0] = svr_sock; } -grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(size_t read_slice_size) { +grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name, size_t read_slice_size) { SOCKET sv[2]; grpc_endpoint_pair p; create_sockets(sv); - p.client = grpc_tcp_create(grpc_winsocket_create(sv[1])); - p.server = grpc_tcp_create(grpc_winsocket_create(sv[0])); + p.client = grpc_tcp_create(grpc_winsocket_create(sv[1], "endpoint:client")); + p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server")); return p; } diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index 5bbf171c6d..28ed7708f7 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -41,7 +41,6 @@ #include <sys/socket.h> #include <unistd.h> -#include "src/core/iomgr/iomgr_internal.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> @@ -119,7 +118,7 @@ static void unref_by(grpc_fd *fd, int n) { if (old == n) { grpc_iomgr_add_callback(&fd->on_done_closure); freelist_fd(fd); - grpc_iomgr_unref(); + grpc_iomgr_unregister_object(&fd->iomgr_object); } else { GPR_ASSERT(old > n); } @@ -138,9 +137,9 @@ void grpc_fd_global_shutdown(void) { static void do_nothing(void *ignored, int success) {} -grpc_fd *grpc_fd_create(int fd) { +grpc_fd *grpc_fd_create(int fd, const char *name) { grpc_fd *r = alloc_fd(fd); - grpc_iomgr_ref(); + grpc_iomgr_register_object(&r->iomgr_object, name); grpc_pollset_add_fd(grpc_backup_pollset(), r); return r; } diff --git a/src/core/iomgr/fd_posix.h b/src/core/iomgr/fd_posix.h index a7c9c34802..0fa71850e3 100644 --- a/src/core/iomgr/fd_posix.h +++ b/src/core/iomgr/fd_posix.h @@ -34,7 +34,7 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_FD_POSIX_H #define GRPC_INTERNAL_CORE_IOMGR_FD_POSIX_H -#include "src/core/iomgr/iomgr.h" +#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/pollset.h" #include <grpc/support/atm.h> #include <grpc/support/sync.h> @@ -95,12 +95,14 @@ struct grpc_fd { grpc_iomgr_closure on_done_closure; grpc_iomgr_closure *shutdown_closures[2]; + + grpc_iomgr_object iomgr_object; }; /* Create a wrapped file descriptor. Requires fd is a non-blocking file descriptor. This takes ownership of closing fd. */ -grpc_fd *grpc_fd_create(int fd); +grpc_fd *grpc_fd_create(int fd, const char *name); /* Releases fd to be asynchronously destroyed. on_done is called when the underlying file descriptor is definitely close()d. diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index b983a89daa..249228a214 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -37,6 +37,7 @@ #include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/alarm_internal.h" +#include "src/core/support/string.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/thd.h> @@ -47,8 +48,8 @@ static gpr_cv g_rcv; static grpc_iomgr_closure *g_cbs_head = NULL; static grpc_iomgr_closure *g_cbs_tail = NULL; static int g_shutdown; -static int g_refs; static gpr_event g_background_callback_executor_done; +static grpc_iomgr_object g_root_object; /* Execute followup callbacks continuously. Other threads may check in and help during pollset_work() */ @@ -88,13 +89,24 @@ void grpc_iomgr_init(void) { gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); grpc_alarm_list_init(gpr_now()); - g_refs = 0; + g_root_object.next = g_root_object.prev = &g_root_object; + g_root_object.name = "root"; grpc_iomgr_platform_init(); gpr_event_init(&g_background_callback_executor_done); gpr_thd_new(&id, background_callback_executor, NULL, NULL); } +static size_t count_objects(void) { + grpc_iomgr_object *obj; + size_t n = 0; + for (obj = g_root_object.next; obj != &g_root_object; obj = obj->next) { + n++; + } + return n; +} + void grpc_iomgr_shutdown(void) { + grpc_iomgr_object *obj; grpc_iomgr_closure *closure; gpr_timespec shutdown_deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(10)); @@ -102,19 +114,23 @@ void grpc_iomgr_shutdown(void) { gpr_mu_lock(&g_mu); g_shutdown = 1; - while (g_cbs_head || g_refs) { - gpr_log(GPR_DEBUG, "Waiting for %d iomgr objects to be destroyed%s", g_refs, + while (g_cbs_head || g_root_object.next != &g_root_object) { + size_t nobjs = count_objects(); + gpr_log(GPR_DEBUG, "Waiting for %d iomgr objects to be destroyed%s", nobjs, g_cbs_head ? " and executing final callbacks" : ""); - while (g_cbs_head) { - closure = g_cbs_head; - g_cbs_head = closure->next; - if (!g_cbs_head) g_cbs_tail = NULL; - gpr_mu_unlock(&g_mu); - - closure->cb(closure->cb_arg, 0); - gpr_mu_lock(&g_mu); + if (g_cbs_head) { + do { + closure = g_cbs_head; + g_cbs_head = closure->next; + if (!g_cbs_head) g_cbs_tail = NULL; + gpr_mu_unlock(&g_mu); + + closure->cb(closure->cb_arg, 0); + gpr_mu_lock(&g_mu); + } while (g_cbs_head); + continue; } - if (g_refs) { + if (nobjs > 0) { int timeout = 0; gpr_timespec short_deadline = gpr_time_add(gpr_now(), gpr_time_from_millis(100)); @@ -128,7 +144,10 @@ void grpc_iomgr_shutdown(void) { gpr_log(GPR_DEBUG, "Failed to free %d iomgr objects before shutdown deadline: " "memory leaks are likely", - g_refs); + count_objects()); + for (obj = g_root_object.next; obj != &g_root_object; obj = obj->next) { + gpr_log(GPR_DEBUG, "LEAKED OBJECT: %s", obj->name); + } break; } } @@ -144,17 +163,21 @@ void grpc_iomgr_shutdown(void) { gpr_cv_destroy(&g_rcv); } -void grpc_iomgr_ref(void) { +void grpc_iomgr_register_object(grpc_iomgr_object *obj, const char *name) { + obj->name = gpr_strdup(name); gpr_mu_lock(&g_mu); - ++g_refs; + obj->next = &g_root_object; + obj->prev = obj->next->prev; + obj->next->prev = obj->prev->next = obj; gpr_mu_unlock(&g_mu); } -void grpc_iomgr_unref(void) { +void grpc_iomgr_unregister_object(grpc_iomgr_object *obj) { + gpr_free(obj->name); gpr_mu_lock(&g_mu); - if (0 == --g_refs) { - gpr_cv_signal(&g_rcv); - } + obj->next->prev = obj->prev; + obj->prev->next = obj->next; + gpr_cv_signal(&g_rcv); gpr_mu_unlock(&g_mu); } diff --git a/src/core/iomgr/iomgr_internal.h b/src/core/iomgr/iomgr_internal.h index 25a731d58c..6c1e0e1799 100644 --- a/src/core/iomgr/iomgr_internal.h +++ b/src/core/iomgr/iomgr_internal.h @@ -37,11 +37,17 @@ #include "src/core/iomgr/iomgr.h" #include <grpc/support/sync.h> +typedef struct grpc_iomgr_object { + char *name; + struct grpc_iomgr_object *next; + struct grpc_iomgr_object *prev; +} grpc_iomgr_object; + int grpc_maybe_call_delayed_callbacks(gpr_mu *drop_mu, int success); void grpc_iomgr_add_delayed_callback(grpc_iomgr_closure *iocb, int success); -void grpc_iomgr_ref(void); -void grpc_iomgr_unref(void); +void grpc_iomgr_register_object(grpc_iomgr_object *obj, const char *name); +void grpc_iomgr_unregister_object(grpc_iomgr_object *obj); void grpc_iomgr_platform_init(void); void grpc_iomgr_platform_shutdown(void); diff --git a/src/core/iomgr/resolve_address_posix.c b/src/core/iomgr/resolve_address_posix.c index 9a9283c93c..fcf48fe0d7 100644 --- a/src/core/iomgr/resolve_address_posix.c +++ b/src/core/iomgr/resolve_address_posix.c @@ -55,6 +55,7 @@ typedef struct { char *default_port; grpc_resolve_cb cb; void *arg; + grpc_iomgr_object iomgr_object; } request; grpc_resolved_addresses *grpc_blocking_resolve_address( @@ -153,9 +154,9 @@ static void do_request(void *rp) { grpc_resolve_cb cb = r->cb; gpr_free(r->name); gpr_free(r->default_port); + grpc_iomgr_unregister_object(&r->iomgr_object); gpr_free(r); cb(arg, resolved); - grpc_iomgr_unref(); } void grpc_resolved_addresses_destroy(grpc_resolved_addresses *addrs) { @@ -167,7 +168,11 @@ void grpc_resolve_address(const char *name, const char *default_port, grpc_resolve_cb cb, void *arg) { request *r = gpr_malloc(sizeof(request)); gpr_thd_id id; - grpc_iomgr_ref(); + char *tmp; + gpr_asprintf(&tmp, "resolve_address:name='%s':default_port='%s'", name, + default_port); + grpc_iomgr_register_object(&r->iomgr_object, tmp); + gpr_free(tmp); r->name = gpr_strdup(name); r->default_port = gpr_strdup(default_port); r->cb = cb; diff --git a/src/core/iomgr/resolve_address_windows.c b/src/core/iomgr/resolve_address_windows.c index 9b416dfe8a..7d0d2f9e7a 100644 --- a/src/core/iomgr/resolve_address_windows.c +++ b/src/core/iomgr/resolve_address_windows.c @@ -54,6 +54,7 @@ typedef struct { char *default_port; grpc_resolve_cb cb; void *arg; + grpc_iomgr_object iomgr_object; } request; grpc_resolved_addresses *grpc_blocking_resolve_address( @@ -135,7 +136,7 @@ static void do_request(void *rp) { gpr_free(r->default_port); gpr_free(r); cb(arg, resolved); - grpc_iomgr_unref(); + grpc_iomgr_unregister_object(&r->iomgr_object); } void grpc_resolved_addresses_destroy(grpc_resolved_addresses *addrs) { @@ -147,7 +148,10 @@ void grpc_resolve_address(const char *name, const char *default_port, grpc_resolve_cb cb, void *arg) { request *r = gpr_malloc(sizeof(request)); gpr_thd_id id; - grpc_iomgr_ref(); + const char *label; + gpr_asprintf(&label, "resolve:%s", name); + grpc_iomgr_register_object(&r->iomgr_object, label); + gpr_free(label); r->name = gpr_strdup(name); r->default_port = gpr_strdup(default_port); r->cb = cb; diff --git a/src/core/iomgr/socket_windows.c b/src/core/iomgr/socket_windows.c index 805fa8a4fc..e4ba0a2b66 100644 --- a/src/core/iomgr/socket_windows.c +++ b/src/core/iomgr/socket_windows.c @@ -44,12 +44,12 @@ #include "src/core/iomgr/pollset_windows.h" #include "src/core/iomgr/socket_windows.h" -grpc_winsocket *grpc_winsocket_create(SOCKET socket) { +grpc_winsocket *grpc_winsocket_create(SOCKET socket, const char *name) { grpc_winsocket *r = gpr_malloc(sizeof(grpc_winsocket)); memset(r, 0, sizeof(grpc_winsocket)); r->socket = socket; gpr_mu_init(&r->state_mu); - grpc_iomgr_ref(); + grpc_iomgr_register_object(&r->iomgr_object, name); grpc_iocp_add_socket(r); return r; } @@ -91,7 +91,7 @@ void grpc_winsocket_orphan(grpc_winsocket *winsocket) { grpc_winsocket_destroy(winsocket); } closesocket(socket); - grpc_iomgr_unref(); + grpc_iomgr_unregister_object(&winsocket->iomgr_object); } void grpc_winsocket_destroy(grpc_winsocket *winsocket) { diff --git a/src/core/iomgr/socket_windows.h b/src/core/iomgr/socket_windows.h index d5fee39604..7080919af0 100644 --- a/src/core/iomgr/socket_windows.h +++ b/src/core/iomgr/socket_windows.h @@ -39,7 +39,7 @@ #include <grpc/support/sync.h> #include <grpc/support/atm.h> -#include "src/core/iomgr/iomgr.h" +#include "src/core/iomgr/iomgr_internal.h" /* This holds the data for an outstanding read or write on a socket. The mutex to protect the concurrent access to that data is the one @@ -97,11 +97,14 @@ typedef struct grpc_winsocket { int orphan; grpc_iomgr_closure shutdown_closure; + + /* A label for iomgr to track outstanding objects */ + grpc_iomgr_object iomgr_object; } grpc_winsocket; /* Create a wrapped windows handle. This takes ownership of it, meaning that it will be responsible for closing it. */ -grpc_winsocket *grpc_winsocket_create(SOCKET socket); +grpc_winsocket *grpc_winsocket_create(SOCKET socket, const char *name); /* Initiate an asynchronous shutdown of the socket. Will call off any pending operation to cancel them. Returns the number of callbacks that got setup. */ diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 2401fe00e4..aa21ba9b9e 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -48,6 +48,7 @@ #include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/socket_utils_posix.h" #include "src/core/iomgr/tcp_posix.h" +#include "src/core/support/string.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/time.h> @@ -185,6 +186,8 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), async_connect *ac; struct sockaddr_in6 addr6_v4mapped; struct sockaddr_in addr4_copy; + char *name; + char *addr_str; /* Use dualstack sockets where available. */ if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { @@ -211,24 +214,27 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), err = connect(fd, addr, addr_len); } while (err < 0 && errno == EINTR); + grpc_sockaddr_to_string(&addr_str, addr, 1); + gpr_asprintf(&name, "tcp-client:%s", addr_str); + if (err >= 0) { gpr_log(GPR_DEBUG, "instant connect"); - cb(arg, - grpc_tcp_create(grpc_fd_create(fd), GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); - return; + cb(arg, grpc_tcp_create(grpc_fd_create(fd, name), + GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + goto done; } if (errno != EWOULDBLOCK && errno != EINPROGRESS) { - gpr_log(GPR_ERROR, "connect error: %s", strerror(errno)); + gpr_log(GPR_ERROR, "connect error to '%s': %s", addr_str, strerror(errno)); close(fd); cb(arg, NULL); - return; + goto done; } ac = gpr_malloc(sizeof(async_connect)); ac->cb = cb; ac->cb_arg = arg; - ac->fd = grpc_fd_create(fd); + ac->fd = grpc_fd_create(fd, name); gpr_mu_init(&ac->mu); ac->refs = 2; ac->write_closure.cb = on_writable; @@ -236,6 +242,10 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now()); grpc_fd_notify_on_write(ac->fd, &ac->write_closure); + +done: + gpr_free(name); + gpr_free(addr_str); } #endif diff --git a/src/core/iomgr/tcp_client_windows.c b/src/core/iomgr/tcp_client_windows.c index cf5174327d..2a040ffc4a 100644 --- a/src/core/iomgr/tcp_client_windows.c +++ b/src/core/iomgr/tcp_client_windows.c @@ -193,7 +193,7 @@ void grpc_tcp_client_connect(void(*cb)(void *arg, grpc_endpoint *tcp), goto failure; } - socket = grpc_winsocket_create(sock); + socket = grpc_winsocket_create(sock, "client"); info = &socket->write_info; info->outstanding = 1; success = ConnectEx(sock, addr, addr_len, NULL, 0, NULL, &info->overlapped); diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index d1cd8a769c..3cd40faafc 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -60,6 +60,7 @@ #include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/socket_utils_posix.h" #include "src/core/iomgr/tcp_posix.h" +#include "src/core/support/string.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> @@ -281,6 +282,8 @@ static void on_read(void *arg, int success) { for (;;) { struct sockaddr_storage addr; socklen_t addrlen = sizeof(addr); + char *addr_str; + char *name; /* Note: If we ever decide to return this address to the user, remember to strip off the ::ffff:0.0.0.0/96 prefix first. */ int fd = grpc_accept4(sp->fd, (struct sockaddr *)&addr, &addrlen, 1, 1); @@ -299,9 +302,15 @@ static void on_read(void *arg, int success) { grpc_set_socket_no_sigpipe_if_possible(fd); - sp->server->cb( - sp->server->cb_arg, - grpc_tcp_create(grpc_fd_create(fd), GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + grpc_sockaddr_to_string(&addr_str, (struct sockaddr *)&addr, 1); + gpr_asprintf(&name, "tcp-server-connection:%s", addr_str); + + sp->server->cb(sp->server->cb_arg, + grpc_tcp_create(grpc_fd_create(fd, name), + GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + + gpr_free(addr_str); + gpr_free(name); } abort(); @@ -318,9 +327,13 @@ static int add_socket_to_server(grpc_tcp_server *s, int fd, const struct sockaddr *addr, int addr_len) { server_port *sp; int port; + char *addr_str; + char *name; port = prepare_socket(fd, addr, addr_len); if (port >= 0) { + grpc_sockaddr_to_string(&addr_str, (struct sockaddr *)&addr, 1); + gpr_asprintf(&name, "tcp-server-listener:%s", addr_str); gpr_mu_lock(&s->mu); GPR_ASSERT(!s->cb && "must add ports before starting server"); /* append it to the list under a lock */ @@ -331,11 +344,13 @@ static int add_socket_to_server(grpc_tcp_server *s, int fd, sp = &s->ports[s->nports++]; sp->server = s; sp->fd = fd; - sp->emfd = grpc_fd_create(fd); + sp->emfd = grpc_fd_create(fd, name); memcpy(sp->addr.untyped, addr, addr_len); sp->addr_len = addr_len; GPR_ASSERT(sp->emfd); gpr_mu_unlock(&s->mu); + gpr_free(addr_str); + gpr_free(name); } return port; diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index d22acc7453..9ef369dfd8 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -270,7 +270,8 @@ static void on_accept(void *arg, int from_iocp) { gpr_free(utf8_message); closesocket(sock); } else { - ep = grpc_tcp_create(grpc_winsocket_create(sock)); + /* TODO(ctiller): add sockaddr address to label */ + ep = grpc_tcp_create(grpc_winsocket_create(sock, "server")); } } else { /* If we're not notified from the IOCP, it means we are asked to shutdown. @@ -336,7 +337,7 @@ static int add_socket_to_server(grpc_tcp_server *s, SOCKET sock, } sp = &s->ports[s->nports++]; sp->server = s; - sp->socket = grpc_winsocket_create(sock); + sp->socket = grpc_winsocket_create(sock, "listener"); sp->shutting_down = 0; sp->AcceptEx = AcceptEx; sp->new_socket = INVALID_SOCKET; diff --git a/src/core/transport/chttp2/gen_hpack_tables.c b/src/core/transport/chttp2/gen_hpack_tables.c index 86b593129b..bdaa3cf094 100644 --- a/src/core/transport/chttp2/gen_hpack_tables.c +++ b/src/core/transport/chttp2/gen_hpack_tables.c @@ -219,10 +219,10 @@ static int state_index(int bitofs, symset syms, int *isnew) { emit - the symbol to emit on this nibble (or -1 if no symbol has been found) syms - the set of symbols that could be matched */ -static void build_dec_tbl(int state, int nibble, int nibbits, int bitofs, +static void build_dec_tbl(int state, int nibble, int nibbits, unsigned bitofs, int emit, symset syms) { int i; - int bit; + unsigned bit; /* If we have four bits in the nibble we're looking at, then we can fill in a slot in the lookup tables. */ @@ -338,7 +338,7 @@ static void generate_base64_inverse_table(void) { static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; unsigned char inverse[256]; - int i; + unsigned i; memset(inverse, 255, sizeof(inverse)); for (i = 0; i < strlen(alphabet); i++) { diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc index e8d0e89ed2..118cabcb61 100644 --- a/src/cpp/server/thread_pool.cc +++ b/src/cpp/server/thread_pool.cc @@ -60,7 +60,7 @@ void ThreadPool::ThreadFunc() { ThreadPool::ThreadPool(int num_threads) : shutdown_(false) { for (int i = 0; i < num_threads; i++) { - threads_.push_back(grpc::thread(&ThreadPool::ThreadFunc, this)); + threads_.push_back(new grpc::thread(&ThreadPool::ThreadFunc, this)); } } @@ -71,7 +71,8 @@ ThreadPool::~ThreadPool() { cv_.notify_all(); } for (auto t = threads_.begin(); t != threads_.end(); t++) { - t->join(); + (*t)->join(); + delete *t; } } diff --git a/src/cpp/server/thread_pool.h b/src/cpp/server/thread_pool.h index 0f24d6e9b3..26f25611b5 100644 --- a/src/cpp/server/thread_pool.h +++ b/src/cpp/server/thread_pool.h @@ -57,7 +57,7 @@ class ThreadPool GRPC_FINAL : public ThreadPoolInterface { grpc::condition_variable cv_; bool shutdown_; std::queue<std::function<void()>> callbacks_; - std::vector<grpc::thread> threads_; + std::vector<grpc::thread*> threads_; void ThreadFunc(); }; diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config new file mode 100644 index 0000000000..a7df95cf6b --- /dev/null +++ b/src/csharp/.nuget/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="NUnit.Runners" version="2.6.4" /> +</packages>
\ No newline at end of file diff --git a/src/csharp/Grpc.Auth/Grpc.Auth.nuspec b/src/csharp/Grpc.Auth/Grpc.Auth.nuspec index 171259d18d..e7a538b21b 100644 --- a/src/csharp/Grpc.Auth/Grpc.Auth.nuspec +++ b/src/csharp/Grpc.Auth/Grpc.Auth.nuspec @@ -5,19 +5,19 @@ <title>gRPC C# Auth</title> <summary>Auth library for C# implementation of gRPC - an RPC library and framework</summary> <description>Auth library for C# implementation of gRPC - an RPC library and framework. See project site for more info.</description> - <version>0.5.0</version> + <version>0.5.1</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> <licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl> <projectUrl>https://github.com/grpc/grpc</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> - <releaseNotes>Release 0.5.0 of gRPC C#</releaseNotes> + <releaseNotes>Release 0.5.1 of gRPC C#</releaseNotes> <copyright>Copyright 2015, Google Inc.</copyright> <tags>gRPC RPC Protocol HTTP/2 Auth OAuth2</tags> <dependencies> <dependency id="BouncyCastle" version="1.7.0" /> <dependency id="Google.Apis.Auth" version="1.9.1" /> - <dependency id="Grpc.Core" version="0.5.0" /> + <dependency id="Grpc.Core" version="0.5.1" /> </dependencies> </metadata> <files> diff --git a/src/csharp/Grpc.Core/Grpc.Core.nuspec b/src/csharp/Grpc.Core/Grpc.Core.nuspec index 42eb90c9a3..629b978fdf 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.nuspec +++ b/src/csharp/Grpc.Core/Grpc.Core.nuspec @@ -5,19 +5,19 @@ <title>gRPC C# Core</title> <summary>Core C# implementation of gRPC - an RPC library and framework</summary> <description>Core C# implementation of gRPC - an RPC library and framework. See project site for more info.</description> - <version>0.5.0</version> + <version>0.5.1</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> <licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl> <projectUrl>https://github.com/grpc/grpc</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> - <releaseNotes>Release 0.5.0 of gRPC C#</releaseNotes> + <releaseNotes>Release 0.5.1 of gRPC C#</releaseNotes> <copyright>Copyright 2015, Google Inc.</copyright> <tags>gRPC RPC Protocol HTTP/2</tags> <dependencies> <dependency id="Microsoft.Bcl.Immutable" version="1.0.34" /> <dependency id="Ix-Async" version="1.2.3" /> - <dependency id="grpc.native.csharp_ext" version="0.9.0.0" /> + <dependency id="grpc.native.csharp_ext" version="0.9.1" /> </dependencies> </metadata> <files> diff --git a/src/csharp/Grpc.Tools.nuspec b/src/csharp/Grpc.Tools.nuspec index 155c2ef8c4..913d4c8f4b 100644 --- a/src/csharp/Grpc.Tools.nuspec +++ b/src/csharp/Grpc.Tools.nuspec @@ -5,13 +5,13 @@ <title>gRPC C# Tools</title> <summary>Tools for C# implementation of gRPC - an RPC library and framework</summary> <description>Precompiled Windows binaries for generating protocol buffer messages and gRPC client/server code</description> - <version>0.5.0</version> + <version>0.5.1</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> <licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl> <projectUrl>https://github.com/grpc/grpc</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> - <releaseNotes>protoc.exe - protocol buffer compiler v3.0.0-alpha-3; grpc_csharp_plugin.exe - gRPC C# protoc plugin version 0.5.0</releaseNotes> + <releaseNotes>protoc.exe - protocol buffer compiler v3.0.0-alpha-3; grpc_csharp_plugin.exe - gRPC C# protoc plugin version 0.5.1</releaseNotes> <copyright>Copyright 2015, Google Inc.</copyright> <tags>gRPC RPC Protocol HTTP/2</tags> </metadata> diff --git a/src/csharp/Grpc.nuspec b/src/csharp/Grpc.nuspec index 263e016339..cf4c74fa2d 100644 --- a/src/csharp/Grpc.nuspec +++ b/src/csharp/Grpc.nuspec @@ -5,17 +5,17 @@ <title>gRPC C#</title> <summary>C# implementation of gRPC - an RPC library and framework</summary> <description>C# implementation of gRPC - an RPC library and framework. See project site for more info.</description> - <version>0.5.0.1</version> + <version>0.5.1</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> <licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl> <projectUrl>https://github.com/grpc/grpc</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> - <releaseNotes>Release 0.5.0 of gRPC C#</releaseNotes> + <releaseNotes>Release 0.5.1 of gRPC C#</releaseNotes> <copyright>Copyright 2015, Google Inc.</copyright> <tags>gRPC RPC Protocol HTTP/2</tags> <dependencies> - <dependency id="Grpc.Core" version="0.5.0" /> + <dependency id="Grpc.Core" version="0.5.1" /> </dependencies> </metadata> <files/> diff --git a/src/csharp/Grpc.sln b/src/csharp/Grpc.sln index e2a374e362..978739f23a 100644 --- a/src/csharp/Grpc.sln +++ b/src/csharp/Grpc.sln @@ -1,6 +1,8 @@ 
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.31101.0
+MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grpc.Examples", "Grpc.Examples\Grpc.Examples.csproj", "{7DC1433E-3225-42C7-B7EA-546D56E27A4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grpc.Core", "Grpc.Core\Grpc.Core.csproj", "{CCC4440E-49F7-4790-B0AF-FEABB0837AE7}"
@@ -21,52 +23,60 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grpc.Examples.MathServer", EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grpc.Auth", "Grpc.Auth\Grpc.Auth.csproj", "{AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B5B87121-35FE-49D1-8CB1-8A91AAA398A9}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\packages.config = .nuget\packages.config
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Debug|x86.ActiveCfg = Debug|Any CPU
- {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Debug|x86.Build.0 = Debug|Any CPU
- {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Release|x86.ActiveCfg = Release|Any CPU
- {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Release|x86.Build.0 = Release|Any CPU
- {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Debug|x86.ActiveCfg = Debug|x86
- {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Debug|x86.Build.0 = Debug|x86
- {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Release|x86.ActiveCfg = Release|x86
- {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Release|x86.Build.0 = Release|x86
- {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Debug|x86.ActiveCfg = Debug|x86
- {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Debug|x86.Build.0 = Debug|x86
- {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Release|x86.ActiveCfg = Release|x86
- {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Release|x86.Build.0 = Release|x86
{7DC1433E-3225-42C7-B7EA-546D56E27A4B}.Debug|x86.ActiveCfg = Debug|Any CPU
{7DC1433E-3225-42C7-B7EA-546D56E27A4B}.Debug|x86.Build.0 = Debug|Any CPU
{7DC1433E-3225-42C7-B7EA-546D56E27A4B}.Release|x86.ActiveCfg = Release|Any CPU
{7DC1433E-3225-42C7-B7EA-546D56E27A4B}.Release|x86.Build.0 = Release|Any CPU
+ {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.Build.0 = Debug|Any CPU
+ {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.ActiveCfg = Release|Any CPU
+ {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.Build.0 = Release|Any CPU
{86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Debug|x86.ActiveCfg = Debug|Any CPU
{86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Debug|x86.Build.0 = Debug|Any CPU
{86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Release|x86.ActiveCfg = Release|Any CPU
{86EC5CB4-4EA2-40A2-8057-86542A0353BB}.Release|x86.Build.0 = Release|Any CPU
+ {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Debug|x86.Build.0 = Debug|Any CPU
+ {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Release|x86.ActiveCfg = Release|Any CPU
+ {143B1C29-C442-4BE0-BF3F-A8F92288AC9F}.Release|x86.Build.0 = Release|Any CPU
+ {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Debug|x86.ActiveCfg = Debug|x86
+ {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Debug|x86.Build.0 = Debug|x86
+ {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Release|x86.ActiveCfg = Release|x86
+ {61ECB8EE-0C96-4F8E-B187-8E4D227417C0}.Release|x86.Build.0 = Release|x86
+ {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.ActiveCfg = Debug|x86
+ {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.Build.0 = Debug|x86
+ {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.ActiveCfg = Release|x86
+ {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.Build.0 = Release|x86
+ {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Debug|x86.ActiveCfg = Debug|x86
+ {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Debug|x86.Build.0 = Debug|x86
+ {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Release|x86.ActiveCfg = Release|x86
+ {3D166931-BA2D-416E-95A3-D36E8F6E90B9}.Release|x86.Build.0 = Release|x86
{A654F3B8-E859-4E6A-B30D-227527DBEF0D}.Debug|x86.ActiveCfg = Debug|x86
{A654F3B8-E859-4E6A-B30D-227527DBEF0D}.Debug|x86.Build.0 = Debug|x86
{A654F3B8-E859-4E6A-B30D-227527DBEF0D}.Release|x86.ActiveCfg = Release|x86
{A654F3B8-E859-4E6A-B30D-227527DBEF0D}.Release|x86.Build.0 = Release|x86
- {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Debug|x86.ActiveCfg = Debug|Any CPU
- {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Debug|x86.Build.0 = Debug|Any CPU
- {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Release|x86.ActiveCfg = Release|Any CPU
- {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Release|x86.Build.0 = Release|Any CPU
{BF62FE08-373A-43D6-9D73-41CAA38B7011}.Debug|x86.ActiveCfg = Debug|x86
{BF62FE08-373A-43D6-9D73-41CAA38B7011}.Debug|x86.Build.0 = Debug|x86
{BF62FE08-373A-43D6-9D73-41CAA38B7011}.Release|x86.ActiveCfg = Release|x86
{BF62FE08-373A-43D6-9D73-41CAA38B7011}.Release|x86.Build.0 = Release|x86
- {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.ActiveCfg = Debug|x86
- {C61154BA-DD4A-4838-8420-0162A28925E0}.Debug|x86.Build.0 = Debug|x86
- {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.ActiveCfg = Release|x86
- {C61154BA-DD4A-4838-8420-0162A28925E0}.Release|x86.Build.0 = Release|x86
- {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.ActiveCfg = Debug|Any CPU
- {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Debug|x86.Build.0 = Debug|Any CPU
- {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.ActiveCfg = Release|Any CPU
- {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}.Release|x86.Build.0 = Release|Any CPU
+ {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Debug|x86.Build.0 = Debug|Any CPU
+ {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Release|x86.ActiveCfg = Release|Any CPU
+ {AE21D0EE-9A2C-4C15-AB7F-5224EED5B0EA}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Grpc.Examples\Grpc.Examples.csproj
diff --git a/src/csharp/buildall.bat b/src/csharp/buildall.bat index 68c61ef039..16860aec3c 100644 --- a/src/csharp/buildall.bat +++ b/src/csharp/buildall.bat @@ -1,6 +1,10 @@ @rem Convenience script to build gRPC C# from command line setlocal + +@rem enter this directory +cd /d %~dp0 + @rem Set VS variables (uses Visual Studio 2013) @call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" x86 diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index c350f32f2a..e14e503ae0 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -35,21 +35,90 @@ #include <grpc/support/alloc.h> +#pragma mark Category for binary metadata elements + +@interface NSData (GRPCMetadata) ++ (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata; + +// Fill a metadata object with the binary value in this NSData and the given key. +- (void)grpc_initMetadata:(grpc_metadata *)metadata withKey:(NSString *)key; +@end + +@implementation NSData (GRPCMetadata) ++ (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata { + // TODO(jcanizales): Should we use a non-copy constructor? + return [self dataWithBytes:metadata->value length:metadata->value_length]; +} + +- (void)grpc_initMetadata:(grpc_metadata *)metadata withKey:(NSString *)key { + // TODO(jcanizales): Encode Unicode chars as ASCII. + metadata->key = [key stringByAppendingString:@"-bin"].UTF8String; + metadata->value = self.bytes; + metadata->value_length = self.length; +} +@end + +#pragma mark Category for textual metadata elements + +@interface NSString (GRPCMetadata) ++ (instancetype)grpc_stringFromMetadataValue:(grpc_metadata *)metadata; + +// Fill a metadata object with the textual value in this NSString and the given key. +- (void)grpc_initMetadata:(grpc_metadata *)metadata withKey:(NSString *)key; +@end + +@implementation NSString (GRPCMetadata) ++ (instancetype)grpc_stringFromMetadataValue:(grpc_metadata *)metadata { + return [[self alloc] initWithBytes:metadata->value + length:metadata->value_length + encoding:NSASCIIStringEncoding]; +} + +- (void)grpc_initMetadata:(grpc_metadata *)metadata withKey:(NSString *)key { + if ([key hasSuffix:@"-bin"]) { + // Disallow this, as at best it will confuse the server. If the app really needs to send a + // textual header with a name ending in "-bin", it can be done by removing the suffix and + // encoding the NSString as a NSData object. + // + // Why raise an exception: In the most common case, the developer knows this won't happen in + // their code, so the exception isn't triggered. In the rare cases when the developer can't + // tell, it's easy enough to add a sanitizing filter before the header is set. There, the + // developer can choose whether to drop such a header, or trim its name. Doing either ourselves, + // silently, would be very unintuitive for the user. + [NSException raise:NSInvalidArgumentException + format:@"Metadata keys ending in '-bin' are reserved for NSData values."]; + } + // TODO(jcanizales): Encode Unicode chars as ASCII. + metadata->key = key.UTF8String; + metadata->value = self.UTF8String; + metadata->value_length = self.length; +} +@end + +#pragma mark Category for metadata arrays + @implementation NSDictionary (GRPC) + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count { NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { - // TODO(jcanizales): Verify in a C library test that it's converting header names to lower case automatically. - NSString *name = [NSString stringWithUTF8String:entry->key]; + // TODO(jcanizales): Verify in a C library test that it's converting header names to lower case + // automatically. + NSString *name = [NSString stringWithCString:entry->key encoding:NSASCIIStringEncoding]; if (!name) { + // log? continue; } + id value; + if ([name hasSuffix:@"-bin"]) { + name = [name substringToIndex:name.length - 4]; + value = [NSData grpc_dataFromMetadataValue:entry]; + } else { + value = [NSString grpc_stringFromMetadataValue:entry]; + } if (!metadata[name]) { metadata[name] = [NSMutableArray array]; } - // TODO(jcanizales): Should we use a non-copy constructor? - [metadata[name] addObject:[NSData dataWithBytes:entry->value - length:entry->value_length]]; + [metadata[name] addObject:value]; } return metadata; } @@ -60,11 +129,8 @@ for (id key in self) { id value = self[key]; grpc_metadata *current = &metadata[i]; - current->key = [key UTF8String]; - if ([value isKindOfClass:[NSData class]]) { - current->value = [value bytes]; - } else if ([value isKindOfClass:[NSString class]]) { - current->value = [value UTF8String]; + if ([value respondsToSelector:@selector(grpc_initMetadata:withKey:)]) { + [value grpc_initMetadata:current withKey:key]; } else { [NSException raise:NSInvalidArgumentException format:@"Metadata values must be NSString or NSData."]; diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb index 8df03ffb3c..16fb1b199d 100755 --- a/src/ruby/bin/interop/interop_client.rb +++ b/src/ruby/bin/interop/interop_client.rb @@ -274,6 +274,7 @@ class NamedTests op = @stub.streaming_input_call(reqs, return_op: true) op.cancel assert_raises(GRPC::Cancelled) { op.execute } + assert(op.cancelled, 'call operation should be CANCELLED') p 'OK: cancel_after_begin' end @@ -282,7 +283,8 @@ class NamedTests ppp = PingPongPlayer.new(msg_sizes) op = @stub.full_duplex_call(ppp.each_item, return_op: true) ppp.canceller_op = op # causes ppp to cancel after the 1st message - assert_raises(GRPC::Cancelled) { op.execute.each { |r| ppp.queue.push(r) } } + op.execute.each { |r| ppp.queue.push(r) } + assert(op.cancelled, 'call operation should be CANCELLED') p 'OK: cancel_after_first_response' end diff --git a/src/ruby/lib/grpc/generic/active_call.rb b/src/ruby/lib/grpc/generic/active_call.rb index 04abab8ac3..3814ef34b4 100644 --- a/src/ruby/lib/grpc/generic/active_call.rb +++ b/src/ruby/lib/grpc/generic/active_call.rb @@ -55,7 +55,6 @@ module GRPC # The ActiveCall class provides simple methods for sending marshallable # data to a call class ActiveCall - include Core::StatusCodes include Core::TimeConsts include Core::CallOps extend Forwardable @@ -129,6 +128,11 @@ module GRPC @output_metadata ||= {} end + # cancelled indicates if the call was cancelled + def cancelled + !@call.status.nil? && @call.status.code == Core::StatusCodes::CANCELLED + end + # multi_req_view provides a restricted view of this ActiveCall for use # in a server client-streaming handler. def multi_req_view @@ -162,6 +166,7 @@ module GRPC ops[RECV_STATUS_ON_CLIENT] = nil if assert_finished batch_result = @call.run_batch(@cq, self, INFINITE_FUTURE, ops) return unless assert_finished + @call.status = batch_result.status batch_result.check_status end @@ -178,6 +183,7 @@ module GRPC @call.metadata.merge!(batch_result.status.metadata) end end + @call.status = batch_result.status batch_result.check_status end @@ -410,9 +416,6 @@ module GRPC start_call(**kw) unless @started bd = BidiCall.new(@call, @cq, @marshal, @unmarshal, @deadline) bd.run_on_client(requests, &blk) - rescue GRPC::Core::CallError => e - finished # checks for Cancelled - raise e end # run_server_bidi orchestrates a BiDi stream processing on a server. diff --git a/src/ruby/lib/grpc/generic/bidi_call.rb b/src/ruby/lib/grpc/generic/bidi_call.rb index f1b9f6b00d..489dd5162a 100644 --- a/src/ruby/lib/grpc/generic/bidi_call.rb +++ b/src/ruby/lib/grpc/generic/bidi_call.rb @@ -78,11 +78,9 @@ module GRPC # @param requests the Enumerable of requests to send # @return an Enumerator of requests to yield def run_on_client(requests, &blk) - @enq_th = start_write_loop(requests) + @enq_th = Thread.new { write_loop(requests) } @loop_th = start_read_loop - replies = each_queued_msg - return replies if blk.nil? - replies.each { |r| blk.call(r) } + each_queued_msg(&blk) end # Begins orchestration of the Bidi stream for a server generating replies. @@ -98,9 +96,8 @@ module GRPC # @param gen_each_reply [Proc] generates the BiDi stream replies. def run_on_server(gen_each_reply) replys = gen_each_reply.call(each_queued_msg) - @enq_th = start_write_loop(replys, is_client: false) @loop_th = start_read_loop - @enq_th.join if @enq_th.alive? + write_loop(replys, is_client: false) end private @@ -126,37 +123,32 @@ module GRPC end end - # during bidi-streaming, read the requests to send from a separate thread - # read so that read_loop does not block waiting for requests to read. - def start_write_loop(requests, is_client: true) - Thread.new do # TODO: run on a thread pool - GRPC.logger.debug('bidi-write-loop: starting') - begin - write_tag = Object.new - count = 0 - requests.each do |req| - GRPC.logger.debug("bidi-write-loop: #{count}") - count += 1 - payload = @marshal.call(req) - @call.run_batch(@cq, write_tag, INFINITE_FUTURE, - SEND_MESSAGE => payload) - end - GRPC.logger.debug("bidi-write-loop: #{count} writes done") - if is_client - GRPC.logger.debug("bidi-write-loop: client sent #{count}, waiting") - @call.run_batch(@cq, write_tag, INFINITE_FUTURE, - SEND_CLOSE_FROM_CLIENT => nil) - batch_result = @call.run_batch(@cq, write_tag, INFINITE_FUTURE, - RECV_STATUS_ON_CLIENT => nil) - batch_result.check_status - end - rescue StandardError => e - GRPC.logger.warn('bidi-write-loop: failed') - GRPC.logger.warn(e) - raise e - end - GRPC.logger.debug('bidi-write-loop: finished') + def write_loop(requests, is_client: true) + GRPC.logger.debug('bidi-write-loop: starting') + write_tag = Object.new + count = 0 + requests.each do |req| + GRPC.logger.debug("bidi-write-loop: #{count}") + count += 1 + payload = @marshal.call(req) + @call.run_batch(@cq, write_tag, INFINITE_FUTURE, + SEND_MESSAGE => payload) + end + GRPC.logger.debug("bidi-write-loop: #{count} writes done") + if is_client + GRPC.logger.debug("bidi-write-loop: client sent #{count}, waiting") + batch_result = @call.run_batch(@cq, write_tag, INFINITE_FUTURE, + SEND_CLOSE_FROM_CLIENT => nil, + RECV_STATUS_ON_CLIENT => nil) + @call.status = batch_result.status + batch_result.check_status + GRPC.logger.debug("bidi-write-loop: done status #{@call.status}") end + GRPC.logger.debug('bidi-write-loop: finished') + rescue StandardError => e + GRPC.logger.warn('bidi-write-loop: failed') + GRPC.logger.warn(e) + raise e end # starts the read loop diff --git a/templates/Makefile.template b/templates/Makefile.template index bc8f1bb1d0..f6028cdecc 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -276,6 +276,8 @@ LDFLAGS += -fPIC endif INCLUDES = . include $(GENDIR) +LDFLAGS += -Llibs/$(CONFIG) + ifeq ($(SYSTEM),Darwin) ifneq ($(wildcard /usr/local/ssl/include),) INCLUDES += /usr/local/ssl/include @@ -1220,7 +1222,7 @@ endif mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)' if lib.get('secure', 'check') == 'yes': - common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)' + common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' for src in lib.src: sources_that_need_openssl.add(src) else: diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c index 9d1c4ce2d7..4cc1ad4312 100644 --- a/test/core/bad_client/bad_client.c +++ b/test/core/bad_client/bad_client.c @@ -88,7 +88,7 @@ void grpc_run_bad_client_test(const char *name, const char *client_payload, grpc_init(); /* Create endpoints */ - sfd = grpc_iomgr_create_endpoint_pair(65536); + sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); /* Create server, completion events */ a.server = grpc_server_create_from_filters(NULL, 0, NULL); diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/chttp2_socket_pair.c index e0221d0452..48c121c7c4 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair.c @@ -98,7 +98,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( f.client_cq = grpc_completion_queue_create(); f.server_cq = grpc_completion_queue_create(); - *sfd = grpc_iomgr_create_endpoint_pair(65536); + *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); return f; } diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c index 37b5529d7f..1d2e6f51c1 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c @@ -98,7 +98,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( f.client_cq = grpc_completion_queue_create(); f.server_cq = grpc_completion_queue_create(); - *sfd = grpc_iomgr_create_endpoint_pair(1); + *sfd = grpc_iomgr_create_endpoint_pair("fixture", 1); return f; } diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c index b15a18f1a7..d32dbec25e 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c @@ -99,7 +99,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( f.client_cq = grpc_completion_queue_create(); f.server_cq = grpc_completion_queue_create(); - *sfd = grpc_iomgr_create_endpoint_pair(65536); + *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); return f; } diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 57e2c6fc17..2c8a89e4cd 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -208,7 +208,7 @@ static void listen_cb(void *arg, /*=sv_arg*/ fcntl(fd, F_SETFL, flags | O_NONBLOCK); se = gpr_malloc(sizeof(*se)); se->sv = sv; - se->em_fd = grpc_fd_create(fd); + se->em_fd = grpc_fd_create(fd, "listener"); se->session_read_closure.cb = session_read_cb; se->session_read_closure.cb_arg = se; grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); @@ -236,7 +236,7 @@ static int server_start(server *sv) { port = ntohs(sin.sin_port); GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); - sv->em_fd = grpc_fd_create(fd); + sv->em_fd = grpc_fd_create(fd, "server"); /* Register to be interested in reading from listen_fd. */ sv->listen_closure.cb = listen_cb; sv->listen_closure.cb_arg = sv; @@ -351,7 +351,7 @@ static void client_start(client *cl, int port) { } } - cl->em_fd = grpc_fd_create(fd); + cl->em_fd = grpc_fd_create(fd, "client"); client_session_write(cl, 1); } @@ -447,7 +447,7 @@ static void test_grpc_fd_change(void) { flags = fcntl(sv[1], F_GETFL, 0); GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); - em_fd = grpc_fd_create(sv[0]); + em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change"); /* Register the first callback, then make its FD readable */ grpc_fd_notify_on_read(em_fd, &first_closure); diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 40abed5f6e..2cfcc8311c 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -172,7 +172,7 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1]), slice_size); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -213,7 +213,7 @@ static void large_read_test(ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1]), slice_size); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -350,7 +350,8 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1]), GRPC_TCP_DEFAULT_READ_SLICE_SIZE); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), + GRPC_TCP_DEFAULT_READ_SLICE_SIZE); gpr_mu_init(&state.mu); gpr_cv_init(&state.cv); @@ -406,7 +407,8 @@ static void write_error_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1]), GRPC_TCP_DEFAULT_READ_SLICE_SIZE); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_error_test"), + GRPC_TCP_DEFAULT_READ_SLICE_SIZE); close(sv[0]); gpr_mu_init(&state.mu); @@ -473,8 +475,10 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( grpc_endpoint_test_fixture f; create_sockets(sv); - f.client_ep = grpc_tcp_create(grpc_fd_create(sv[0]), slice_size); - f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1]), slice_size); + f.client_ep = + grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), slice_size); + f.server_ep = + grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), slice_size); return f; } diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c index 7a40fe0dbb..3202df3328 100644 --- a/test/core/security/fetch_oauth2.c +++ b/test/core/security/fetch_oauth2.c @@ -51,7 +51,8 @@ typedef struct { int is_done; } synchronizer; -static void on_oauth2_response(void *user_data, grpc_mdelem **md_elems, +static void on_oauth2_response(void *user_data, + grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { synchronizer *sync = user_data; char *token; @@ -60,7 +61,7 @@ static void on_oauth2_response(void *user_data, grpc_mdelem **md_elems, gpr_log(GPR_ERROR, "Fetching token failed."); } else { GPR_ASSERT(num_md == 1); - token_slice = md_elems[0]->value->slice; + token_slice = md_elems[0].value; token = gpr_malloc(GPR_SLICE_LENGTH(token_slice) + 1); memcpy(token, GPR_SLICE_START_PTR(token_slice), GPR_SLICE_LENGTH(token_slice)); diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index 76e69ef716..051e8607c4 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -49,7 +49,8 @@ typedef struct { int is_done; } synchronizer; -static void on_metadata_response(void *user_data, grpc_mdelem **md_elems, +static void on_metadata_response(void *user_data, + grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { synchronizer *sync = user_data; @@ -58,7 +59,7 @@ static void on_metadata_response(void *user_data, grpc_mdelem **md_elems, } else { GPR_ASSERT(num_md == 1); printf("\nGot token: %s\n\n", - (const char *)GPR_SLICE_START_PTR(md_elems[0]->value->slice)); + (const char *)GPR_SLICE_START_PTR(md_elems[0].value)); } gpr_mu_lock(&sync->mu); sync->is_done = 1; diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index 6477454e8a..30b23624d8 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -51,7 +51,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( grpc_endpoint_test_fixture f; grpc_endpoint_pair tcp; - tcp = grpc_iomgr_create_endpoint_pair(slice_size); + tcp = grpc_iomgr_create_endpoint_pair("fixture", slice_size); if (leftover_nslices == 0) { f.client_ep = diff --git a/test/core/support/tls_test.c b/test/core/support/tls_test.c index 8632fd4490..0a3c28417f 100644 --- a/test/core/support/tls_test.c +++ b/test/core/support/tls_test.c @@ -54,6 +54,7 @@ static void thd_body(void *arg) { gpr_tls_set(&test_var, i); GPR_ASSERT(gpr_tls_get(&test_var) == i); } + gpr_tls_set(&test_var, 0); } /* ------------------------------------------------- */ diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index e26f379bfc..9e7b2ea1df 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -94,6 +94,26 @@ static void test_cq_end_op(void) { shutdown_and_destroy(cc); } +static void test_shutdown_then_next_polling(void) { + grpc_completion_queue *cc; + LOG_TEST("test_shutdown_then_next_polling"); + + cc = grpc_completion_queue_create(); + grpc_completion_queue_shutdown(cc); + GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_past).type == GRPC_QUEUE_SHUTDOWN); + grpc_completion_queue_destroy(cc); +} + +static void test_shutdown_then_next_with_timeout(void) { + grpc_completion_queue *cc; + LOG_TEST("test_shutdown_then_next_with_timeout"); + + cc = grpc_completion_queue_create(); + grpc_completion_queue_shutdown(cc); + GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_future).type == GRPC_QUEUE_SHUTDOWN); + grpc_completion_queue_destroy(cc); +} + static void test_pluck(void) { grpc_event ev; grpc_completion_queue *cc; @@ -291,6 +311,8 @@ int main(int argc, char **argv) { grpc_iomgr_init(); test_no_op(); test_wait_empty(); + test_shutdown_then_next_polling(); + test_shutdown_then_next_with_timeout(); test_cq_end_op(); test_pluck(); test_threading(1, 1); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 7a15591b44..f48cf953a4 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -31,6 +31,7 @@ * */ +#include <mutex> #include <thread> #include "src/core/security/credentials.h" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 310227a29c..5ee29e40f4 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -31,6 +31,7 @@ * */ +#include <mutex> #include <thread> #include "test/core/util/port.h" diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index b9998405f6..977dfc2372 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -33,6 +33,7 @@ #include <forward_list> #include <functional> +#include <memory> #include <mutex> #include <sys/time.h> #include <sys/resource.h> @@ -158,11 +159,12 @@ class AsyncQpsServerTest : public Server { void *)> request_method, std::function<grpc::Status(const RequestType *, ResponseType *)> invoke_method) - : next_state_(&ServerRpcContextUnaryImpl::invoker), + : srv_ctx_(new ServerContext), + next_state_(&ServerRpcContextUnaryImpl::invoker), request_method_(request_method), invoke_method_(invoke_method), - response_writer_(&srv_ctx_) { - request_method_(&srv_ctx_, &req_, &response_writer_, + response_writer_(srv_ctx_.get()) { + request_method_(srv_ctx_.get(), &req_, &response_writer_, AsyncQpsServerTest::tag(this)); } ~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {} @@ -170,14 +172,14 @@ class AsyncQpsServerTest : public Server { return (this->*next_state_)(ok); } void Reset() GRPC_OVERRIDE { - srv_ctx_ = ServerContext(); + srv_ctx_.reset(new ServerContext); req_ = RequestType(); response_writer_ = - grpc::ServerAsyncResponseWriter<ResponseType>(&srv_ctx_); + grpc::ServerAsyncResponseWriter<ResponseType>(srv_ctx_.get()); // Then request the method next_state_ = &ServerRpcContextUnaryImpl::invoker; - request_method_(&srv_ctx_, &req_, &response_writer_, + request_method_(srv_ctx_.get(), &req_, &response_writer_, AsyncQpsServerTest::tag(this)); } @@ -198,7 +200,7 @@ class AsyncQpsServerTest : public Server { response_writer_.Finish(response, status, AsyncQpsServerTest::tag(this)); return true; } - ServerContext srv_ctx_; + std::unique_ptr<ServerContext> srv_ctx_; RequestType req_; bool (ServerRpcContextUnaryImpl::*next_state_)(bool); std::function<void(ServerContext *, RequestType *, @@ -218,25 +220,26 @@ class AsyncQpsServerTest : public Server { void *)> request_method, std::function<grpc::Status(const RequestType *, ResponseType *)> invoke_method) - : next_state_(&ServerRpcContextStreamingImpl::request_done), + : srv_ctx_(new ServerContext), + next_state_(&ServerRpcContextStreamingImpl::request_done), request_method_(request_method), invoke_method_(invoke_method), - stream_(&srv_ctx_) { - request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this)); + stream_(srv_ctx_.get()) { + request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this)); } ~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {} bool RunNextState(bool ok) GRPC_OVERRIDE { return (this->*next_state_)(ok); } void Reset() GRPC_OVERRIDE { - srv_ctx_ = ServerContext(); + srv_ctx_.reset(new ServerContext); req_ = RequestType(); - stream_ = - grpc::ServerAsyncReaderWriter<ResponseType, RequestType>(&srv_ctx_); + stream_ = grpc::ServerAsyncReaderWriter<ResponseType, RequestType>( + srv_ctx_.get()); // Then request the method next_state_ = &ServerRpcContextStreamingImpl::request_done; - request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this)); + request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this)); } private: @@ -278,7 +281,7 @@ class AsyncQpsServerTest : public Server { } bool finish_done(bool ok) { return false; /* reset the context */ } - ServerContext srv_ctx_; + std::unique_ptr<ServerContext> srv_ctx_; RequestType req_; bool (ServerRpcContextStreamingImpl::*next_state_)(bool); std::function<void( diff --git a/tools/dockerfile/grpc_java/Dockerfile b/tools/dockerfile/grpc_java/Dockerfile index fa67cb2627..c20ab4687c 100644 --- a/tools/dockerfile/grpc_java/Dockerfile +++ b/tools/dockerfile/grpc_java/Dockerfile @@ -36,5 +36,8 @@ RUN cd /var/local/git/grpc-java/lib/netty && \ RUN cd /var/local/git/grpc-java && \ ./gradlew build installDist +# Add a service_account directory containing the auth creds file +ADD service_account service_account + # Specify the default command such that the interop server runs on its known testing port CMD ["/var/local/git/grpc-java/run-test-server.sh", "--use_tls=true", "--port=8030"] diff --git a/tools/gce_setup/grpc_docker.sh b/tools/gce_setup/grpc_docker.sh index 123d0615b4..b53aa98aab 100755 --- a/tools/gce_setup/grpc_docker.sh +++ b/tools/gce_setup/grpc_docker.sh @@ -1274,8 +1274,7 @@ grpc_cloud_prod_gen_go_cmd() { # cmd=$($grpc_gen_test_cmd $flags) grpc_interop_gen_java_cmd() { local cmd_prefix="sudo docker run grpc/java"; - local test_script="/var/local/git/grpc-java/run-test-client.sh"; - local test_script+=" --use_test_ca=true --use_tls=true" + local test_script="/var/local/git/grpc-java/run-test-client.sh --use_test_ca=true --use_tls=true"; local the_cmd="$cmd_prefix $test_script $@"; echo $the_cmd } @@ -1287,13 +1286,40 @@ grpc_interop_gen_java_cmd() { # cmd=$($grpc_gen_test_cmd $flags) grpc_cloud_prod_gen_java_cmd() { local cmd_prefix="sudo docker run grpc/java"; - local test_script="/var/local/git/grpc-java/run-test-client.sh"; - local test_script+=" --use_tls=true" + local test_script="/var/local/git/grpc-java/run-test-client.sh --use_tls=true"; local gfe_flags=$(_grpc_prod_gfe_flags) local the_cmd="$cmd_prefix $test_script $gfe_flags $@"; echo $the_cmd } +# constructs the full dockerized java service_account auth interop test cmd. +# +# call-seq: +# flags= .... # generic flags to include the command +# cmd=$($grpc_gen_test_cmd $flags) +grpc_cloud_prod_auth_service_account_creds_gen_java_cmd() { + local cmd_prefix="sudo docker run grpc/java"; + local test_script="/var/local/git/grpc-java/run-test-client.sh --use_tls=true"; + local gfe_flags=$(_grpc_prod_gfe_flags) + local added_gfe_flags=$(_grpc_svc_acc_test_flags) + local the_cmd="$cmd_prefix $test_script $gfe_flags $added_gfe_flags $@"; + echo $the_cmd +} + +# constructs the full dockerized java gce auth interop test cmd. +# +# call-seq: +# flags= .... # generic flags to include the command +# cmd=$($grpc_gen_test_cmd $flags) +grpc_cloud_prod_auth_compute_engine_creds_gen_java_cmd() { + local cmd_prefix="sudo docker run grpc/java"; + local test_script="/var/local/git/grpc-java/run-test-client.sh --use_tls=true"; + local gfe_flags=$(_grpc_prod_gfe_flags) + local added_gfe_flags=$(_grpc_gce_test_flags) + local the_cmd="$cmd_prefix $test_script $gfe_flags $added_gfe_flags $@"; + echo $the_cmd +} + # constructs the full dockerized php interop test cmd. # # TODO(mlumish): update this to use the script once that's on git diff --git a/tools/gce_setup/shared_startup_funcs.sh b/tools/gce_setup/shared_startup_funcs.sh index a3a3b59c8a..60cd9f6897 100755 --- a/tools/gce_setup/shared_startup_funcs.sh +++ b/tools/gce_setup/shared_startup_funcs.sh @@ -413,6 +413,9 @@ grpc_dockerfile_install() { [[ $image_label == "grpc/java_base" ]] && { grpc_docker_sync_github_key $dockerfile_dir/.ssh 'java_base_ssh_key' || return 1; } + [[ $image_label == "grpc/java" ]] && { + grpc_docker_sync_service_account $dockerfile_dir/service_account || return 1; + } [[ $image_label == "grpc/ruby" ]] && { grpc_docker_sync_roots_pem $dockerfile_dir/cacerts || return 1; grpc_docker_sync_service_account $dockerfile_dir/service_account || return 1; diff --git a/tools/run_tests/run_csharp.bat b/tools/run_tests/run_csharp.bat new file mode 100644 index 0000000000..17c622cc2d --- /dev/null +++ b/tools/run_tests/run_csharp.bat @@ -0,0 +1,16 @@ +@rem Runs C# tests for given assembly from command line. The Grpc.sln solution needs to be built before running the tests. + +setlocal + +@rem enter this directory +cd /d %~dp0\..\..\src\csharp + +packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe -labels "%1/bin/Debug/%1.dll" || goto :error + +endlocal + +goto :EOF + +:error +echo Failed! +exit /b %errorlevel% diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index bd5959cd00..c00d7941f4 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -234,20 +234,36 @@ class RubyLanguage(object): class CSharpLanguage(object): + def __init__(self): + if platform.system() == 'Windows': + plat = 'windows' + else: + plat = 'posix' + self.platform = plat + def test_specs(self, config, travis): assemblies = ['Grpc.Core.Tests', 'Grpc.Examples.Tests', 'Grpc.IntegrationTesting'] - return [config.job_spec(['tools/run_tests/run_csharp.sh', assembly], + if self.platform == 'windows': + cmd = 'tools\\run_tests\\run_csharp.bat' + else: + cmd = 'tools/run_tests/run_csharp.sh' + return [config.job_spec([cmd, assembly], None, shortname=assembly, environ={'GRPC_TRACE': 'surface,batch'}) for assembly in assemblies ] def make_targets(self): + # For Windows, this target doesn't really build anything, + # everything is build by buildall script later. return ['grpc_csharp_ext'] def build_steps(self): - return [['tools/run_tests/build_csharp.sh']] + if self.platform == 'windows': + return [['src\\csharp\\buildall.bat']] + else: + return [['tools/run_tests/build_csharp.sh']] def supports_multi_config(self): return False @@ -346,6 +362,7 @@ def runs_per_test_type(arg_str): try: n = int(arg_str) if n <= 0: raise ValueError + return n except: msg = "'{}' isn't a positive integer or 'inf'".format(arg_str) raise argparse.ArgumentTypeError(msg) diff --git a/vsprojects/nuget_package/grpc.native.csharp_ext.nuspec b/vsprojects/nuget_package/grpc.native.csharp_ext.nuspec index 2527f4c415..211d747e2d 100644 --- a/vsprojects/nuget_package/grpc.native.csharp_ext.nuspec +++ b/vsprojects/nuget_package/grpc.native.csharp_ext.nuspec @@ -2,14 +2,14 @@ <package> <metadata> <id>grpc.native.csharp_ext</id> - <version>0.9.0.0</version> + <version>0.9.1</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> <licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl> <projectUrl>http://github.com/grpc/grpc</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Native extension needed by gRPC C# library. This is not the package you are looking for, it is only meant to be used as a dependency.</description> - <releaseNotes>Release of gRPC C core 0.9.0 libraries.</releaseNotes> + <releaseNotes>Release of gRPC C core 0.9.1 libraries.</releaseNotes> <copyright>Copyright 2015</copyright> <title>gRPC C# Native Extension</title> <summary>Native library required by gRPC C#</summary> @@ -27,4 +27,4 @@ <file src="output\v100\Win32\Debug\grpc_csharp_ext.dll" target="/build/native/bin/v100\Win32\Debug\grpc_csharp_ext.dll" /> <file src="output\v120\Win32\Debug\grpc_csharp_ext.dll" target="/build/native/bin/v120\Win32\Debug\grpc_csharp_ext.dll" /> </files> -</package>
\ No newline at end of file +</package> |