grpc 1.42.0.pre1-arm64-darwin

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.

Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +123 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  17. data/src/ruby/ext/grpc/rb_call.h +57 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +846 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +385 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  43. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  44. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  45. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  46. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  47. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  48. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  49. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  50. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  51. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  52. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  53. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  54. data/src/ruby/lib/grpc/errors.rb +277 -0
  55. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  56. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  57. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  58. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  59. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  60. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  61. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  62. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  63. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  64. data/src/ruby/lib/grpc/grpc.rb +24 -0
  65. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  66. data/src/ruby/lib/grpc/notifier.rb +45 -0
  67. data/src/ruby/lib/grpc/structs.rb +15 -0
  68. data/src/ruby/lib/grpc/version.rb +18 -0
  69. data/src/ruby/lib/grpc.rb +37 -0
  70. data/src/ruby/pb/README.md +42 -0
  71. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  72. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  73. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  74. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  75. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  76. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  77. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +145 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  82. data/src/ruby/pb/test/client.rb +769 -0
  83. data/src/ruby/pb/test/server.rb +252 -0
  84. data/src/ruby/pb/test/xds_client.rb +415 -0
  85. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  86. data/src/ruby/spec/call_spec.rb +180 -0
  87. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  88. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  89. data/src/ruby/spec/channel_spec.rb +245 -0
  90. data/src/ruby/spec/client_auth_spec.rb +152 -0
  91. data/src/ruby/spec/client_server_spec.rb +664 -0
  92. data/src/ruby/spec/compression_options_spec.rb +149 -0
  93. data/src/ruby/spec/debug_message_spec.rb +134 -0
  94. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  95. data/src/ruby/spec/errors_spec.rb +142 -0
  96. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  97. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  98. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  99. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  100. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  101. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  102. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  103. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  104. data/src/ruby/spec/generic/service_spec.rb +263 -0
  105. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  112. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  113. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  114. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  115. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  116. data/src/ruby/spec/server_spec.rb +231 -0
  117. data/src/ruby/spec/spec_helper.rb +61 -0
  118. data/src/ruby/spec/support/helpers.rb +107 -0
  119. data/src/ruby/spec/support/services.rb +160 -0
  120. data/src/ruby/spec/testdata/README +1 -0
  121. data/src/ruby/spec/testdata/ca.pem +20 -0
  122. data/src/ruby/spec/testdata/client.key +28 -0
  123. data/src/ruby/spec/testdata/client.pem +20 -0
  124. data/src/ruby/spec/testdata/server1.key +28 -0
  125. data/src/ruby/spec/testdata/server1.pem +22 -0
  126. data/src/ruby/spec/time_consts_spec.rb +74 -0
  127. data/src/ruby/spec/user_agent_spec.rb +74 -0
  128. metadata +404 -0
@@ -0,0 +1,233 @@
1
+ # Copyright 2015 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'forwardable'
16
+ require_relative '../grpc'
17
+
18
+ # GRPC contains the General RPC module.
19
+ module GRPC
20
+ # The BiDiCall class orchestrates execution of a BiDi stream on a client or
21
+ # server.
22
+ class BidiCall
23
+ include Core::CallOps
24
+ include Core::StatusCodes
25
+ include Core::TimeConsts
26
+
27
+ # Creates a BidiCall.
28
+ #
29
+ # BidiCall should only be created after a call is accepted. That means
30
+ # different things on a client and a server. On the client, the call is
31
+ # accepted after call.invoke. On the server, this is after call.accept.
32
+ #
33
+ # #initialize cannot determine if the call is accepted or not; so if a
34
+ # call that's not accepted is used here, the error won't be visible until
35
+ # the BidiCall#run is called.
36
+ #
37
+ # deadline is the absolute deadline for the call.
38
+ #
39
+ # @param call [Call] the call used by the ActiveCall
40
+ # @param marshal [Function] f(obj)->string that marshal requests
41
+ # @param unmarshal [Function] f(string)->obj that unmarshals responses
42
+ # @param metadata_received [true|false] indicates if metadata has already
43
+ # been received. Should always be true for server calls
44
+ def initialize(call, marshal, unmarshal, metadata_received: false,
45
+ req_view: nil)
46
+ fail(ArgumentError, 'not a call') unless call.is_a? Core::Call
47
+ @call = call
48
+ @marshal = marshal
49
+ @op_notifier = nil # signals completion on clients
50
+ @unmarshal = unmarshal
51
+ @metadata_received = metadata_received
52
+ @reads_complete = false
53
+ @writes_complete = false
54
+ @complete = false
55
+ @done_mutex = Mutex.new
56
+ @req_view = req_view
57
+ end
58
+
59
+ # Begins orchestration of the Bidi stream for a client sending requests.
60
+ #
61
+ # The method either returns an Enumerator of the responses, or accepts a
62
+ # block that can be invoked with each response.
63
+ #
64
+ # @param requests the Enumerable of requests to send
65
+ # @param set_input_stream_done [Proc] called back when we're done
66
+ # reading the input stream
67
+ # @param set_output_stream_done [Proc] called back when we're done
68
+ # sending data on the output stream
69
+ # @return an Enumerator of requests to yield
70
+ def run_on_client(requests,
71
+ set_input_stream_done,
72
+ set_output_stream_done,
73
+ &blk)
74
+ @enq_th = Thread.new do
75
+ write_loop(requests, set_output_stream_done: set_output_stream_done)
76
+ end
77
+ read_loop(set_input_stream_done, &blk)
78
+ end
79
+
80
+ # Begins orchestration of the Bidi stream for a server generating replies.
81
+ #
82
+ # N.B. gen_each_reply is a func(Enumerable<Requests>)
83
+ #
84
+ # It takes an enumerable of requests as an arg, in case there is a
85
+ # relationship between the stream of requests and the stream of replies.
86
+ #
87
+ # This does not mean that must necessarily be one. E.g, the replies
88
+ # produced by gen_each_reply could ignore the received_msgs
89
+ #
90
+ # @param [Proc] gen_each_reply generates the BiDi stream replies.
91
+ # @param [Enumerable] requests The enumerable of requests to run
92
+ def run_on_server(gen_each_reply, requests)
93
+ replies = nil
94
+
95
+ # Pass in the optional call object parameter if possible
96
+ if gen_each_reply.arity == 1
97
+ replies = gen_each_reply.call(requests)
98
+ elsif gen_each_reply.arity == 2
99
+ replies = gen_each_reply.call(requests, @req_view)
100
+ else
101
+ fail 'Illegal arity of reply generator'
102
+ end
103
+
104
+ write_loop(replies, is_client: false)
105
+ end
106
+
107
+ ##
108
+ # Read the next stream iteration
109
+ #
110
+ # @param [Proc] finalize_stream callback to call when the reads have been
111
+ # completely read through.
112
+ # @param [Boolean] is_client If this is a client or server request
113
+ #
114
+ def read_next_loop(finalize_stream, is_client = false)
115
+ read_loop(finalize_stream, is_client: is_client)
116
+ end
117
+
118
+ private
119
+
120
+ END_OF_READS = :end_of_reads
121
+ END_OF_WRITES = :end_of_writes
122
+
123
+ # performs a read using @call.run_batch, ensures metadata is set up
124
+ def read_using_run_batch
125
+ ops = { RECV_MESSAGE => nil }
126
+ ops[RECV_INITIAL_METADATA] = nil unless @metadata_received
127
+ begin
128
+ batch_result = @call.run_batch(ops)
129
+ unless @metadata_received
130
+ @call.metadata = batch_result.metadata
131
+ @metadata_received = true
132
+ end
133
+ batch_result
134
+ rescue GRPC::Core::CallError => e
135
+ GRPC.logger.warn('bidi call: read_using_run_batch failed')
136
+ GRPC.logger.warn(e)
137
+ nil
138
+ end
139
+ end
140
+
141
+ # set_output_stream_done is relevant on client-side
142
+ def write_loop(requests, is_client: true, set_output_stream_done: nil)
143
+ GRPC.logger.debug('bidi-write-loop: starting')
144
+ count = 0
145
+ requests.each do |req|
146
+ GRPC.logger.debug("bidi-write-loop: #{count}")
147
+ count += 1
148
+ payload = @marshal.call(req)
149
+ # Fails if status already received
150
+ begin
151
+ @req_view.send_initial_metadata unless @req_view.nil?
152
+ @call.run_batch(SEND_MESSAGE => payload)
153
+ rescue GRPC::Core::CallError => e
154
+ # This is almost definitely caused by a status arriving while still
155
+ # writing. Don't re-throw the error
156
+ GRPC.logger.warn('bidi-write-loop: ended with error')
157
+ GRPC.logger.warn(e)
158
+ break
159
+ end
160
+ end
161
+ GRPC.logger.debug("bidi-write-loop: #{count} writes done")
162
+ if is_client
163
+ GRPC.logger.debug("bidi-write-loop: client sent #{count}, waiting")
164
+ begin
165
+ @call.run_batch(SEND_CLOSE_FROM_CLIENT => nil)
166
+ rescue GRPC::Core::CallError => e
167
+ GRPC.logger.warn('bidi-write-loop: send close failed')
168
+ GRPC.logger.warn(e)
169
+ end
170
+ GRPC.logger.debug('bidi-write-loop: done')
171
+ end
172
+ GRPC.logger.debug('bidi-write-loop: finished')
173
+ rescue StandardError => e
174
+ GRPC.logger.warn('bidi-write-loop: failed')
175
+ GRPC.logger.warn(e)
176
+ if is_client
177
+ @call.cancel_with_status(GRPC::Core::StatusCodes::UNKNOWN,
178
+ "GRPC bidi call error: #{e.inspect}")
179
+ else
180
+ raise e
181
+ end
182
+ ensure
183
+ set_output_stream_done.call if is_client
184
+ end
185
+
186
+ # Provides an enumerator that yields results of remote reads
187
+ def read_loop(set_input_stream_done, is_client: true)
188
+ return enum_for(:read_loop,
189
+ set_input_stream_done,
190
+ is_client: is_client) unless block_given?
191
+ GRPC.logger.debug('bidi-read-loop: starting')
192
+ begin
193
+ count = 0
194
+ # queue the initial read before beginning the loop
195
+ loop do
196
+ GRPC.logger.debug("bidi-read-loop: #{count}")
197
+ count += 1
198
+ batch_result = read_using_run_batch
199
+
200
+ # handle the next message
201
+ if batch_result.nil? || batch_result.message.nil?
202
+ GRPC.logger.debug("bidi-read-loop: null batch #{batch_result}")
203
+
204
+ if is_client
205
+ batch_result = @call.run_batch(RECV_STATUS_ON_CLIENT => nil)
206
+ @call.status = batch_result.status
207
+ @call.trailing_metadata = @call.status.metadata if @call.status
208
+ GRPC.logger.debug("bidi-read-loop: done status #{@call.status}")
209
+ batch_result.check_status
210
+ end
211
+
212
+ GRPC.logger.debug('bidi-read-loop: done reading!')
213
+ break
214
+ end
215
+
216
+ res = @unmarshal.call(batch_result.message)
217
+ yield res
218
+ end
219
+ rescue StandardError => e
220
+ GRPC.logger.warn('bidi: read-loop failed')
221
+ GRPC.logger.warn(e)
222
+ raise e
223
+ ensure
224
+ set_input_stream_done.call
225
+ end
226
+ GRPC.logger.debug('bidi-read-loop: finished')
227
+ # Make sure that the write loop is done before finishing the call.
228
+ # Note that blocking is ok at this point because we've already received
229
+ # a status
230
+ @enq_th.join if is_client
231
+ end
232
+ end
233
+ end