grpc 1.49.0.pre1-x64-mingw-ucrt
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 +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.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-truffleruby.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +2 -0
- data/src/ruby/ext/grpc/ext-export.gcc +7 -0
- data/src/ruby/ext/grpc/extconf.rb +163 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1051 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +849 -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 +286 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +471 -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 +145 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
- data/src/ruby/ext/grpc/rb_grpc.c +333 -0
- data/src/ruby/ext/grpc/rb_grpc.h +77 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +901 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +388 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/3.1/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 +675 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -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/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +52 -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 +149 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -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 +415 -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 +124 -0
- data/src/ruby/spec/channel_spec.rb +245 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -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 +683 -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/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -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 +104 -0
- data/src/ruby/spec/server_spec.rb +231 -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
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +406 -0
@@ -0,0 +1,471 @@
|
|
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_compression_options.h"
|
22
|
+
|
23
|
+
#include <string.h>
|
24
|
+
|
25
|
+
#include "rb_byte_buffer.h"
|
26
|
+
#include "rb_grpc.h"
|
27
|
+
#include "rb_grpc_imports.generated.h"
|
28
|
+
|
29
|
+
#include <grpc/compression.h>
|
30
|
+
#include <grpc/grpc.h>
|
31
|
+
#include <grpc/impl/codegen/compression_types.h>
|
32
|
+
#include <grpc/impl/codegen/grpc_types.h>
|
33
|
+
#include <grpc/support/alloc.h>
|
34
|
+
#include <grpc/support/log.h>
|
35
|
+
#include <grpc/support/string_util.h>
|
36
|
+
|
37
|
+
static VALUE grpc_rb_cCompressionOptions = Qnil;
|
38
|
+
|
39
|
+
/* Ruby Ids for the names of valid compression levels. */
|
40
|
+
static VALUE id_compress_level_none = Qnil;
|
41
|
+
static VALUE id_compress_level_low = Qnil;
|
42
|
+
static VALUE id_compress_level_medium = Qnil;
|
43
|
+
static VALUE id_compress_level_high = Qnil;
|
44
|
+
|
45
|
+
/* grpc_rb_compression_options wraps a grpc_compression_options.
|
46
|
+
* It can be used to get the channel argument key-values for specific
|
47
|
+
* compression settings. */
|
48
|
+
|
49
|
+
/* Note that ruby objects of this type don't carry any state in other
|
50
|
+
* Ruby objects and don't have a mark for GC. */
|
51
|
+
typedef struct grpc_rb_compression_options {
|
52
|
+
/* The actual compression options that's being wrapped */
|
53
|
+
grpc_compression_options* wrapped;
|
54
|
+
} grpc_rb_compression_options;
|
55
|
+
|
56
|
+
static void grpc_rb_compression_options_free_internal(void* p) {
|
57
|
+
grpc_rb_compression_options* wrapper = NULL;
|
58
|
+
if (p == NULL) {
|
59
|
+
return;
|
60
|
+
};
|
61
|
+
wrapper = (grpc_rb_compression_options*)p;
|
62
|
+
if (wrapper->wrapped != NULL) {
|
63
|
+
gpr_free(wrapper->wrapped);
|
64
|
+
wrapper->wrapped = NULL;
|
65
|
+
}
|
66
|
+
xfree(p);
|
67
|
+
}
|
68
|
+
|
69
|
+
/* Destroys the compression options instances and free the
|
70
|
+
* wrapped grpc compression options. */
|
71
|
+
static void grpc_rb_compression_options_free(void* p) {
|
72
|
+
grpc_rb_compression_options_free_internal(p);
|
73
|
+
grpc_ruby_shutdown();
|
74
|
+
}
|
75
|
+
|
76
|
+
/* Ruby recognized data type for the CompressionOptions class. */
|
77
|
+
static rb_data_type_t grpc_rb_compression_options_data_type = {
|
78
|
+
"grpc_compression_options",
|
79
|
+
{NULL,
|
80
|
+
grpc_rb_compression_options_free,
|
81
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
82
|
+
{NULL, NULL}},
|
83
|
+
NULL,
|
84
|
+
NULL,
|
85
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
86
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
87
|
+
#endif
|
88
|
+
};
|
89
|
+
|
90
|
+
/* Allocates CompressionOptions instances.
|
91
|
+
Allocate the wrapped grpc compression options and
|
92
|
+
initialize it here too. */
|
93
|
+
static VALUE grpc_rb_compression_options_alloc(VALUE cls) {
|
94
|
+
grpc_ruby_init();
|
95
|
+
grpc_rb_compression_options* wrapper = NULL;
|
96
|
+
|
97
|
+
wrapper = gpr_malloc(sizeof(grpc_rb_compression_options));
|
98
|
+
wrapper->wrapped = NULL;
|
99
|
+
wrapper->wrapped = gpr_malloc(sizeof(grpc_compression_options));
|
100
|
+
grpc_compression_options_init(wrapper->wrapped);
|
101
|
+
|
102
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_compression_options_data_type,
|
103
|
+
wrapper);
|
104
|
+
}
|
105
|
+
|
106
|
+
/* Disables a compression algorithm, given the GRPC core internal number of a
|
107
|
+
* compression algorithm. */
|
108
|
+
VALUE grpc_rb_compression_options_disable_compression_algorithm_internal(
|
109
|
+
VALUE self, VALUE algorithm_to_disable) {
|
110
|
+
grpc_compression_algorithm compression_algorithm = 0;
|
111
|
+
grpc_rb_compression_options* wrapper = NULL;
|
112
|
+
|
113
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
114
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
115
|
+
compression_algorithm =
|
116
|
+
(grpc_compression_algorithm)NUM2INT(algorithm_to_disable);
|
117
|
+
|
118
|
+
grpc_compression_options_disable_algorithm(wrapper->wrapped,
|
119
|
+
compression_algorithm);
|
120
|
+
|
121
|
+
return Qnil;
|
122
|
+
}
|
123
|
+
|
124
|
+
/* Gets the compression internal enum value of a compression level given its
|
125
|
+
* name. */
|
126
|
+
grpc_compression_level grpc_rb_compression_options_level_name_to_value_internal(
|
127
|
+
VALUE level_name) {
|
128
|
+
Check_Type(level_name, T_SYMBOL);
|
129
|
+
|
130
|
+
/* Check the compression level of the name passed in, and see which macro
|
131
|
+
* from the GRPC core header files match. */
|
132
|
+
if (id_compress_level_none == SYM2ID(level_name)) {
|
133
|
+
return GRPC_COMPRESS_LEVEL_NONE;
|
134
|
+
} else if (id_compress_level_low == SYM2ID(level_name)) {
|
135
|
+
return GRPC_COMPRESS_LEVEL_LOW;
|
136
|
+
} else if (id_compress_level_medium == SYM2ID(level_name)) {
|
137
|
+
return GRPC_COMPRESS_LEVEL_MED;
|
138
|
+
} else if (id_compress_level_high == SYM2ID(level_name)) {
|
139
|
+
return GRPC_COMPRESS_LEVEL_HIGH;
|
140
|
+
}
|
141
|
+
|
142
|
+
rb_raise(rb_eArgError,
|
143
|
+
"Unrecognized compression level name."
|
144
|
+
"Valid compression level names are none, low, medium, and high.");
|
145
|
+
|
146
|
+
/* Phony return statement. */
|
147
|
+
return GRPC_COMPRESS_LEVEL_NONE;
|
148
|
+
}
|
149
|
+
|
150
|
+
/* Sets the default compression level, given the name of a compression level.
|
151
|
+
* Throws an error if no algorithm matched. */
|
152
|
+
void grpc_rb_compression_options_set_default_level(
|
153
|
+
grpc_compression_options* options, VALUE new_level_name) {
|
154
|
+
options->default_level.level =
|
155
|
+
grpc_rb_compression_options_level_name_to_value_internal(new_level_name);
|
156
|
+
options->default_level.is_set = 1;
|
157
|
+
}
|
158
|
+
|
159
|
+
/* Gets the internal value of a compression algorithm suitable as the value
|
160
|
+
* in a GRPC core channel arguments hash.
|
161
|
+
* algorithm_value is an out parameter.
|
162
|
+
* Raises an error if the name of the algorithm passed in is invalid. */
|
163
|
+
void grpc_rb_compression_options_algorithm_name_to_value_internal(
|
164
|
+
grpc_compression_algorithm* algorithm_value, VALUE algorithm_name) {
|
165
|
+
grpc_slice name_slice;
|
166
|
+
VALUE algorithm_name_as_string = Qnil;
|
167
|
+
|
168
|
+
Check_Type(algorithm_name, T_SYMBOL);
|
169
|
+
|
170
|
+
/* Convert the algorithm symbol to a ruby string, so that we can get the
|
171
|
+
* correct C string out of it. */
|
172
|
+
algorithm_name_as_string = rb_funcall(algorithm_name, rb_intern("to_s"), 0);
|
173
|
+
|
174
|
+
name_slice =
|
175
|
+
grpc_slice_from_copied_buffer(RSTRING_PTR(algorithm_name_as_string),
|
176
|
+
RSTRING_LEN(algorithm_name_as_string));
|
177
|
+
|
178
|
+
/* Raise an error if the name isn't recognized as a compression algorithm by
|
179
|
+
* the algorithm parse function
|
180
|
+
* in GRPC core. */
|
181
|
+
if (!grpc_compression_algorithm_parse(name_slice, algorithm_value)) {
|
182
|
+
char* name_slice_str = grpc_slice_to_c_string(name_slice);
|
183
|
+
char* error_message_str = NULL;
|
184
|
+
VALUE error_message_ruby_str = Qnil;
|
185
|
+
GPR_ASSERT(gpr_asprintf(&error_message_str,
|
186
|
+
"Invalid compression algorithm name: %s",
|
187
|
+
name_slice_str) != -1);
|
188
|
+
gpr_free(name_slice_str);
|
189
|
+
error_message_ruby_str =
|
190
|
+
rb_str_new(error_message_str, strlen(error_message_str));
|
191
|
+
gpr_free(error_message_str);
|
192
|
+
rb_raise(rb_eNameError, "%s", StringValueCStr(error_message_ruby_str));
|
193
|
+
}
|
194
|
+
|
195
|
+
grpc_slice_unref(name_slice);
|
196
|
+
}
|
197
|
+
|
198
|
+
/* Indicates whether a given algorithm is enabled on this instance, given the
|
199
|
+
* readable algorithm name. */
|
200
|
+
VALUE grpc_rb_compression_options_is_algorithm_enabled(VALUE self,
|
201
|
+
VALUE algorithm_name) {
|
202
|
+
grpc_rb_compression_options* wrapper = NULL;
|
203
|
+
grpc_compression_algorithm internal_algorithm_value;
|
204
|
+
|
205
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
206
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
207
|
+
grpc_rb_compression_options_algorithm_name_to_value_internal(
|
208
|
+
&internal_algorithm_value, algorithm_name);
|
209
|
+
|
210
|
+
if (grpc_compression_options_is_algorithm_enabled(wrapper->wrapped,
|
211
|
+
internal_algorithm_value)) {
|
212
|
+
return Qtrue;
|
213
|
+
}
|
214
|
+
return Qfalse;
|
215
|
+
}
|
216
|
+
|
217
|
+
/* Sets the default algorithm to the name of the algorithm passed in.
|
218
|
+
* Raises an error if the name is not a valid compression algorithm name. */
|
219
|
+
void grpc_rb_compression_options_set_default_algorithm(
|
220
|
+
grpc_compression_options* options, VALUE algorithm_name) {
|
221
|
+
grpc_rb_compression_options_algorithm_name_to_value_internal(
|
222
|
+
&options->default_algorithm.algorithm, algorithm_name);
|
223
|
+
options->default_algorithm.is_set = 1;
|
224
|
+
}
|
225
|
+
|
226
|
+
/* Disables an algorithm on the current instance, given the name of an
|
227
|
+
* algorithm.
|
228
|
+
* Fails if the algorithm name is invalid. */
|
229
|
+
void grpc_rb_compression_options_disable_algorithm(
|
230
|
+
grpc_compression_options* compression_options, VALUE algorithm_name) {
|
231
|
+
grpc_compression_algorithm internal_algorithm_value;
|
232
|
+
|
233
|
+
grpc_rb_compression_options_algorithm_name_to_value_internal(
|
234
|
+
&internal_algorithm_value, algorithm_name);
|
235
|
+
grpc_compression_options_disable_algorithm(compression_options,
|
236
|
+
internal_algorithm_value);
|
237
|
+
}
|
238
|
+
|
239
|
+
/* Provides a ruby hash of GRPC core channel argument key-values that
|
240
|
+
* correspond to the compression settings on this instance. */
|
241
|
+
VALUE grpc_rb_compression_options_to_hash(VALUE self) {
|
242
|
+
grpc_rb_compression_options* wrapper = NULL;
|
243
|
+
grpc_compression_options* compression_options = NULL;
|
244
|
+
VALUE channel_arg_hash = rb_hash_new();
|
245
|
+
VALUE key = Qnil;
|
246
|
+
VALUE value = Qnil;
|
247
|
+
|
248
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
249
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
250
|
+
compression_options = wrapper->wrapped;
|
251
|
+
|
252
|
+
/* Add key-value pairs to the new Ruby hash. It can be used
|
253
|
+
* as GRPC core channel arguments. */
|
254
|
+
if (compression_options->default_level.is_set) {
|
255
|
+
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL);
|
256
|
+
value = INT2NUM((int)compression_options->default_level.level);
|
257
|
+
rb_hash_aset(channel_arg_hash, key, value);
|
258
|
+
}
|
259
|
+
|
260
|
+
if (compression_options->default_algorithm.is_set) {
|
261
|
+
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM);
|
262
|
+
value = INT2NUM((int)compression_options->default_algorithm.algorithm);
|
263
|
+
rb_hash_aset(channel_arg_hash, key, value);
|
264
|
+
}
|
265
|
+
|
266
|
+
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET);
|
267
|
+
value = INT2NUM((int)compression_options->enabled_algorithms_bitset);
|
268
|
+
rb_hash_aset(channel_arg_hash, key, value);
|
269
|
+
|
270
|
+
return channel_arg_hash;
|
271
|
+
}
|
272
|
+
|
273
|
+
/* Converts an internal enum level value to a readable level name.
|
274
|
+
* Fails if the level value is invalid. */
|
275
|
+
VALUE grpc_rb_compression_options_level_value_to_name_internal(
|
276
|
+
grpc_compression_level compression_value) {
|
277
|
+
switch (compression_value) {
|
278
|
+
case GRPC_COMPRESS_LEVEL_NONE:
|
279
|
+
return ID2SYM(id_compress_level_none);
|
280
|
+
case GRPC_COMPRESS_LEVEL_LOW:
|
281
|
+
return ID2SYM(id_compress_level_low);
|
282
|
+
case GRPC_COMPRESS_LEVEL_MED:
|
283
|
+
return ID2SYM(id_compress_level_medium);
|
284
|
+
case GRPC_COMPRESS_LEVEL_HIGH:
|
285
|
+
return ID2SYM(id_compress_level_high);
|
286
|
+
default:
|
287
|
+
rb_raise(
|
288
|
+
rb_eArgError,
|
289
|
+
"Failed to convert compression level value to name for value: %d",
|
290
|
+
(int)compression_value);
|
291
|
+
/* return something to avoid compiler error about no return */
|
292
|
+
return Qnil;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
/* Converts an algorithm internal enum value to a readable name.
|
297
|
+
* Fails if the enum value is invalid. */
|
298
|
+
VALUE grpc_rb_compression_options_algorithm_value_to_name_internal(
|
299
|
+
grpc_compression_algorithm internal_value) {
|
300
|
+
char* algorithm_name = NULL;
|
301
|
+
|
302
|
+
if (!grpc_compression_algorithm_name(internal_value, &algorithm_name)) {
|
303
|
+
rb_raise(rb_eArgError, "Failed to convert algorithm value to name");
|
304
|
+
}
|
305
|
+
|
306
|
+
return ID2SYM(rb_intern(algorithm_name));
|
307
|
+
}
|
308
|
+
|
309
|
+
/* Gets the readable name of the default algorithm if one has been set.
|
310
|
+
* Returns nil if no algorithm has been set. */
|
311
|
+
VALUE grpc_rb_compression_options_get_default_algorithm(VALUE self) {
|
312
|
+
grpc_compression_algorithm internal_value;
|
313
|
+
grpc_rb_compression_options* wrapper = NULL;
|
314
|
+
|
315
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
316
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
317
|
+
|
318
|
+
if (wrapper->wrapped->default_algorithm.is_set) {
|
319
|
+
internal_value = wrapper->wrapped->default_algorithm.algorithm;
|
320
|
+
return grpc_rb_compression_options_algorithm_value_to_name_internal(
|
321
|
+
internal_value);
|
322
|
+
}
|
323
|
+
|
324
|
+
return Qnil;
|
325
|
+
}
|
326
|
+
|
327
|
+
/* Gets the internal value of the default compression level that is to be passed
|
328
|
+
* to the GRPC core as a channel argument value.
|
329
|
+
* A nil return value means that it hasn't been set. */
|
330
|
+
VALUE grpc_rb_compression_options_get_default_level(VALUE self) {
|
331
|
+
grpc_compression_level internal_value;
|
332
|
+
grpc_rb_compression_options* wrapper = NULL;
|
333
|
+
|
334
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
335
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
336
|
+
|
337
|
+
if (wrapper->wrapped->default_level.is_set) {
|
338
|
+
internal_value = wrapper->wrapped->default_level.level;
|
339
|
+
return grpc_rb_compression_options_level_value_to_name_internal(
|
340
|
+
internal_value);
|
341
|
+
}
|
342
|
+
|
343
|
+
return Qnil;
|
344
|
+
}
|
345
|
+
|
346
|
+
/* Gets a list of the disabled algorithms as readable names.
|
347
|
+
* Returns an empty list if no algorithms have been disabled. */
|
348
|
+
VALUE grpc_rb_compression_options_get_disabled_algorithms(VALUE self) {
|
349
|
+
VALUE disabled_algorithms = rb_ary_new();
|
350
|
+
grpc_compression_algorithm internal_value;
|
351
|
+
grpc_rb_compression_options* wrapper = NULL;
|
352
|
+
|
353
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
354
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
355
|
+
|
356
|
+
for (internal_value = GRPC_COMPRESS_NONE;
|
357
|
+
internal_value < GRPC_COMPRESS_ALGORITHMS_COUNT; internal_value++) {
|
358
|
+
if (!grpc_compression_options_is_algorithm_enabled(wrapper->wrapped,
|
359
|
+
internal_value)) {
|
360
|
+
rb_ary_push(disabled_algorithms,
|
361
|
+
grpc_rb_compression_options_algorithm_value_to_name_internal(
|
362
|
+
internal_value));
|
363
|
+
}
|
364
|
+
}
|
365
|
+
return disabled_algorithms;
|
366
|
+
}
|
367
|
+
|
368
|
+
/* Initializes the compression options wrapper.
|
369
|
+
* Takes an optional hash parameter.
|
370
|
+
*
|
371
|
+
* Example call-seq:
|
372
|
+
* options = CompressionOptions.new(
|
373
|
+
* default_level: :none,
|
374
|
+
* disabled_algorithms: [:gzip]
|
375
|
+
* )
|
376
|
+
* channel_arg hash = Hash.new[...]
|
377
|
+
* channel_arg_hash_with_compression_options = channel_arg_hash.merge(options)
|
378
|
+
*/
|
379
|
+
VALUE grpc_rb_compression_options_init(int argc, VALUE* argv, VALUE self) {
|
380
|
+
grpc_rb_compression_options* wrapper = NULL;
|
381
|
+
VALUE default_algorithm = Qnil;
|
382
|
+
VALUE default_level = Qnil;
|
383
|
+
VALUE disabled_algorithms = Qnil;
|
384
|
+
VALUE algorithm_name = Qnil;
|
385
|
+
VALUE hash_arg = Qnil;
|
386
|
+
|
387
|
+
rb_scan_args(argc, argv, "01", &hash_arg);
|
388
|
+
|
389
|
+
/* Check if the hash parameter was passed, or if invalid arguments were
|
390
|
+
* passed. */
|
391
|
+
if (hash_arg == Qnil) {
|
392
|
+
return self;
|
393
|
+
} else if (TYPE(hash_arg) != T_HASH || argc > 1) {
|
394
|
+
rb_raise(rb_eArgError,
|
395
|
+
"Invalid arguments. Expecting optional hash parameter");
|
396
|
+
}
|
397
|
+
|
398
|
+
TypedData_Get_Struct(self, grpc_rb_compression_options,
|
399
|
+
&grpc_rb_compression_options_data_type, wrapper);
|
400
|
+
|
401
|
+
/* Set the default algorithm if one was chosen. */
|
402
|
+
default_algorithm =
|
403
|
+
rb_hash_aref(hash_arg, ID2SYM(rb_intern("default_algorithm")));
|
404
|
+
if (default_algorithm != Qnil) {
|
405
|
+
grpc_rb_compression_options_set_default_algorithm(wrapper->wrapped,
|
406
|
+
default_algorithm);
|
407
|
+
}
|
408
|
+
|
409
|
+
/* Set the default level if one was chosen. */
|
410
|
+
default_level = rb_hash_aref(hash_arg, ID2SYM(rb_intern("default_level")));
|
411
|
+
if (default_level != Qnil) {
|
412
|
+
grpc_rb_compression_options_set_default_level(wrapper->wrapped,
|
413
|
+
default_level);
|
414
|
+
}
|
415
|
+
|
416
|
+
/* Set the disabled algorithms if any were chosen. */
|
417
|
+
disabled_algorithms =
|
418
|
+
rb_hash_aref(hash_arg, ID2SYM(rb_intern("disabled_algorithms")));
|
419
|
+
if (disabled_algorithms != Qnil) {
|
420
|
+
Check_Type(disabled_algorithms, T_ARRAY);
|
421
|
+
|
422
|
+
for (int i = 0; i < RARRAY_LEN(disabled_algorithms); i++) {
|
423
|
+
algorithm_name = rb_ary_entry(disabled_algorithms, i);
|
424
|
+
grpc_rb_compression_options_disable_algorithm(wrapper->wrapped,
|
425
|
+
algorithm_name);
|
426
|
+
}
|
427
|
+
}
|
428
|
+
|
429
|
+
return self;
|
430
|
+
}
|
431
|
+
|
432
|
+
void Init_grpc_compression_options() {
|
433
|
+
grpc_rb_cCompressionOptions = rb_define_class_under(
|
434
|
+
grpc_rb_mGrpcCore, "CompressionOptions", rb_cObject);
|
435
|
+
|
436
|
+
/* Allocates an object managed by the ruby runtime. */
|
437
|
+
rb_define_alloc_func(grpc_rb_cCompressionOptions,
|
438
|
+
grpc_rb_compression_options_alloc);
|
439
|
+
|
440
|
+
/* Initializes the ruby wrapper. #new method takes an optional hash argument.
|
441
|
+
*/
|
442
|
+
rb_define_method(grpc_rb_cCompressionOptions, "initialize",
|
443
|
+
grpc_rb_compression_options_init, -1);
|
444
|
+
|
445
|
+
/* Methods for getting the default algorithm, default level, and disabled
|
446
|
+
* algorithms as readable names. */
|
447
|
+
rb_define_method(grpc_rb_cCompressionOptions, "default_algorithm",
|
448
|
+
grpc_rb_compression_options_get_default_algorithm, 0);
|
449
|
+
rb_define_method(grpc_rb_cCompressionOptions, "default_level",
|
450
|
+
grpc_rb_compression_options_get_default_level, 0);
|
451
|
+
rb_define_method(grpc_rb_cCompressionOptions, "disabled_algorithms",
|
452
|
+
grpc_rb_compression_options_get_disabled_algorithms, 0);
|
453
|
+
|
454
|
+
/* Determines whether or not an algorithm is enabled, given a readable
|
455
|
+
* algorithm name.*/
|
456
|
+
rb_define_method(grpc_rb_cCompressionOptions, "algorithm_enabled?",
|
457
|
+
grpc_rb_compression_options_is_algorithm_enabled, 1);
|
458
|
+
|
459
|
+
/* Provides a hash of the compression settings suitable
|
460
|
+
* for passing to server or channel args. */
|
461
|
+
rb_define_method(grpc_rb_cCompressionOptions, "to_hash",
|
462
|
+
grpc_rb_compression_options_to_hash, 0);
|
463
|
+
rb_define_alias(grpc_rb_cCompressionOptions, "to_channel_arg_hash",
|
464
|
+
"to_hash");
|
465
|
+
|
466
|
+
/* Ruby ids for the names of the different compression levels. */
|
467
|
+
id_compress_level_none = rb_intern("none");
|
468
|
+
id_compress_level_low = rb_intern("low");
|
469
|
+
id_compress_level_medium = rb_intern("medium");
|
470
|
+
id_compress_level_high = rb_intern("high");
|
471
|
+
}
|
@@ -0,0 +1,29 @@
|
|
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
|
+
#ifndef GRPC_RB_COMPRESSION_OPTIONS_H_
|
20
|
+
#define GRPC_RB_COMPRESSION_OPTIONS_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
/* Initializes the compression options ruby wrapper. */
|
27
|
+
void Init_grpc_compression_options();
|
28
|
+
|
29
|
+
#endif /* GRPC_RB_COMPRESSION_OPTIONS_H_ */
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2019 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
|
+
// This is a phony C++ source file to trigger ruby extension builder to
|
22
|
+
// pick C++ rather than C linker to link with c++ library properly.
|
@@ -0,0 +1,145 @@
|
|
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 <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_event_thread.h"
|
22
|
+
|
23
|
+
#include <ruby/thread.h>
|
24
|
+
#include <stdbool.h>
|
25
|
+
|
26
|
+
#include "rb_grpc.h"
|
27
|
+
#include "rb_grpc_imports.generated.h"
|
28
|
+
|
29
|
+
#include <grpc/support/alloc.h>
|
30
|
+
#include <grpc/support/log.h>
|
31
|
+
#include <grpc/support/sync.h>
|
32
|
+
#include <grpc/support/time.h>
|
33
|
+
|
34
|
+
typedef struct grpc_rb_event {
|
35
|
+
// callback will be called with argument while holding the GVL
|
36
|
+
void (*callback)(void*);
|
37
|
+
void* argument;
|
38
|
+
|
39
|
+
struct grpc_rb_event* next;
|
40
|
+
} grpc_rb_event;
|
41
|
+
|
42
|
+
typedef struct grpc_rb_event_queue {
|
43
|
+
grpc_rb_event* head;
|
44
|
+
grpc_rb_event* tail;
|
45
|
+
|
46
|
+
gpr_mu mu;
|
47
|
+
gpr_cv cv;
|
48
|
+
|
49
|
+
// Indicates that the thread should stop waiting
|
50
|
+
bool abort;
|
51
|
+
} grpc_rb_event_queue;
|
52
|
+
|
53
|
+
static grpc_rb_event_queue event_queue;
|
54
|
+
|
55
|
+
void grpc_rb_event_queue_enqueue(void (*callback)(void*), void* argument) {
|
56
|
+
grpc_rb_event* event = gpr_malloc(sizeof(grpc_rb_event));
|
57
|
+
event->callback = callback;
|
58
|
+
event->argument = argument;
|
59
|
+
event->next = NULL;
|
60
|
+
gpr_mu_lock(&event_queue.mu);
|
61
|
+
if (event_queue.tail == NULL) {
|
62
|
+
event_queue.head = event_queue.tail = event;
|
63
|
+
} else {
|
64
|
+
event_queue.tail->next = event;
|
65
|
+
event_queue.tail = event;
|
66
|
+
}
|
67
|
+
gpr_cv_signal(&event_queue.cv);
|
68
|
+
gpr_mu_unlock(&event_queue.mu);
|
69
|
+
}
|
70
|
+
|
71
|
+
static grpc_rb_event* grpc_rb_event_queue_dequeue() {
|
72
|
+
grpc_rb_event* event;
|
73
|
+
if (event_queue.head == NULL) {
|
74
|
+
event = NULL;
|
75
|
+
} else {
|
76
|
+
event = event_queue.head;
|
77
|
+
if (event_queue.head->next == NULL) {
|
78
|
+
event_queue.head = event_queue.tail = NULL;
|
79
|
+
} else {
|
80
|
+
event_queue.head = event_queue.head->next;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return event;
|
84
|
+
}
|
85
|
+
|
86
|
+
static void grpc_rb_event_queue_destroy() {
|
87
|
+
gpr_mu_destroy(&event_queue.mu);
|
88
|
+
gpr_cv_destroy(&event_queue.cv);
|
89
|
+
}
|
90
|
+
|
91
|
+
static void* grpc_rb_wait_for_event_no_gil(void* param) {
|
92
|
+
grpc_rb_event* event = NULL;
|
93
|
+
(void)param;
|
94
|
+
gpr_mu_lock(&event_queue.mu);
|
95
|
+
while (!event_queue.abort) {
|
96
|
+
if ((event = grpc_rb_event_queue_dequeue()) != NULL) {
|
97
|
+
gpr_mu_unlock(&event_queue.mu);
|
98
|
+
return event;
|
99
|
+
}
|
100
|
+
gpr_cv_wait(&event_queue.cv, &event_queue.mu,
|
101
|
+
gpr_inf_future(GPR_CLOCK_REALTIME));
|
102
|
+
}
|
103
|
+
gpr_mu_unlock(&event_queue.mu);
|
104
|
+
return NULL;
|
105
|
+
}
|
106
|
+
|
107
|
+
static void grpc_rb_event_unblocking_func(void* arg) {
|
108
|
+
(void)arg;
|
109
|
+
gpr_mu_lock(&event_queue.mu);
|
110
|
+
event_queue.abort = true;
|
111
|
+
gpr_cv_signal(&event_queue.cv);
|
112
|
+
gpr_mu_unlock(&event_queue.mu);
|
113
|
+
}
|
114
|
+
|
115
|
+
/* This is the implementation of the thread that handles auth metadata plugin
|
116
|
+
* events */
|
117
|
+
static VALUE grpc_rb_event_thread(VALUE arg) {
|
118
|
+
grpc_rb_event* event;
|
119
|
+
(void)arg;
|
120
|
+
grpc_ruby_init();
|
121
|
+
while (true) {
|
122
|
+
event = (grpc_rb_event*)rb_thread_call_without_gvl(
|
123
|
+
grpc_rb_wait_for_event_no_gil, NULL, grpc_rb_event_unblocking_func,
|
124
|
+
NULL);
|
125
|
+
if (event == NULL) {
|
126
|
+
// Indicates that the thread needs to shut down
|
127
|
+
break;
|
128
|
+
} else {
|
129
|
+
event->callback(event->argument);
|
130
|
+
gpr_free(event);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
grpc_rb_event_queue_destroy();
|
134
|
+
grpc_ruby_shutdown();
|
135
|
+
return Qnil;
|
136
|
+
}
|
137
|
+
|
138
|
+
void grpc_rb_event_queue_thread_start() {
|
139
|
+
event_queue.head = event_queue.tail = NULL;
|
140
|
+
event_queue.abort = false;
|
141
|
+
gpr_mu_init(&event_queue.mu);
|
142
|
+
gpr_cv_init(&event_queue.cv);
|
143
|
+
|
144
|
+
rb_thread_create(grpc_rb_event_thread, NULL);
|
145
|
+
}
|
@@ -0,0 +1,21 @@
|
|
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
|
+
void grpc_rb_event_queue_thread_start();
|
20
|
+
|
21
|
+
void grpc_rb_event_queue_enqueue(void (*callback)(void*), void* argument);
|