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
acc6cf28
Commit
acc6cf28
authored
9 years ago
by
Stanley Cheung
Browse files
Options
Downloads
Plain Diff
Merge pull request #2885 from tbetbetbe/grpc-rb-expose-call-peer
Exposes call#peer, channel#target
parents
9a2a3aec
623a74d0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ruby/ext/grpc/rb_call.c
+14
-0
14 additions, 0 deletions
src/ruby/ext/grpc/rb_call.c
src/ruby/ext/grpc/rb_channel.c
+17
-0
17 additions, 0 deletions
src/ruby/ext/grpc/rb_channel.c
src/ruby/spec/client_server_spec.rb
+17
-0
17 additions, 0 deletions
src/ruby/spec/client_server_spec.rb
with
48 additions
and
0 deletions
src/ruby/ext/grpc/rb_call.c
+
14
−
0
View file @
acc6cf28
...
@@ -179,6 +179,19 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
...
@@ -179,6 +179,19 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
return
Qnil
;
return
Qnil
;
}
}
/* Called to obtain the peer that this call is connected to. */
static
VALUE
grpc_rb_call_get_peer
(
VALUE
self
)
{
VALUE
res
=
Qnil
;
grpc_call
*
call
=
NULL
;
char
*
peer
=
NULL
;
TypedData_Get_Struct
(
self
,
grpc_call
,
&
grpc_call_data_type
,
call
);
peer
=
grpc_call_get_peer
(
call
);
res
=
rb_str_new2
(
peer
);
gpr_free
(
peer
);
return
res
;
}
/*
/*
call-seq:
call-seq:
status = call.status
status = call.status
...
@@ -720,6 +733,7 @@ void Init_grpc_call() {
...
@@ -720,6 +733,7 @@ void Init_grpc_call() {
/* Add ruby analogues of the Call methods. */
/* Add ruby analogues of the Call methods. */
rb_define_method
(
grpc_rb_cCall
,
"run_batch"
,
grpc_rb_call_run_batch
,
4
);
rb_define_method
(
grpc_rb_cCall
,
"run_batch"
,
grpc_rb_call_run_batch
,
4
);
rb_define_method
(
grpc_rb_cCall
,
"cancel"
,
grpc_rb_call_cancel
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"cancel"
,
grpc_rb_call_cancel
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"peer"
,
grpc_rb_call_get_peer
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"status"
,
grpc_rb_call_get_status
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"status"
,
grpc_rb_call_get_status
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"status="
,
grpc_rb_call_set_status
,
1
);
rb_define_method
(
grpc_rb_cCall
,
"status="
,
grpc_rb_call_set_status
,
1
);
rb_define_method
(
grpc_rb_cCall
,
"metadata"
,
grpc_rb_call_get_metadata
,
0
);
rb_define_method
(
grpc_rb_cCall
,
"metadata"
,
grpc_rb_call_get_metadata
,
0
);
...
...
This diff is collapsed.
Click to expand it.
src/ruby/ext/grpc/rb_channel.c
+
17
−
0
View file @
acc6cf28
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
#include
<grpc/grpc.h>
#include
<grpc/grpc.h>
#include
<grpc/grpc_security.h>
#include
<grpc/grpc_security.h>
#include
<grpc/support/alloc.h>
#include
"rb_grpc.h"
#include
"rb_grpc.h"
#include
"rb_call.h"
#include
"rb_call.h"
#include
"rb_channel_args.h"
#include
"rb_channel_args.h"
...
@@ -249,6 +250,21 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
...
@@ -249,6 +250,21 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
return
Qnil
;
return
Qnil
;
}
}
/* Called to obtain the target that this channel accesses. */
static
VALUE
grpc_rb_channel_get_target
(
VALUE
self
)
{
grpc_rb_channel
*
wrapper
=
NULL
;
VALUE
res
=
Qnil
;
char
*
target
=
NULL
;
TypedData_Get_Struct
(
self
,
grpc_rb_channel
,
&
grpc_channel_data_type
,
wrapper
);
target
=
grpc_channel_get_target
(
wrapper
->
wrapped
);
res
=
rb_str_new2
(
target
);
gpr_free
(
target
);
return
res
;
}
void
Init_grpc_channel
()
{
void
Init_grpc_channel
()
{
grpc_rb_cChannelArgs
=
rb_define_class
(
"TmpChannelArgs"
,
rb_cObject
);
grpc_rb_cChannelArgs
=
rb_define_class
(
"TmpChannelArgs"
,
rb_cObject
);
grpc_rb_cChannel
=
grpc_rb_cChannel
=
...
@@ -265,6 +281,7 @@ void Init_grpc_channel() {
...
@@ -265,6 +281,7 @@ void Init_grpc_channel() {
/* Add ruby analogues of the Channel methods. */
/* Add ruby analogues of the Channel methods. */
rb_define_method
(
grpc_rb_cChannel
,
"create_call"
,
rb_define_method
(
grpc_rb_cChannel
,
"create_call"
,
grpc_rb_channel_create_call
,
4
);
grpc_rb_channel_create_call
,
4
);
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"
);
...
...
This diff is collapsed.
Click to expand it.
src/ruby/spec/client_server_spec.rb
+
17
−
0
View file @
acc6cf28
...
@@ -69,6 +69,23 @@ shared_examples 'basic GRPC message delivery is OK' do
...
@@ -69,6 +69,23 @@ shared_examples 'basic GRPC message delivery is OK' do
include
GRPC
::
Core
include
GRPC
::
Core
include_context
'setup: tags'
include_context
'setup: tags'
context
'the test channel'
do
it
'should have a target'
do
expect
(
@ch
.
target
).
to
be_a
(
String
)
end
end
context
'a client call'
do
it
'should have a peer'
do
expect
(
new_client_call
.
peer
).
to
be_a
(
String
)
end
end
it
'calls have peer info'
do
call
=
new_client_call
expect
(
call
.
peer
).
to
be_a
(
String
)
end
it
'servers receive requests from clients and can respond'
do
it
'servers receive requests from clients and can respond'
do
call
=
new_client_call
call
=
new_client_call
server_call
=
nil
server_call
=
nil
...
...
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