grpc 1.30.2-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/etc/roots.pem +4644 -0
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +34 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +107 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +64 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1050 -0
- data/src/ruby/ext/grpc/rb_call.h +53 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +297 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +835 -0
- data/src/ruby/ext/grpc/rb_channel.h +34 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +267 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +100 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +143 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
- data/src/ruby/ext/grpc/rb_grpc.c +328 -0
- data/src/ruby/ext/grpc/rb_grpc.h +76 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +573 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +865 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +372 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +243 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +32 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +501 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +105 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +118 -0
- data/src/ruby/pb/test/client.rb +769 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +213 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +82 -0
- data/src/ruby/spec/channel_spec.rb +234 -0
- data/src/ruby/spec/client_auth_spec.rb +126 -0
- data/src/ruby/spec/client_server_spec.rb +664 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +672 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +82 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +79 -0
- data/src/ruby/spec/server_spec.rb +209 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- metadata +394 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rb_grpc_imports.generated.h"
|
20
|
+
|
21
|
+
#if GPR_WINDOWS
|
22
|
+
#include <tchar.h>
|
23
|
+
|
24
|
+
int grpc_rb_load_core() {
|
25
|
+
#if GPR_ARCH_64
|
26
|
+
TCHAR fname[] = _T("grpc_c.64.ruby");
|
27
|
+
#else
|
28
|
+
TCHAR fname[] = _T("grpc_c.32.ruby");
|
29
|
+
#endif
|
30
|
+
HMODULE module = GetModuleHandle(_T("grpc_c.so"));
|
31
|
+
TCHAR path[2048 + 32] = _T("");
|
32
|
+
LPTSTR seek_back = NULL;
|
33
|
+
GetModuleFileName(module, path, 2048);
|
34
|
+
|
35
|
+
seek_back = _tcsrchr(path, _T('\\'));
|
36
|
+
|
37
|
+
while (seek_back) {
|
38
|
+
HMODULE grpc_c;
|
39
|
+
_tcscpy(seek_back + 1, fname);
|
40
|
+
grpc_c = LoadLibrary(path);
|
41
|
+
if (grpc_c) {
|
42
|
+
grpc_rb_load_imports(grpc_c);
|
43
|
+
return 1;
|
44
|
+
} else {
|
45
|
+
*seek_back = _T('\0');
|
46
|
+
seek_back = _tcsrchr(path, _T('\\'));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
return 0;
|
51
|
+
}
|
52
|
+
|
53
|
+
#else
|
54
|
+
|
55
|
+
int grpc_rb_load_core() { return 1; }
|
56
|
+
|
57
|
+
#endif
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_LOADER_H_
|
20
|
+
#define GRPC_RB_LOADER_H_
|
21
|
+
|
22
|
+
/* Attempts to load the core if necessary, and return non-zero upon succes. */
|
23
|
+
int grpc_rb_load_core();
|
24
|
+
|
25
|
+
#endif /* GRPC_RB_BYTE_BUFFER_H_ */
|
@@ -0,0 +1,372 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_grpc_imports.generated.h"
|
22
|
+
#include "rb_server.h"
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
#include <grpc/grpc_security.h>
|
26
|
+
#include <grpc/support/atm.h>
|
27
|
+
#include <grpc/support/log.h>
|
28
|
+
#include "rb_byte_buffer.h"
|
29
|
+
#include "rb_call.h"
|
30
|
+
#include "rb_channel_args.h"
|
31
|
+
#include "rb_completion_queue.h"
|
32
|
+
#include "rb_grpc.h"
|
33
|
+
#include "rb_server_credentials.h"
|
34
|
+
|
35
|
+
/* grpc_rb_cServer is the ruby class that proxies grpc_server. */
|
36
|
+
static VALUE grpc_rb_cServer = Qnil;
|
37
|
+
|
38
|
+
/* id_at is the constructor method of the ruby standard Time class. */
|
39
|
+
static ID id_at;
|
40
|
+
|
41
|
+
/* id_insecure_server is used to indicate that a server is insecure */
|
42
|
+
static VALUE id_insecure_server;
|
43
|
+
|
44
|
+
/* grpc_rb_server wraps a grpc_server. */
|
45
|
+
typedef struct grpc_rb_server {
|
46
|
+
/* The actual server */
|
47
|
+
grpc_server* wrapped;
|
48
|
+
grpc_completion_queue* queue;
|
49
|
+
int shutdown_and_notify_done;
|
50
|
+
int destroy_done;
|
51
|
+
} grpc_rb_server;
|
52
|
+
|
53
|
+
static void grpc_rb_server_maybe_shutdown_and_notify(grpc_rb_server* server,
|
54
|
+
gpr_timespec deadline) {
|
55
|
+
grpc_event ev;
|
56
|
+
void* tag = &ev;
|
57
|
+
if (!server->shutdown_and_notify_done) {
|
58
|
+
server->shutdown_and_notify_done = 1;
|
59
|
+
if (server->wrapped != NULL) {
|
60
|
+
grpc_server_shutdown_and_notify(server->wrapped, server->queue, tag);
|
61
|
+
ev = rb_completion_queue_pluck(server->queue, tag, deadline, NULL);
|
62
|
+
if (ev.type == GRPC_QUEUE_TIMEOUT) {
|
63
|
+
grpc_server_cancel_all_calls(server->wrapped);
|
64
|
+
ev = rb_completion_queue_pluck(
|
65
|
+
server->queue, tag, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
|
66
|
+
}
|
67
|
+
if (ev.type != GRPC_OP_COMPLETE) {
|
68
|
+
gpr_log(GPR_INFO,
|
69
|
+
"GRPC_RUBY: bad grpc_server_shutdown_and_notify result:%d",
|
70
|
+
ev.type);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
static void grpc_rb_server_maybe_destroy(grpc_rb_server* server) {
|
77
|
+
// This can be started by app or implicitly by GC. Avoid a race between these.
|
78
|
+
if (!server->destroy_done) {
|
79
|
+
server->destroy_done = 1;
|
80
|
+
if (server->wrapped != NULL) {
|
81
|
+
grpc_server_destroy(server->wrapped);
|
82
|
+
grpc_rb_completion_queue_destroy(server->queue);
|
83
|
+
server->wrapped = NULL;
|
84
|
+
server->queue = NULL;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
static void grpc_rb_server_free_internal(void* p) {
|
90
|
+
grpc_rb_server* svr = NULL;
|
91
|
+
gpr_timespec deadline;
|
92
|
+
if (p == NULL) {
|
93
|
+
return;
|
94
|
+
};
|
95
|
+
svr = (grpc_rb_server*)p;
|
96
|
+
|
97
|
+
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
|
98
|
+
gpr_time_from_seconds(2, GPR_TIMESPAN));
|
99
|
+
|
100
|
+
grpc_rb_server_maybe_shutdown_and_notify(svr, deadline);
|
101
|
+
grpc_rb_server_maybe_destroy(svr);
|
102
|
+
|
103
|
+
xfree(p);
|
104
|
+
}
|
105
|
+
|
106
|
+
/* Destroys server instances. */
|
107
|
+
static void grpc_rb_server_free(void* p) {
|
108
|
+
grpc_rb_server_free_internal(p);
|
109
|
+
grpc_ruby_shutdown();
|
110
|
+
}
|
111
|
+
|
112
|
+
static const rb_data_type_t grpc_rb_server_data_type = {
|
113
|
+
"grpc_server",
|
114
|
+
{GRPC_RB_GC_NOT_MARKED,
|
115
|
+
grpc_rb_server_free,
|
116
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
117
|
+
{NULL, NULL}},
|
118
|
+
NULL,
|
119
|
+
NULL,
|
120
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
121
|
+
/* It is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because the free
|
122
|
+
* function would block and we might want to unlock GVL
|
123
|
+
* TODO(yugui) Unlock GVL?
|
124
|
+
*/
|
125
|
+
0,
|
126
|
+
#endif
|
127
|
+
};
|
128
|
+
|
129
|
+
/* Allocates grpc_rb_server instances. */
|
130
|
+
static VALUE grpc_rb_server_alloc(VALUE cls) {
|
131
|
+
grpc_ruby_init();
|
132
|
+
grpc_rb_server* wrapper = ALLOC(grpc_rb_server);
|
133
|
+
wrapper->wrapped = NULL;
|
134
|
+
wrapper->destroy_done = 0;
|
135
|
+
wrapper->shutdown_and_notify_done = 0;
|
136
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_server_data_type, wrapper);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
call-seq:
|
141
|
+
server = Server.new({'arg1': 'value1'})
|
142
|
+
|
143
|
+
Initializes server instances. */
|
144
|
+
static VALUE grpc_rb_server_init(VALUE self, VALUE channel_args) {
|
145
|
+
grpc_completion_queue* cq = NULL;
|
146
|
+
grpc_rb_server* wrapper = NULL;
|
147
|
+
grpc_server* srv = NULL;
|
148
|
+
grpc_channel_args args;
|
149
|
+
MEMZERO(&args, grpc_channel_args, 1);
|
150
|
+
|
151
|
+
cq = grpc_completion_queue_create_for_pluck(NULL);
|
152
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type,
|
153
|
+
wrapper);
|
154
|
+
grpc_rb_hash_convert_to_channel_args(channel_args, &args);
|
155
|
+
srv = grpc_server_create(&args, NULL);
|
156
|
+
|
157
|
+
if (args.args != NULL) {
|
158
|
+
xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
|
159
|
+
}
|
160
|
+
if (srv == NULL) {
|
161
|
+
rb_raise(rb_eRuntimeError, "could not create a gRPC server, not sure why");
|
162
|
+
}
|
163
|
+
grpc_server_register_completion_queue(srv, cq, NULL);
|
164
|
+
wrapper->wrapped = srv;
|
165
|
+
wrapper->queue = cq;
|
166
|
+
|
167
|
+
return self;
|
168
|
+
}
|
169
|
+
|
170
|
+
/* request_call_stack holds various values used by the
|
171
|
+
* grpc_rb_server_request_call function */
|
172
|
+
typedef struct request_call_stack {
|
173
|
+
grpc_call_details details;
|
174
|
+
grpc_metadata_array md_ary;
|
175
|
+
} request_call_stack;
|
176
|
+
|
177
|
+
/* grpc_request_call_stack_init ensures the request_call_stack is properly
|
178
|
+
* initialized */
|
179
|
+
static void grpc_request_call_stack_init(request_call_stack* st) {
|
180
|
+
MEMZERO(st, request_call_stack, 1);
|
181
|
+
grpc_metadata_array_init(&st->md_ary);
|
182
|
+
grpc_call_details_init(&st->details);
|
183
|
+
}
|
184
|
+
|
185
|
+
/* grpc_request_call_stack_cleanup ensures the request_call_stack is properly
|
186
|
+
* cleaned up */
|
187
|
+
static void grpc_request_call_stack_cleanup(request_call_stack* st) {
|
188
|
+
grpc_metadata_array_destroy(&st->md_ary);
|
189
|
+
grpc_call_details_destroy(&st->details);
|
190
|
+
}
|
191
|
+
|
192
|
+
/* call-seq:
|
193
|
+
server.request_call
|
194
|
+
|
195
|
+
Requests notification of a new call on a server. */
|
196
|
+
static VALUE grpc_rb_server_request_call(VALUE self) {
|
197
|
+
grpc_rb_server* s = NULL;
|
198
|
+
grpc_call* call = NULL;
|
199
|
+
grpc_event ev;
|
200
|
+
grpc_call_error err;
|
201
|
+
request_call_stack st;
|
202
|
+
VALUE result;
|
203
|
+
void* tag = (void*)&st;
|
204
|
+
grpc_completion_queue* call_queue =
|
205
|
+
grpc_completion_queue_create_for_pluck(NULL);
|
206
|
+
gpr_timespec deadline;
|
207
|
+
|
208
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
|
209
|
+
if (s->wrapped == NULL) {
|
210
|
+
rb_raise(rb_eRuntimeError, "destroyed!");
|
211
|
+
return Qnil;
|
212
|
+
}
|
213
|
+
grpc_request_call_stack_init(&st);
|
214
|
+
/* call grpc_server_request_call, then wait for it to complete using
|
215
|
+
* pluck_event */
|
216
|
+
err = grpc_server_request_call(s->wrapped, &call, &st.details, &st.md_ary,
|
217
|
+
call_queue, s->queue, tag);
|
218
|
+
if (err != GRPC_CALL_OK) {
|
219
|
+
grpc_request_call_stack_cleanup(&st);
|
220
|
+
rb_raise(grpc_rb_eCallError,
|
221
|
+
"grpc_server_request_call failed: %s (code=%d)",
|
222
|
+
grpc_call_error_detail_of(err), err);
|
223
|
+
return Qnil;
|
224
|
+
}
|
225
|
+
|
226
|
+
ev = rb_completion_queue_pluck(s->queue, tag,
|
227
|
+
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
|
228
|
+
if (!ev.success) {
|
229
|
+
grpc_request_call_stack_cleanup(&st);
|
230
|
+
rb_raise(grpc_rb_eCallError, "request_call completion failed");
|
231
|
+
return Qnil;
|
232
|
+
}
|
233
|
+
|
234
|
+
/* build the NewServerRpc struct result */
|
235
|
+
deadline = gpr_convert_clock_type(st.details.deadline, GPR_CLOCK_REALTIME);
|
236
|
+
result = rb_struct_new(
|
237
|
+
grpc_rb_sNewServerRpc, grpc_rb_slice_to_ruby_string(st.details.method),
|
238
|
+
grpc_rb_slice_to_ruby_string(st.details.host),
|
239
|
+
rb_funcall(rb_cTime, id_at, 2, INT2NUM(deadline.tv_sec),
|
240
|
+
INT2NUM(deadline.tv_nsec / 1000)),
|
241
|
+
grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call, call_queue),
|
242
|
+
NULL);
|
243
|
+
grpc_request_call_stack_cleanup(&st);
|
244
|
+
return result;
|
245
|
+
}
|
246
|
+
|
247
|
+
static VALUE grpc_rb_server_start(VALUE self) {
|
248
|
+
grpc_rb_server* s = NULL;
|
249
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
|
250
|
+
|
251
|
+
grpc_ruby_fork_guard();
|
252
|
+
if (s->wrapped == NULL) {
|
253
|
+
rb_raise(rb_eRuntimeError, "destroyed!");
|
254
|
+
} else {
|
255
|
+
grpc_server_start(s->wrapped);
|
256
|
+
}
|
257
|
+
return Qnil;
|
258
|
+
}
|
259
|
+
|
260
|
+
static VALUE grpc_rb_server_shutdown_and_notify(VALUE self, VALUE timeout) {
|
261
|
+
gpr_timespec deadline;
|
262
|
+
grpc_rb_server* s = NULL;
|
263
|
+
|
264
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
|
265
|
+
if (TYPE(timeout) == T_NIL) {
|
266
|
+
deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
|
267
|
+
} else {
|
268
|
+
deadline = grpc_rb_time_timeval(timeout, /* absolute time*/ 0);
|
269
|
+
}
|
270
|
+
|
271
|
+
grpc_rb_server_maybe_shutdown_and_notify(s, deadline);
|
272
|
+
|
273
|
+
return Qnil;
|
274
|
+
}
|
275
|
+
|
276
|
+
/*
|
277
|
+
call-seq:
|
278
|
+
server = Server.new({'arg1': 'value1'})
|
279
|
+
... // do stuff with server
|
280
|
+
...
|
281
|
+
... // initiate server shutdown
|
282
|
+
server.shutdown_and_notify(timeout)
|
283
|
+
... // to shutdown the server
|
284
|
+
server.destroy()
|
285
|
+
|
286
|
+
Destroys server instances. */
|
287
|
+
static VALUE grpc_rb_server_destroy(VALUE self) {
|
288
|
+
grpc_rb_server* s = NULL;
|
289
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
|
290
|
+
grpc_rb_server_maybe_destroy(s);
|
291
|
+
return Qnil;
|
292
|
+
}
|
293
|
+
|
294
|
+
/*
|
295
|
+
call-seq:
|
296
|
+
// insecure port
|
297
|
+
insecure_server = Server.new(cq, {'arg1': 'value1'})
|
298
|
+
insecure_server.add_http2_port('mydomain:50051', :this_port_is_insecure)
|
299
|
+
|
300
|
+
// secure port
|
301
|
+
server_creds = ...
|
302
|
+
secure_server = Server.new(cq, {'arg1': 'value1'})
|
303
|
+
secure_server.add_http_port('mydomain:50051', server_creds)
|
304
|
+
|
305
|
+
Adds a http2 port to server */
|
306
|
+
static VALUE grpc_rb_server_add_http2_port(VALUE self, VALUE port,
|
307
|
+
VALUE rb_creds) {
|
308
|
+
grpc_rb_server* s = NULL;
|
309
|
+
grpc_server_credentials* creds = NULL;
|
310
|
+
int recvd_port = 0;
|
311
|
+
|
312
|
+
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
|
313
|
+
if (s->wrapped == NULL) {
|
314
|
+
rb_raise(rb_eRuntimeError, "destroyed!");
|
315
|
+
return Qnil;
|
316
|
+
} else if (TYPE(rb_creds) == T_SYMBOL) {
|
317
|
+
if (id_insecure_server != SYM2ID(rb_creds)) {
|
318
|
+
rb_raise(rb_eTypeError, "bad creds symbol, want :this_port_is_insecure");
|
319
|
+
return Qnil;
|
320
|
+
}
|
321
|
+
recvd_port =
|
322
|
+
grpc_server_add_insecure_http2_port(s->wrapped, StringValueCStr(port));
|
323
|
+
if (recvd_port == 0) {
|
324
|
+
rb_raise(rb_eRuntimeError,
|
325
|
+
"could not add port %s to server, not sure why",
|
326
|
+
StringValueCStr(port));
|
327
|
+
}
|
328
|
+
} else {
|
329
|
+
creds = grpc_rb_get_wrapped_server_credentials(rb_creds);
|
330
|
+
recvd_port = grpc_server_add_secure_http2_port(
|
331
|
+
s->wrapped, StringValueCStr(port), creds);
|
332
|
+
if (recvd_port == 0) {
|
333
|
+
rb_raise(rb_eRuntimeError,
|
334
|
+
"could not add secure port %s to server, not sure why",
|
335
|
+
StringValueCStr(port));
|
336
|
+
}
|
337
|
+
}
|
338
|
+
return INT2NUM(recvd_port);
|
339
|
+
}
|
340
|
+
|
341
|
+
void Init_grpc_server() {
|
342
|
+
grpc_rb_cServer =
|
343
|
+
rb_define_class_under(grpc_rb_mGrpcCore, "Server", rb_cObject);
|
344
|
+
|
345
|
+
/* Allocates an object managed by the ruby runtime */
|
346
|
+
rb_define_alloc_func(grpc_rb_cServer, grpc_rb_server_alloc);
|
347
|
+
|
348
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
349
|
+
rb_define_method(grpc_rb_cServer, "initialize", grpc_rb_server_init, 1);
|
350
|
+
rb_define_method(grpc_rb_cServer, "initialize_copy", grpc_rb_cannot_init_copy,
|
351
|
+
1);
|
352
|
+
|
353
|
+
/* Add the server methods. */
|
354
|
+
rb_define_method(grpc_rb_cServer, "request_call", grpc_rb_server_request_call,
|
355
|
+
0);
|
356
|
+
rb_define_method(grpc_rb_cServer, "start", grpc_rb_server_start, 0);
|
357
|
+
rb_define_method(grpc_rb_cServer, "shutdown_and_notify",
|
358
|
+
grpc_rb_server_shutdown_and_notify, 1);
|
359
|
+
rb_define_method(grpc_rb_cServer, "destroy", grpc_rb_server_destroy, 0);
|
360
|
+
rb_define_alias(grpc_rb_cServer, "close", "destroy");
|
361
|
+
rb_define_method(grpc_rb_cServer, "add_http2_port",
|
362
|
+
grpc_rb_server_add_http2_port, 2);
|
363
|
+
id_at = rb_intern("at");
|
364
|
+
id_insecure_server = rb_intern("this_port_is_insecure");
|
365
|
+
}
|
366
|
+
|
367
|
+
/* Gets the wrapped server from the ruby wrapper */
|
368
|
+
grpc_server* grpc_rb_get_wrapped_server(VALUE v) {
|
369
|
+
grpc_rb_server* wrapper = NULL;
|
370
|
+
TypedData_Get_Struct(v, grpc_rb_server, &grpc_rb_server_data_type, wrapper);
|
371
|
+
return wrapper->wrapped;
|
372
|
+
}
|