|
|
@ -33,20 +33,20 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <ruby/ruby.h> |
|
|
|
#include <ruby/ruby.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "rb_grpc_imports.generated.h" |
|
|
|
|
|
|
|
#include "rb_channel.h" |
|
|
|
|
|
|
|
#include "rb_byte_buffer.h" |
|
|
|
#include "rb_byte_buffer.h" |
|
|
|
|
|
|
|
#include "rb_channel.h" |
|
|
|
|
|
|
|
#include "rb_grpc_imports.generated.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/grpc.h> |
|
|
|
#include <grpc/grpc.h> |
|
|
|
#include <grpc/grpc_security.h> |
|
|
|
#include <grpc/grpc_security.h> |
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/time.h> |
|
|
|
#include <grpc/support/time.h> |
|
|
|
#include "rb_grpc.h" |
|
|
|
|
|
|
|
#include "rb_call.h" |
|
|
|
#include "rb_call.h" |
|
|
|
#include "rb_channel_args.h" |
|
|
|
#include "rb_channel_args.h" |
|
|
|
#include "rb_channel_credentials.h" |
|
|
|
#include "rb_channel_credentials.h" |
|
|
|
#include "rb_completion_queue.h" |
|
|
|
#include "rb_completion_queue.h" |
|
|
|
|
|
|
|
#include "rb_grpc.h" |
|
|
|
#include "rb_server.h" |
|
|
|
#include "rb_server.h" |
|
|
|
|
|
|
|
|
|
|
|
/* id_channel is the name of the hidden ivar that preserves a reference to the
|
|
|
|
/* id_channel is the name of the hidden ivar that preserves a reference to the
|
|
|
@ -104,11 +104,13 @@ static void grpc_rb_channel_mark(void *p) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static rb_data_type_t grpc_channel_data_type = { |
|
|
|
static rb_data_type_t grpc_channel_data_type = {"grpc_channel", |
|
|
|
"grpc_channel", |
|
|
|
{grpc_rb_channel_mark, |
|
|
|
{grpc_rb_channel_mark, grpc_rb_channel_free, GRPC_RB_MEMSIZE_UNAVAILABLE, |
|
|
|
grpc_rb_channel_free, |
|
|
|
|
|
|
|
GRPC_RB_MEMSIZE_UNAVAILABLE, |
|
|
|
{NULL, NULL}}, |
|
|
|
{NULL, NULL}}, |
|
|
|
NULL, NULL, |
|
|
|
NULL, |
|
|
|
|
|
|
|
NULL, |
|
|
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY |
|
|
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY |
|
|
|
RUBY_TYPED_FREE_IMMEDIATELY |
|
|
|
RUBY_TYPED_FREE_IMMEDIATELY |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -169,7 +171,8 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) { |
|
|
|
} |
|
|
|
} |
|
|
|
rb_ivar_set(self, id_target, target); |
|
|
|
rb_ivar_set(self, id_target, target); |
|
|
|
wrapper->wrapped = ch; |
|
|
|
wrapper->wrapped = ch; |
|
|
|
wrapper->queue = grpc_completion_queue_create(NULL); |
|
|
|
wrapper->queue = grpc_completion_queue_create(GRPC_CQ_PLUCK, |
|
|
|
|
|
|
|
GRPC_CQ_DEFAULT_POLLING, NULL); |
|
|
|
return self; |
|
|
|
return self; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -225,14 +228,11 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self, |
|
|
|
return Qnil; |
|
|
|
return Qnil; |
|
|
|
} |
|
|
|
} |
|
|
|
grpc_channel_watch_connectivity_state( |
|
|
|
grpc_channel_watch_connectivity_state( |
|
|
|
ch, |
|
|
|
ch, (grpc_connectivity_state)NUM2LONG(last_state), |
|
|
|
(grpc_connectivity_state)NUM2LONG(last_state), |
|
|
|
grpc_rb_time_timeval(deadline, /* absolute time */ 0), cq, tag); |
|
|
|
grpc_rb_time_timeval(deadline, /* absolute time */ 0), |
|
|
|
|
|
|
|
cq, |
|
|
|
|
|
|
|
tag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event = rb_completion_queue_pluck(cq, tag, |
|
|
|
event = rb_completion_queue_pluck(cq, tag, gpr_inf_future(GPR_CLOCK_REALTIME), |
|
|
|
gpr_inf_future(GPR_CLOCK_REALTIME), NULL); |
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
|
|
if (event.success) { |
|
|
|
if (event.success) { |
|
|
|
return Qtrue; |
|
|
|
return Qtrue; |
|
|
@ -243,9 +243,9 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self, |
|
|
|
|
|
|
|
|
|
|
|
/* Create a call given a grpc_channel, in order to call method. The request
|
|
|
|
/* Create a call given a grpc_channel, in order to call method. The request
|
|
|
|
is not sent until grpc_call_invoke is called. */ |
|
|
|
is not sent until grpc_call_invoke is called. */ |
|
|
|
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, |
|
|
|
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask, |
|
|
|
VALUE mask, VALUE method, |
|
|
|
VALUE method, VALUE host, |
|
|
|
VALUE host, VALUE deadline) { |
|
|
|
VALUE deadline) { |
|
|
|
VALUE res = Qnil; |
|
|
|
VALUE res = Qnil; |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
|
grpc_call *call = NULL; |
|
|
|
grpc_call *call = NULL; |
|
|
@ -259,7 +259,8 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, |
|
|
|
char *tmp_str = NULL; |
|
|
|
char *tmp_str = NULL; |
|
|
|
|
|
|
|
|
|
|
|
if (host != Qnil) { |
|
|
|
if (host != Qnil) { |
|
|
|
host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); |
|
|
|
host_slice = |
|
|
|
|
|
|
|
grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); |
|
|
|
host_slice_ptr = &host_slice; |
|
|
|
host_slice_ptr = &host_slice; |
|
|
|
} |
|
|
|
} |
|
|
|
if (mask != Qnil) { |
|
|
|
if (mask != Qnil) { |
|
|
@ -269,7 +270,8 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, |
|
|
|
parent_call = grpc_rb_get_wrapped_call(parent); |
|
|
|
parent_call = grpc_rb_get_wrapped_call(parent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cq = grpc_completion_queue_create(NULL); |
|
|
|
cq = grpc_completion_queue_create(GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, |
|
|
|
|
|
|
|
NULL); |
|
|
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper); |
|
|
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper); |
|
|
|
ch = wrapper->wrapped; |
|
|
|
ch = wrapper->wrapped; |
|
|
|
if (ch == NULL) { |
|
|
|
if (ch == NULL) { |
|
|
@ -277,17 +279,18 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, |
|
|
|
return Qnil; |
|
|
|
return Qnil; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); |
|
|
|
method_slice = |
|
|
|
|
|
|
|
grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); |
|
|
|
|
|
|
|
|
|
|
|
call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice, |
|
|
|
call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice, |
|
|
|
host_slice_ptr, grpc_rb_time_timeval( |
|
|
|
host_slice_ptr, |
|
|
|
deadline, |
|
|
|
grpc_rb_time_timeval(deadline, |
|
|
|
/* absolute time */ 0), NULL); |
|
|
|
/* absolute time */ 0), |
|
|
|
|
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
|
|
if (call == NULL) { |
|
|
|
if (call == NULL) { |
|
|
|
tmp_str = grpc_slice_to_c_string(method_slice); |
|
|
|
tmp_str = grpc_slice_to_c_string(method_slice); |
|
|
|
rb_raise(rb_eRuntimeError, "cannot create call with method %s", |
|
|
|
rb_raise(rb_eRuntimeError, "cannot create call with method %s", tmp_str); |
|
|
|
tmp_str); |
|
|
|
|
|
|
|
return Qnil; |
|
|
|
return Qnil; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -304,7 +307,6 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Closes the channel, calling it's destroy method */ |
|
|
|
/* Closes the channel, calling it's destroy method */ |
|
|
|
static VALUE grpc_rb_channel_destroy(VALUE self) { |
|
|
|
static VALUE grpc_rb_channel_destroy(VALUE self) { |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
@ -320,7 +322,6 @@ static VALUE grpc_rb_channel_destroy(VALUE self) { |
|
|
|
return Qnil; |
|
|
|
return Qnil; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Called to obtain the target that this channel accesses. */ |
|
|
|
/* Called to obtain the target that this channel accesses. */ |
|
|
|
static VALUE grpc_rb_channel_get_target(VALUE self) { |
|
|
|
static VALUE grpc_rb_channel_get_target(VALUE self) { |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
|
grpc_rb_channel *wrapper = NULL; |
|
|
@ -337,8 +338,8 @@ static VALUE grpc_rb_channel_get_target(VALUE self) { |
|
|
|
|
|
|
|
|
|
|
|
static void Init_grpc_propagate_masks() { |
|
|
|
static void Init_grpc_propagate_masks() { |
|
|
|
/* Constants representing call propagation masks in grpc.h */ |
|
|
|
/* Constants representing call propagation masks in grpc.h */ |
|
|
|
VALUE grpc_rb_mPropagateMasks = rb_define_module_under( |
|
|
|
VALUE grpc_rb_mPropagateMasks = |
|
|
|
grpc_rb_mGrpcCore, "PropagateMasks"); |
|
|
|
rb_define_module_under(grpc_rb_mGrpcCore, "PropagateMasks"); |
|
|
|
rb_define_const(grpc_rb_mPropagateMasks, "DEADLINE", |
|
|
|
rb_define_const(grpc_rb_mPropagateMasks, "DEADLINE", |
|
|
|
UINT2NUM(GRPC_PROPAGATE_DEADLINE)); |
|
|
|
UINT2NUM(GRPC_PROPAGATE_DEADLINE)); |
|
|
|
rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_STATS_CONTEXT", |
|
|
|
rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_STATS_CONTEXT", |
|
|
@ -353,8 +354,8 @@ static void Init_grpc_propagate_masks() { |
|
|
|
|
|
|
|
|
|
|
|
static void Init_grpc_connectivity_states() { |
|
|
|
static void Init_grpc_connectivity_states() { |
|
|
|
/* Constants representing call propagation masks in grpc.h */ |
|
|
|
/* Constants representing call propagation masks in grpc.h */ |
|
|
|
VALUE grpc_rb_mConnectivityStates = rb_define_module_under( |
|
|
|
VALUE grpc_rb_mConnectivityStates = |
|
|
|
grpc_rb_mGrpcCore, "ConnectivityStates"); |
|
|
|
rb_define_module_under(grpc_rb_mGrpcCore, "ConnectivityStates"); |
|
|
|
rb_define_const(grpc_rb_mConnectivityStates, "IDLE", |
|
|
|
rb_define_const(grpc_rb_mConnectivityStates, "IDLE", |
|
|
|
LONG2NUM(GRPC_CHANNEL_IDLE)); |
|
|
|
LONG2NUM(GRPC_CHANNEL_IDLE)); |
|
|
|
rb_define_const(grpc_rb_mConnectivityStates, "CONNECTING", |
|
|
|
rb_define_const(grpc_rb_mConnectivityStates, "CONNECTING", |
|
|
@ -382,12 +383,11 @@ void Init_grpc_channel() { |
|
|
|
|
|
|
|
|
|
|
|
/* Add ruby analogues of the Channel methods. */ |
|
|
|
/* Add ruby analogues of the Channel methods. */ |
|
|
|
rb_define_method(grpc_rb_cChannel, "connectivity_state", |
|
|
|
rb_define_method(grpc_rb_cChannel, "connectivity_state", |
|
|
|
grpc_rb_channel_get_connectivity_state, |
|
|
|
grpc_rb_channel_get_connectivity_state, -1); |
|
|
|
-1); |
|
|
|
|
|
|
|
rb_define_method(grpc_rb_cChannel, "watch_connectivity_state", |
|
|
|
rb_define_method(grpc_rb_cChannel, "watch_connectivity_state", |
|
|
|
grpc_rb_channel_watch_connectivity_state, 4); |
|
|
|
grpc_rb_channel_watch_connectivity_state, 4); |
|
|
|
rb_define_method(grpc_rb_cChannel, "create_call", |
|
|
|
rb_define_method(grpc_rb_cChannel, "create_call", grpc_rb_channel_create_call, |
|
|
|
grpc_rb_channel_create_call, 5); |
|
|
|
5); |
|
|
|
rb_define_method(grpc_rb_cChannel, "target", grpc_rb_channel_get_target, 0); |
|
|
|
rb_define_method(grpc_rb_cChannel, "target", grpc_rb_channel_get_target, 0); |
|
|
|
rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0); |
|
|
|
rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0); |
|
|
|
rb_define_alias(grpc_rb_cChannel, "close", "destroy"); |
|
|
|
rb_define_alias(grpc_rb_cChannel, "close", "destroy"); |
|
|
|