Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
9232f124
Commit
9232f124
authored
10 years ago
by
Yuki Yugui Sonoda
Browse files
Options
Downloads
Patches
Plain Diff
Use TypedData for GRPC::Core::Server
parent
d441c2e5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ruby/ext/grpc/rb_server.c
+23
-10
23 additions, 10 deletions
src/ruby/ext/grpc/rb_server.c
with
23 additions
and
10 deletions
src/ruby/ext/grpc/rb_server.c
+
23
−
10
View file @
9232f124
...
@@ -88,13 +88,23 @@ static void grpc_rb_server_mark(void *p) {
...
@@ -88,13 +88,23 @@ static void grpc_rb_server_mark(void *p) {
}
}
}
}
static
const
rb_data_type_t
grpc_rb_server_data_type
=
{
"grpc_server"
,
{
grpc_rb_server_mark
,
grpc_rb_server_free
,
GRPC_RB_MEMSIZE_UNAVAILABLE
},
NULL
,
NULL
,
/* It is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because the free function would block
* and we might want to unlock GVL
* TODO(yugui) Unlock GVL?
*/
0
};
/* Allocates grpc_rb_server instances. */
/* Allocates grpc_rb_server instances. */
static
VALUE
grpc_rb_server_alloc
(
VALUE
cls
)
{
static
VALUE
grpc_rb_server_alloc
(
VALUE
cls
)
{
grpc_rb_server
*
wrapper
=
ALLOC
(
grpc_rb_server
);
grpc_rb_server
*
wrapper
=
ALLOC
(
grpc_rb_server
);
wrapper
->
wrapped
=
NULL
;
wrapper
->
wrapped
=
NULL
;
wrapper
->
mark
=
Qnil
;
wrapper
->
mark
=
Qnil
;
return
Data_Wrap_Struct
(
cls
,
grpc_rb_server_mark
,
grpc_rb_server_free
,
return
TypedData_Wrap_Struct
(
cls
,
&
grpc_rb_server_data_type
,
wrapper
);
wrapper
);
}
}
/*
/*
...
@@ -110,7 +120,8 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
...
@@ -110,7 +120,8 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
grpc_channel_args
args
;
grpc_channel_args
args
;
MEMZERO
(
&
args
,
grpc_channel_args
,
1
);
MEMZERO
(
&
args
,
grpc_channel_args
,
1
);
cq
=
grpc_rb_get_wrapped_completion_queue
(
cqueue
);
cq
=
grpc_rb_get_wrapped_completion_queue
(
cqueue
);
Data_Get_Struct
(
self
,
grpc_rb_server
,
wrapper
);
TypedData_Get_Struct
(
self
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
wrapper
);
grpc_rb_hash_convert_to_channel_args
(
channel_args
,
&
args
);
grpc_rb_hash_convert_to_channel_args
(
channel_args
,
&
args
);
srv
=
grpc_server_create
(
cq
,
&
args
);
srv
=
grpc_server_create
(
cq
,
&
args
);
...
@@ -146,8 +157,10 @@ static VALUE grpc_rb_server_init_copy(VALUE copy, VALUE orig) {
...
@@ -146,8 +157,10 @@ static VALUE grpc_rb_server_init_copy(VALUE copy, VALUE orig) {
rb_raise
(
rb_eTypeError
,
"not a %s"
,
rb_obj_classname
(
grpc_rb_cServer
));
rb_raise
(
rb_eTypeError
,
"not a %s"
,
rb_obj_classname
(
grpc_rb_cServer
));
}
}
Data_Get_Struct
(
orig
,
grpc_rb_server
,
orig_srv
);
TypedData_Get_Struct
(
orig
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
Data_Get_Struct
(
copy
,
grpc_rb_server
,
copy_srv
);
orig_srv
);
TypedData_Get_Struct
(
copy
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
copy_srv
);
/* use ruby's MEMCPY to make a byte-for-byte copy of the server wrapper
/* use ruby's MEMCPY to make a byte-for-byte copy of the server wrapper
object. */
object. */
...
@@ -194,7 +207,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
...
@@ -194,7 +207,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
grpc_call_error
err
;
grpc_call_error
err
;
request_call_stack
st
;
request_call_stack
st
;
VALUE
result
;
VALUE
result
;
Data_Get_Struct
(
self
,
grpc_rb_server
,
s
);
Typed
Data_Get_Struct
(
self
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
s
);
if
(
s
->
wrapped
==
NULL
)
{
if
(
s
->
wrapped
==
NULL
)
{
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
return
Qnil
;
return
Qnil
;
...
@@ -245,7 +258,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
...
@@ -245,7 +258,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
static
VALUE
grpc_rb_server_start
(
VALUE
self
)
{
static
VALUE
grpc_rb_server_start
(
VALUE
self
)
{
grpc_rb_server
*
s
=
NULL
;
grpc_rb_server
*
s
=
NULL
;
Data_Get_Struct
(
self
,
grpc_rb_server
,
s
);
Typed
Data_Get_Struct
(
self
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
s
);
if
(
s
->
wrapped
==
NULL
)
{
if
(
s
->
wrapped
==
NULL
)
{
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
}
else
{
}
else
{
...
@@ -256,7 +269,7 @@ static VALUE grpc_rb_server_start(VALUE self) {
...
@@ -256,7 +269,7 @@ static VALUE grpc_rb_server_start(VALUE self) {
static
VALUE
grpc_rb_server_destroy
(
VALUE
self
)
{
static
VALUE
grpc_rb_server_destroy
(
VALUE
self
)
{
grpc_rb_server
*
s
=
NULL
;
grpc_rb_server
*
s
=
NULL
;
Data_Get_Struct
(
self
,
grpc_rb_server
,
s
);
Typed
Data_Get_Struct
(
self
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
s
);
if
(
s
->
wrapped
!=
NULL
)
{
if
(
s
->
wrapped
!=
NULL
)
{
grpc_server_shutdown
(
s
->
wrapped
);
grpc_server_shutdown
(
s
->
wrapped
);
grpc_server_destroy
(
s
->
wrapped
);
grpc_server_destroy
(
s
->
wrapped
);
...
@@ -288,7 +301,7 @@ static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) {
...
@@ -288,7 +301,7 @@ static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) {
/* "11" == 1 mandatory args, 1 (rb_creds) is optional */
/* "11" == 1 mandatory args, 1 (rb_creds) is optional */
rb_scan_args
(
argc
,
argv
,
"11"
,
&
port
,
&
rb_creds
);
rb_scan_args
(
argc
,
argv
,
"11"
,
&
port
,
&
rb_creds
);
Data_Get_Struct
(
self
,
grpc_rb_server
,
s
);
Typed
Data_Get_Struct
(
self
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
s
);
if
(
s
->
wrapped
==
NULL
)
{
if
(
s
->
wrapped
==
NULL
)
{
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
rb_raise
(
rb_eRuntimeError
,
"closed!"
);
return
Qnil
;
return
Qnil
;
...
@@ -340,6 +353,6 @@ void Init_grpc_server() {
...
@@ -340,6 +353,6 @@ void Init_grpc_server() {
/* Gets the wrapped server from the ruby wrapper */
/* Gets the wrapped server from the ruby wrapper */
grpc_server
*
grpc_rb_get_wrapped_server
(
VALUE
v
)
{
grpc_server
*
grpc_rb_get_wrapped_server
(
VALUE
v
)
{
grpc_rb_server
*
wrapper
=
NULL
;
grpc_rb_server
*
wrapper
=
NULL
;
Data_Get_Struct
(
v
,
grpc_rb_server
,
wrapper
);
Typed
Data_Get_Struct
(
v
,
grpc_rb_server
,
&
grpc_rb_server_data_type
,
wrapper
);
return
wrapper
->
wrapped
;
return
wrapper
->
wrapped
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment