aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/ext/grpc/rb_server.c
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2016-05-16 14:53:13 -0700
committerGravatar murgatroid99 <mlumish@google.com>2016-05-16 14:53:13 -0700
commitd595fb65574007527eab0c03bc90de4e6e3b2ac8 (patch)
treeb191508ac202836f9613832f07f88bde67f1af1a /src/ruby/ext/grpc/rb_server.c
parent1ba1bba66a18b6b7986a1cfa52c6f1ac4a14a029 (diff)
Handle signals properly when dropping GVL
Diffstat (limited to 'src/ruby/ext/grpc/rb_server.c')
-rw-r--r--src/ruby/ext/grpc/rb_server.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c
index 2b3acaaf59..aa7fa0af8e 100644
--- a/src/ruby/ext/grpc/rb_server.c
+++ b/src/ruby/ext/grpc/rb_server.c
@@ -60,6 +60,7 @@ typedef struct grpc_rb_server {
VALUE mark;
/* The actual server */
grpc_server *wrapped;
+ grpc_completion_queue *queue;
} grpc_rb_server;
/* Destroys server instances. */
@@ -145,6 +146,7 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
}
grpc_server_register_completion_queue(srv, cq, NULL);
wrapper->wrapped = srv;
+ wrapper->queue = cq;
/* Add the cq as the server's mark object. This ensures the ruby cq can't be
GCed before the server */
@@ -205,6 +207,11 @@ static void grpc_request_call_stack_cleanup(request_call_stack* st) {
grpc_call_details_destroy(&st->details);
}
+static void request_call_unblock_func(void *ptr) {
+ grpc_rb_server *rb_srv = (grpc_rb_server*)ptr;
+ grpc_server_shutdown_and_notify(rb_srv->wrapped, rb_srv->queue, rb_srv);
+}
+
/* call-seq:
cq = CompletionQueue.new
tag = Object.new
@@ -242,7 +249,9 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
return Qnil;
}
- ev = grpc_rb_completion_queue_pluck_event(cqueue, tag_new, timeout);
+ ev = grpc_rb_completion_queue_pluck_event(cqueue, tag_new, timeout,
+ request_call_unblock_func,
+ (void*)s);
if (ev.type == GRPC_QUEUE_TIMEOUT) {
grpc_request_call_stack_cleanup(&st);
return Qnil;
@@ -305,7 +314,8 @@ static VALUE grpc_rb_server_destroy(int argc, VALUE *argv, VALUE self) {
if (s->wrapped != NULL) {
grpc_server_shutdown_and_notify(s->wrapped, cq, NULL);
- ev = grpc_rb_completion_queue_pluck_event(cqueue, Qnil, timeout);
+ ev = grpc_rb_completion_queue_pluck_event(cqueue, Qnil, timeout,
+ NULL, NULL);
if (!ev.success) {
rb_warn("server shutdown failed, cancelling the calls, objects may leak");
grpc_server_cancel_all_calls(s->wrapped);