grpc 1.60.0.pre1-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32-msvcrt.ruby +0 -0
  4. data/grpc_c.64-msvcrt.ruby +0 -0
  5. data/grpc_c.64-ucrt.ruby +0 -0
  6. data/src/ruby/bin/math_client.rb +140 -0
  7. data/src/ruby/bin/math_pb.rb +40 -0
  8. data/src/ruby/bin/math_server.rb +191 -0
  9. data/src/ruby/bin/math_services_pb.rb +51 -0
  10. data/src/ruby/bin/noproto_client.rb +93 -0
  11. data/src/ruby/bin/noproto_server.rb +97 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
  13. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
  14. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
  15. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
  16. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  17. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  18. data/src/ruby/ext/grpc/extconf.rb +270 -0
  19. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  20. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  21. data/src/ruby/ext/grpc/rb_call.c +1075 -0
  22. data/src/ruby/ext/grpc/rb_call.h +57 -0
  23. data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
  24. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  25. data/src/ruby/ext/grpc/rb_channel.c +875 -0
  26. data/src/ruby/ext/grpc/rb_channel.h +35 -0
  27. data/src/ruby/ext/grpc/rb_channel_args.c +172 -0
  28. data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
  29. data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
  30. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  31. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  32. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  33. data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
  34. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  35. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  36. data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
  37. data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
  38. data/src/ruby/ext/grpc/rb_grpc.c +496 -0
  39. data/src/ruby/ext/grpc/rb_grpc.h +83 -0
  40. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +603 -0
  41. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +910 -0
  42. data/src/ruby/ext/grpc/rb_loader.c +61 -0
  43. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  44. data/src/ruby/ext/grpc/rb_server.c +405 -0
  45. data/src/ruby/ext/grpc/rb_server.h +32 -0
  46. data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
  47. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  48. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
  49. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  50. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  51. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  52. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  53. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  54. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  55. data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
  56. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  57. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  58. data/src/ruby/lib/grpc/errors.rb +277 -0
  59. data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
  60. data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
  61. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  62. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  63. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  64. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  65. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  66. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  67. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  68. data/src/ruby/lib/grpc/grpc.rb +24 -0
  69. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  70. data/src/ruby/lib/grpc/notifier.rb +45 -0
  71. data/src/ruby/lib/grpc/structs.rb +15 -0
  72. data/src/ruby/lib/grpc/version.rb +18 -0
  73. data/src/ruby/lib/grpc.rb +37 -0
  74. data/src/ruby/pb/README.md +42 -0
  75. data/src/ruby/pb/generate_proto_ruby.sh +46 -0
  76. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  77. data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
  78. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  79. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  80. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  81. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  82. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
  83. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +71 -0
  84. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
  85. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
  86. data/src/ruby/pb/test/client.rb +785 -0
  87. data/src/ruby/pb/test/server.rb +252 -0
  88. data/src/ruby/pb/test/xds_client.rb +415 -0
  89. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  90. data/src/ruby/spec/call_spec.rb +180 -0
  91. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  92. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  93. data/src/ruby/spec/channel_spec.rb +207 -0
  94. data/src/ruby/spec/client_auth_spec.rb +152 -0
  95. data/src/ruby/spec/client_server_spec.rb +676 -0
  96. data/src/ruby/spec/compression_options_spec.rb +149 -0
  97. data/src/ruby/spec/debug_message_spec.rb +134 -0
  98. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  99. data/src/ruby/spec/errors_spec.rb +142 -0
  100. data/src/ruby/spec/generic/active_call_spec.rb +692 -0
  101. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  102. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  103. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  104. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  105. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  106. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  107. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  108. data/src/ruby/spec/generic/service_spec.rb +263 -0
  109. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  112. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  113. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  114. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  115. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  116. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  117. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  118. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  119. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  120. data/src/ruby/spec/server_spec.rb +231 -0
  121. data/src/ruby/spec/spec_helper.rb +61 -0
  122. data/src/ruby/spec/support/helpers.rb +107 -0
  123. data/src/ruby/spec/support/services.rb +160 -0
  124. data/src/ruby/spec/testdata/README +1 -0
  125. data/src/ruby/spec/testdata/ca.pem +20 -0
  126. data/src/ruby/spec/testdata/client.key +28 -0
  127. data/src/ruby/spec/testdata/client.pem +20 -0
  128. data/src/ruby/spec/testdata/server1.key +28 -0
  129. data/src/ruby/spec/testdata/server1.pem +22 -0
  130. data/src/ruby/spec/time_consts_spec.rb +74 -0
  131. data/src/ruby/spec/user_agent_spec.rb +74 -0
  132. metadata +405 -0
File without changes
File without changes
File without changes
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
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
+ # Sample app that accesses a Calc service running on a Ruby gRPC server and
18
+ # helps validate RpcServer as a gRPC server using proto2 serialization.
19
+ #
20
+ # Usage: $ path/to/math_client.rb
21
+
22
+ this_dir = File.expand_path(File.dirname(__FILE__))
23
+ lib_dir = File.join(File.dirname(this_dir), 'lib')
24
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
25
+ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
26
+
27
+ require 'grpc'
28
+ require 'math_services_pb'
29
+ require 'optparse'
30
+ require 'logger'
31
+
32
+ include GRPC::Core::TimeConsts
33
+
34
+ module StdoutLogger
35
+ def logger
36
+ LOGGER
37
+ end
38
+
39
+ LOGGER = Logger.new(STDOUT)
40
+ end
41
+
42
+ GRPC.extend(StdoutLogger)
43
+
44
+ def do_div(stub)
45
+ GRPC.logger.info('request_response')
46
+ GRPC.logger.info('----------------')
47
+ req = Math::DivArgs.new(dividend: 7, divisor: 3)
48
+ GRPC.logger.info("div(7/3): req=#{req.inspect}")
49
+ resp = stub.div(req)
50
+ GRPC.logger.info("Answer: #{resp.inspect}")
51
+ GRPC.logger.info('----------------')
52
+ end
53
+
54
+ def do_sum(stub)
55
+ # to make client streaming requests, pass an enumerable of the inputs
56
+ GRPC.logger.info('client_streamer')
57
+ GRPC.logger.info('---------------')
58
+ reqs = [1, 2, 3, 4, 5].map { |x| Math::Num.new(num: x) }
59
+ GRPC.logger.info("sum(1, 2, 3, 4, 5): reqs=#{reqs.inspect}")
60
+ resp = stub.sum(reqs) # reqs.is_a?(Enumerable)
61
+ GRPC.logger.info("Answer: #{resp.inspect}")
62
+ GRPC.logger.info('---------------')
63
+ end
64
+
65
+ def do_fib(stub)
66
+ GRPC.logger.info('server_streamer')
67
+ GRPC.logger.info('----------------')
68
+ req = Math::FibArgs.new(limit: 11)
69
+ GRPC.logger.info("fib(11): req=#{req.inspect}")
70
+ resp = stub.fib(req)
71
+ resp.each do |r|
72
+ GRPC.logger.info("Answer: #{r.inspect}")
73
+ end
74
+ GRPC.logger.info('----------------')
75
+ end
76
+
77
+ def do_div_many(stub)
78
+ GRPC.logger.info('bidi_streamer')
79
+ GRPC.logger.info('-------------')
80
+ reqs = []
81
+ reqs << Math::DivArgs.new(dividend: 7, divisor: 3)
82
+ reqs << Math::DivArgs.new(dividend: 5, divisor: 2)
83
+ reqs << Math::DivArgs.new(dividend: 7, divisor: 2)
84
+ GRPC.logger.info("div(7/3), div(5/2), div(7/2): reqs=#{reqs.inspect}")
85
+ resp = stub.div_many(reqs)
86
+ resp.each do |r|
87
+ GRPC.logger.info("Answer: #{r.inspect}")
88
+ end
89
+ GRPC.logger.info('----------------')
90
+ end
91
+
92
+ def load_test_certs
93
+ this_dir = File.expand_path(File.dirname(__FILE__))
94
+ data_dir = File.join(File.dirname(this_dir), 'spec/testdata')
95
+ files = ['ca.pem', 'server1.key', 'server1.pem']
96
+ files.map { |f| File.open(File.join(data_dir, f)).read }
97
+ end
98
+
99
+ def test_creds
100
+ certs = load_test_certs
101
+ GRPC::Core::ChannelCredentials.new(certs[0])
102
+ end
103
+
104
+ def main
105
+ options = {
106
+ 'host' => 'localhost:7071',
107
+ 'secure' => false
108
+ }
109
+ OptionParser.new do |opts|
110
+ opts.banner = 'Usage: [--host <hostname>:<port>] [--secure|-s]'
111
+ opts.on('--host HOST', '<hostname>:<port>') do |v|
112
+ options['host'] = v
113
+ end
114
+ opts.on('-s', '--secure', 'access using test creds') do |v|
115
+ options['secure'] = v
116
+ end
117
+ end.parse!
118
+
119
+ # The Math::Math:: module occurs because the service has the same name as its
120
+ # package. That practice should be avoided by defining real services.
121
+ if options['secure']
122
+ stub_opts = {
123
+ :creds => test_creds,
124
+ GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr',
125
+ timeout: INFINITE_FUTURE,
126
+ }
127
+ stub = Math::Math::Stub.new(options['host'], **stub_opts)
128
+ GRPC.logger.info("... connecting securely on #{options['host']}")
129
+ else
130
+ stub = Math::Math::Stub.new(options['host'], :this_channel_is_insecure, timeout: INFINITE_FUTURE)
131
+ GRPC.logger.info("... connecting insecurely on #{options['host']}")
132
+ end
133
+
134
+ do_div(stub)
135
+ do_sum(stub)
136
+ do_fib(stub)
137
+ do_div_many(stub)
138
+ end
139
+
140
+ main
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: math.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+
8
+ descriptor_data = "\n\nmath.proto\x12\x04math\",\n\x07\x44ivArgs\x12\x10\n\x08\x64ividend\x18\x01 \x01(\x03\x12\x0f\n\x07\x64ivisor\x18\x02 \x01(\x03\"/\n\x08\x44ivReply\x12\x10\n\x08quotient\x18\x01 \x01(\x03\x12\x11\n\tremainder\x18\x02 \x01(\x03\"\x18\n\x07\x46ibArgs\x12\r\n\x05limit\x18\x01 \x01(\x03\"\x12\n\x03Num\x12\x0b\n\x03num\x18\x01 \x01(\x03\"\x19\n\x08\x46ibReply\x12\r\n\x05\x63ount\x18\x01 \x01(\x03\x32\xa4\x01\n\x04Math\x12&\n\x03\x44iv\x12\r.math.DivArgs\x1a\x0e.math.DivReply\"\x00\x12.\n\x07\x44ivMany\x12\r.math.DivArgs\x1a\x0e.math.DivReply\"\x00(\x01\x30\x01\x12#\n\x03\x46ib\x12\r.math.FibArgs\x1a\t.math.Num\"\x00\x30\x01\x12\x1f\n\x03Sum\x12\t.math.Num\x1a\t.math.Num\"\x00(\x01\x62\x06proto3"
9
+
10
+ pool = Google::Protobuf::DescriptorPool.generated_pool
11
+
12
+ begin
13
+ pool.add_serialized_file(descriptor_data)
14
+ rescue TypeError
15
+ # Compatibility code: will be removed in the next major version.
16
+ require 'google/protobuf/descriptor_pb'
17
+ parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
18
+ parsed.clear_dependency
19
+ serialized = parsed.class.encode(parsed)
20
+ file = pool.add_serialized_file(serialized)
21
+ warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
22
+ imports = [
23
+ ]
24
+ imports.each do |type_name, expected_filename|
25
+ import_file = pool.lookup(type_name).file_descriptor
26
+ if import_file.name != expected_filename
27
+ warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
28
+ end
29
+ end
30
+ warn "Each proto file must use a consistent fully-qualified name."
31
+ warn "This will become an error in the next major version."
32
+ end
33
+
34
+ module Math
35
+ DivArgs = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("math.DivArgs").msgclass
36
+ DivReply = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("math.DivReply").msgclass
37
+ FibArgs = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("math.FibArgs").msgclass
38
+ Num = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("math.Num").msgclass
39
+ FibReply = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("math.FibReply").msgclass
40
+ end
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env ruby
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
+ # Sample gRPC Ruby server that implements the Math::Calc service and helps
18
+ # validate GRPC::RpcServer as GRPC implementation using proto2 serialization.
19
+ #
20
+ # Usage: $ path/to/math_server.rb
21
+
22
+ this_dir = File.expand_path(File.dirname(__FILE__))
23
+ lib_dir = File.join(File.dirname(this_dir), 'lib')
24
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
25
+ $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
26
+
27
+ require 'forwardable'
28
+ require 'grpc'
29
+ require 'logger'
30
+ require 'math_services_pb'
31
+ require 'optparse'
32
+
33
+ # RubyLogger defines a logger for gRPC based on the standard ruby logger.
34
+ module RubyLogger
35
+ def logger
36
+ LOGGER
37
+ end
38
+
39
+ LOGGER = Logger.new(STDOUT)
40
+ end
41
+
42
+ # GRPC is the general RPC module
43
+ module GRPC
44
+ # Inject the noop #logger if no module-level logger method has been injected.
45
+ extend RubyLogger
46
+ end
47
+
48
+ # Holds state for a fibonacci series
49
+ class Fibber
50
+ def initialize(limit)
51
+ fail "bad limit: got #{limit}, want limit > 0" if limit < 1
52
+ @limit = limit
53
+ end
54
+
55
+ def generator
56
+ return enum_for(:generator) unless block_given?
57
+ idx, current, previous = 0, 1, 1
58
+ until idx == @limit
59
+ if idx.zero? || idx == 1
60
+ yield Math::Num.new(num: 1)
61
+ idx += 1
62
+ next
63
+ end
64
+ tmp = current
65
+ current = previous + current
66
+ previous = tmp
67
+ yield Math::Num.new(num: current)
68
+ idx += 1
69
+ end
70
+ end
71
+ end
72
+
73
+ # A EnumeratorQueue wraps a Queue to yield the items added to it.
74
+ class EnumeratorQueue
75
+ extend Forwardable
76
+ def_delegators :@q, :push
77
+
78
+ def initialize(sentinel)
79
+ @q = Queue.new
80
+ @sentinel = sentinel
81
+ end
82
+
83
+ def each_item
84
+ return enum_for(:each_item) unless block_given?
85
+ loop do
86
+ r = @q.pop
87
+ break if r.equal?(@sentinel)
88
+ fail r if r.is_a? Exception
89
+ yield r
90
+ end
91
+ end
92
+ end
93
+
94
+ # The Math::Math:: module occurs because the service has the same name as its
95
+ # package. That practice should be avoided by defining real services.
96
+ class Calculator < Math::Math::Service
97
+ def div(div_args, _call)
98
+ if div_args.divisor.zero?
99
+ # To send non-OK status handlers raise a StatusError with the code and
100
+ # and detail they want sent as a Status.
101
+ fail GRPC::StatusError.new(GRPC::Status::INVALID_ARGUMENT,
102
+ 'divisor cannot be 0')
103
+ end
104
+
105
+ Math::DivReply.new(quotient: div_args.dividend / div_args.divisor,
106
+ remainder: div_args.dividend % div_args.divisor)
107
+ end
108
+
109
+ def sum(call)
110
+ # the requests are accesible as the Enumerator call#each_request
111
+ nums = call.each_remote_read.collect(&:num)
112
+ sum = nums.inject { |s, x| s + x }
113
+ Math::Num.new(num: sum)
114
+ end
115
+
116
+ def fib(fib_args, _call)
117
+ if fib_args.limit < 1
118
+ fail StatusError.new(Status::INVALID_ARGUMENT, 'limit must be >= 0')
119
+ end
120
+
121
+ # return an Enumerator of Nums
122
+ Fibber.new(fib_args.limit).generator
123
+ # just return the generator, GRPC::GenericServer sends each actual response
124
+ end
125
+
126
+ def div_many(requests)
127
+ # requests is an lazy Enumerator of the requests sent by the client.
128
+ q = EnumeratorQueue.new(self)
129
+ t = Thread.new do
130
+ begin
131
+ requests.each do |req|
132
+ GRPC.logger.info("read #{req.inspect}")
133
+ resp = Math::DivReply.new(quotient: req.dividend / req.divisor,
134
+ remainder: req.dividend % req.divisor)
135
+ q.push(resp)
136
+ Thread.pass # let the internal Bidi threads run
137
+ end
138
+ GRPC.logger.info('finished reads')
139
+ q.push(self)
140
+ rescue StandardError => e
141
+ q.push(e) # share the exception with the enumerator
142
+ raise e
143
+ end
144
+ end
145
+ t.priority = -2 # hint that the div_many thread should not be favoured
146
+ q.each_item
147
+ end
148
+ end
149
+
150
+ def load_test_certs
151
+ this_dir = File.expand_path(File.dirname(__FILE__))
152
+ data_dir = File.join(File.dirname(this_dir), 'spec/testdata')
153
+ files = ['ca.pem', 'server1.key', 'server1.pem']
154
+ files.map { |f| File.open(File.join(data_dir, f)).read }
155
+ end
156
+
157
+ def test_server_creds
158
+ certs = load_test_certs
159
+ GRPC::Core::ServerCredentials.new(
160
+ nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
161
+ end
162
+
163
+ def main
164
+ options = {
165
+ 'host' => 'localhost:7071',
166
+ 'secure' => false
167
+ }
168
+ OptionParser.new do |opts|
169
+ opts.banner = 'Usage: [--host <hostname>:<port>] [--secure|-s]'
170
+ opts.on('--host HOST', '<hostname>:<port>') do |v|
171
+ options['host'] = v
172
+ end
173
+ opts.on('-s', '--secure', 'access using test creds') do |v|
174
+ options['secure'] = v
175
+ end
176
+ end.parse!
177
+
178
+ s = GRPC::RpcServer.new
179
+ if options['secure']
180
+ s.add_http2_port(options['host'], test_server_creds)
181
+ GRPC.logger.info("... running securely on #{options['host']}")
182
+ else
183
+ s.add_http2_port(options['host'], :this_port_is_insecure)
184
+ GRPC.logger.info("... running insecurely on #{options['host']}")
185
+ end
186
+
187
+ s.handle(Calculator)
188
+ s.run_till_terminated
189
+ end
190
+
191
+ main
@@ -0,0 +1,51 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: math.proto for package 'math'
3
+ # Original file comments:
4
+ # Copyright 2015 gRPC authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'grpc'
20
+ require 'math_pb'
21
+
22
+ module Math
23
+ module Math
24
+ class Service
25
+
26
+ include ::GRPC::GenericService
27
+
28
+ self.marshal_class_method = :encode
29
+ self.unmarshal_class_method = :decode
30
+ self.service_name = 'math.Math'
31
+
32
+ # Div divides DivArgs.dividend by DivArgs.divisor and returns the quotient
33
+ # and remainder.
34
+ rpc :Div, ::Math::DivArgs, ::Math::DivReply
35
+ # DivMany accepts an arbitrary number of division args from the client stream
36
+ # and sends back the results in the reply stream. The stream continues until
37
+ # the client closes its end; the server does the same after sending all the
38
+ # replies. The stream ends immediately if either end aborts.
39
+ rpc :DivMany, stream(::Math::DivArgs), stream(::Math::DivReply)
40
+ # Fib generates numbers in the Fibonacci sequence. If FibArgs.limit > 0, Fib
41
+ # generates up to limit numbers; otherwise it continues until the call is
42
+ # canceled. Unlike Fib above, Fib has no final FibReply.
43
+ rpc :Fib, ::Math::FibArgs, stream(::Math::Num)
44
+ # Sum sums a stream of numbers, returning the final result once the stream
45
+ # is closed.
46
+ rpc :Sum, stream(::Math::Num), ::Math::Num
47
+ end
48
+
49
+ Stub = Service.rpc_stub_class
50
+ end
51
+ end
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
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
+ # Sample app that helps validate RpcServer without protobuf serialization.
18
+ #
19
+ # Usage: $ ruby -S path/to/noproto_client.rb
20
+
21
+ this_dir = File.expand_path(File.dirname(__FILE__))
22
+ lib_dir = File.join(File.dirname(this_dir), 'lib')
23
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
24
+
25
+ require 'grpc'
26
+ require 'optparse'
27
+
28
+ # a simple non-protobuf message class.
29
+ class NoProtoMsg
30
+ def self.marshal(_o)
31
+ ''
32
+ end
33
+
34
+ def self.unmarshal(_o)
35
+ NoProtoMsg.new
36
+ end
37
+ end
38
+
39
+ # service the uses the non-protobuf message class.
40
+ class NoProtoService
41
+ include GRPC::GenericService
42
+ rpc :AnRPC, NoProtoMsg, NoProtoMsg
43
+ end
44
+
45
+ NoProtoStub = NoProtoService.rpc_stub_class
46
+
47
+ def load_test_certs
48
+ this_dir = File.expand_path(File.dirname(__FILE__))
49
+ data_dir = File.join(File.dirname(this_dir), 'spec/testdata')
50
+ files = ['ca.pem', 'server1.key', 'server1.pem']
51
+ files.map { |f| File.open(File.join(data_dir, f)).read }
52
+ end
53
+
54
+ def test_creds
55
+ certs = load_test_certs
56
+ GRPC::Core::ChannelCredentials.new(certs[0])
57
+ end
58
+
59
+ def main
60
+ options = {
61
+ 'host' => 'localhost:7071',
62
+ 'secure' => false
63
+ }
64
+ OptionParser.new do |opts|
65
+ opts.banner = 'Usage: [--host <hostname>:<port>] [--secure|-s]'
66
+ opts.on('--host HOST', '<hostname>:<port>') do |v|
67
+ options['host'] = v
68
+ end
69
+ opts.on('-s', '--secure', 'access using test creds') do |v|
70
+ options['secure'] = v
71
+ end
72
+ end.parse!
73
+
74
+ if options['secure']
75
+ stub_opts = {
76
+ :creds => test_creds,
77
+ GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr'
78
+ }
79
+ p stub_opts
80
+ p options['host']
81
+ stub = NoProtoStub.new(options['host'], **stub_opts)
82
+ GRPC.logger.info("... connecting securely on #{options['host']}")
83
+ else
84
+ stub = NoProtoStub.new(options['host'])
85
+ GRPC.logger.info("... connecting insecurely on #{options['host']}")
86
+ end
87
+
88
+ GRPC.logger.info('sending a NoProto rpc')
89
+ resp = stub.an_rpc(NoProtoMsg.new)
90
+ GRPC.logger.info("got a response: #{resp}")
91
+ end
92
+
93
+ main
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
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
+ # Sample app that helps validate RpcServer without protobuf serialization.
18
+ #
19
+ # Usage: $ path/to/noproto_server.rb
20
+
21
+ this_dir = File.expand_path(File.dirname(__FILE__))
22
+ lib_dir = File.join(File.dirname(this_dir), 'lib')
23
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
24
+
25
+ require 'grpc'
26
+ require 'optparse'
27
+
28
+ # a simple non-protobuf message class.
29
+ class NoProtoMsg
30
+ def self.marshal(_o)
31
+ ''
32
+ end
33
+
34
+ def self.unmarshal(_o)
35
+ NoProtoMsg.new
36
+ end
37
+ end
38
+
39
+ # service the uses the non-protobuf message class.
40
+ class NoProtoService
41
+ include GRPC::GenericService
42
+ rpc :AnRPC, NoProtoMsg, NoProtoMsg
43
+ end
44
+
45
+ # an implementation of the non-protobuf service.
46
+ class NoProto < NoProtoService
47
+ def initialize(_default_var = 'ignored')
48
+ end
49
+
50
+ def an_rpc(req, _call)
51
+ GRPC.logger.info('echo service received a request')
52
+ req
53
+ end
54
+ end
55
+
56
+ def load_test_certs
57
+ this_dir = File.expand_path(File.dirname(__FILE__))
58
+ data_dir = File.join(File.dirname(this_dir), 'spec/testdata')
59
+ files = ['ca.pem', 'server1.key', 'server1.pem']
60
+ files.map { |f| File.open(File.join(data_dir, f)).read }
61
+ end
62
+
63
+ def test_server_creds
64
+ certs = load_test_certs
65
+ GRPC::Core::ServerCredentials.new(
66
+ nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
67
+ end
68
+
69
+ def main
70
+ options = {
71
+ 'host' => 'localhost:9090',
72
+ 'secure' => false
73
+ }
74
+ OptionParser.new do |opts|
75
+ opts.banner = 'Usage: [--host <hostname>:<port>] [--secure|-s]'
76
+ opts.on('--host HOST', '<hostname>:<port>') do |v|
77
+ options['host'] = v
78
+ end
79
+ opts.on('-s', '--secure', 'access using test creds') do |v|
80
+ options['secure'] = v
81
+ end
82
+ end.parse!
83
+
84
+ s = GRPC::RpcServer.new
85
+ if options['secure']
86
+ s.add_http2_port(options['host'], test_server_creds)
87
+ GRPC.logger.info("... running securely on #{options['host']}")
88
+ else
89
+ s.add_http2_port(options['host'], :this_port_is_insecure)
90
+ GRPC.logger.info("... running insecurely on #{options['host']}")
91
+ end
92
+
93
+ s.handle(NoProto)
94
+ s.run_till_terminated
95
+ end
96
+
97
+ main
@@ -0,0 +1,2 @@
1
+ _Init_grpc_c
2
+ _rb_tr_abi_version
@@ -0,0 +1,7 @@
1
+ grpc_1.0 {
2
+ global:
3
+ Init_grpc_c;
4
+ rb_tr_abi_version;
5
+ local:
6
+ *;
7
+ };
@@ -0,0 +1,2 @@
1
+ _Init_grpc_c
2
+ _ruby_abi_version
@@ -0,0 +1,7 @@
1
+ grpc_1.0 {
2
+ global:
3
+ Init_grpc_c;
4
+ ruby_abi_version;
5
+ local:
6
+ *;
7
+ };
@@ -0,0 +1 @@
1
+ _Init_grpc_c
@@ -0,0 +1,6 @@
1
+ grpc_1.0 {
2
+ global:
3
+ Init_grpc_c;
4
+ local:
5
+ *;
6
+ };