aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/ext/grpc/rb_channel.c
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2016-12-09 17:39:33 -0800
committerGravatar Alexander Polcyn <apolcyn@google.com>2016-12-12 22:40:48 -0800
commit70f4d26e0f164c2ccf5d9530681d25913a2c4509 (patch)
tree8d7d2a345531d92da5733b76a97fe307d7ea0500 /src/ruby/ext/grpc/rb_channel.c
parent58a81ac72314940d04ddb1e49c9b18e75d306f83 (diff)
convert char* to grpc_slice in ruby
Diffstat (limited to 'src/ruby/ext/grpc/rb_channel.c')
-rw-r--r--src/ruby/ext/grpc/rb_channel.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c
index 3b2b88eb77..84e43d3f7b 100644
--- a/src/ruby/ext/grpc/rb_channel.c
+++ b/src/ruby/ext/grpc/rb_channel.c
@@ -35,6 +35,7 @@
#include "rb_grpc_imports.generated.h"
#include "rb_channel.h"
+#include "rb_byte_buffer.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
@@ -252,10 +253,14 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent,
grpc_channel *ch = NULL;
grpc_completion_queue *cq = NULL;
int flags = GRPC_PROPAGATE_DEFAULTS;
- char *method_chars = StringValueCStr(method);
- char *host_chars = NULL;
+ grpc_slice method_slice;
+ grpc_slice host_slice;
+ grpc_slice *host_slice_ptr = NULL;
+ char* tmp_str = NULL;
+
if (host != Qnil) {
- host_chars = StringValueCStr(host);
+ host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host));
+ host_slice_ptr = &host_slice;
}
if (mask != Qnil) {
flags = NUM2UINT(mask);
@@ -272,15 +277,25 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent,
return Qnil;
}
- call = grpc_channel_create_call(ch, parent_call, flags, cq, method_chars,
- host_chars, grpc_rb_time_timeval(
+ 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,
+ host_slice_ptr, grpc_rb_time_timeval(
deadline,
/* absolute time */ 0), NULL);
+
if (call == NULL) {
+ tmp_str = grpc_slice_to_c_string(method_slice);
rb_raise(rb_eRuntimeError, "cannot create call with method %s",
- method_chars);
+ tmp_str);
return Qnil;
}
+
+ grpc_slice_unref(method_slice);
+ if (host_slice_ptr != NULL) {
+ grpc_slice_unref(host_slice);
+ }
+
res = grpc_rb_wrap_call(call, cq);
/* Make this channel an instance attribute of the call so that it is not GCed