grpc 1.22.0 → 1.23.0

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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +487 -649
  3. data/include/grpc/grpc_security.h +25 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +11 -2
  5. data/include/grpc/impl/codegen/port_platform.h +12 -0
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
  10. data/src/core/ext/filters/client_channel/connector.h +10 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
  12. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
  13. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
  14. data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
  19. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
  20. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
  22. data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
  23. data/src/core/ext/filters/client_channel/resolver.h +3 -11
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
  31. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
  32. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
  33. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
  34. data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
  35. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
  36. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
  37. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
  38. data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
  39. data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
  40. data/src/core/ext/filters/client_channel/subchannel.h +65 -45
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
  42. data/src/core/ext/filters/client_idle/client_idle_filter.cc +262 -0
  43. data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
  44. data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
  45. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
  46. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +63 -38
  50. data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
  53. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -0
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +7 -0
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +1 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -81
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
  60. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
  61. data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
  62. data/src/core/ext/transport/chttp2/transport/internal.h +13 -2
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -22
  64. data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
  65. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -0
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  67. data/src/core/lib/channel/channelz.cc +80 -33
  68. data/src/core/lib/channel/channelz.h +28 -13
  69. data/src/core/lib/compression/compression.cc +1 -2
  70. data/src/core/lib/compression/compression_args.cc +13 -6
  71. data/src/core/lib/compression/compression_args.h +3 -2
  72. data/src/core/lib/compression/compression_internal.cc +1 -1
  73. data/src/core/lib/gpr/env_linux.cc +10 -21
  74. data/src/core/lib/gpr/env_posix.cc +0 -5
  75. data/src/core/lib/gpr/string.cc +7 -2
  76. data/src/core/lib/gpr/string.h +1 -0
  77. data/src/core/lib/gpr/sync_posix.cc +0 -129
  78. data/src/core/lib/gprpp/debug_location.h +3 -2
  79. data/src/core/lib/gprpp/fork.cc +14 -21
  80. data/src/core/lib/gprpp/fork.h +15 -4
  81. data/src/core/lib/gprpp/host_port.cc +118 -0
  82. data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
  83. data/src/core/lib/gprpp/map.h +25 -0
  84. data/src/core/lib/gprpp/memory.h +26 -9
  85. data/src/core/lib/gprpp/ref_counted.h +63 -21
  86. data/src/core/lib/gprpp/string_view.h +143 -0
  87. data/src/core/lib/gprpp/thd.h +10 -1
  88. data/src/core/lib/gprpp/thd_posix.cc +25 -0
  89. data/src/core/lib/gprpp/thd_windows.cc +9 -1
  90. data/src/core/lib/http/httpcli_security_connector.cc +3 -1
  91. data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
  92. data/src/core/lib/iomgr/cfstream_handle.h +8 -2
  93. data/src/core/lib/iomgr/combiner.cc +4 -4
  94. data/src/core/lib/iomgr/error.cc +18 -8
  95. data/src/core/lib/iomgr/error.h +2 -0
  96. data/src/core/lib/iomgr/ev_posix.cc +4 -2
  97. data/src/core/lib/iomgr/executor.cc +4 -1
  98. data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
  99. data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
  100. data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
  101. data/src/core/lib/iomgr/executor/threadpool.h +153 -0
  102. data/src/core/lib/iomgr/fork_posix.cc +4 -2
  103. data/src/core/lib/iomgr/iocp_windows.cc +2 -2
  104. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
  105. data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
  106. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  107. data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
  108. data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
  109. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  110. data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
  111. data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
  112. data/src/core/lib/iomgr/socket_windows.h +1 -1
  113. data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
  114. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
  115. data/src/core/lib/iomgr/tcp_custom.cc +4 -0
  116. data/src/core/lib/iomgr/tcp_posix.cc +8 -2
  117. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
  118. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  119. data/src/core/lib/iomgr/tcp_windows.cc +7 -7
  120. data/src/core/lib/iomgr/timer_custom.cc +1 -0
  121. data/src/core/lib/iomgr/timer_manager.cc +0 -29
  122. data/src/core/lib/security/credentials/credentials.cc +84 -0
  123. data/src/core/lib/security/credentials/credentials.h +58 -2
  124. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
  125. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
  127. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
  128. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
  129. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
  130. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
  131. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  132. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  133. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
  134. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
  135. data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
  136. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
  137. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
  138. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  139. data/src/core/lib/security/util/json_util.cc +19 -5
  140. data/src/core/lib/security/util/json_util.h +3 -1
  141. data/src/core/lib/slice/slice.cc +69 -50
  142. data/src/core/lib/slice/slice_buffer.cc +6 -5
  143. data/src/core/lib/slice/slice_hash_table.h +3 -7
  144. data/src/core/lib/slice/slice_intern.cc +130 -39
  145. data/src/core/lib/slice/slice_internal.h +8 -0
  146. data/src/core/lib/slice/slice_utils.h +120 -0
  147. data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
  148. data/src/core/lib/surface/call.cc +8 -3
  149. data/src/core/lib/surface/channel.cc +31 -8
  150. data/src/core/lib/surface/completion_queue.cc +17 -7
  151. data/src/core/lib/surface/init_secure.cc +4 -1
  152. data/src/core/lib/surface/lame_client.cc +2 -2
  153. data/src/core/lib/surface/server.cc +34 -35
  154. data/src/core/lib/surface/server.h +8 -17
  155. data/src/core/lib/surface/version.cc +1 -1
  156. data/src/core/lib/transport/byte_stream.cc +3 -5
  157. data/src/core/lib/transport/byte_stream.h +1 -2
  158. data/src/core/lib/transport/error_utils.cc +10 -1
  159. data/src/core/lib/transport/metadata.cc +202 -35
  160. data/src/core/lib/transport/metadata.h +81 -6
  161. data/src/core/lib/transport/static_metadata.cc +1257 -465
  162. data/src/core/lib/transport/static_metadata.h +190 -347
  163. data/src/core/lib/transport/timeout_encoding.cc +7 -0
  164. data/src/core/lib/transport/timeout_encoding.h +3 -2
  165. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  166. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
  167. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
  168. data/src/core/tsi/ssl_transport_security.cc +35 -43
  169. data/src/core/tsi/ssl_transport_security.h +2 -1
  170. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  172. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  173. data/src/ruby/lib/grpc/grpc.rb +1 -1
  174. data/src/ruby/lib/grpc/version.rb +1 -1
  175. metadata +39 -33
  176. data/src/core/lib/gpr/host_port.cc +0 -98
@@ -58,13 +58,8 @@ namespace channelz {
58
58
  grpc_arg MakeParentUuidArg(intptr_t parent_uuid);
59
59
  intptr_t GetParentUuidFromArgs(const grpc_channel_args& args);
60
60
 
61
- // TODO(ncteisen), this only contains the uuids of the children for now,
62
- // since that is all that is strictly needed. In a future enhancement we will
63
- // add human readable names as in the channelz.proto
64
- typedef InlinedVector<intptr_t, 10> ChildRefsList;
65
-
66
61
  class SocketNode;
67
- typedef InlinedVector<SocketNode*, 10> ChildSocketsList;
62
+ class ListenSocketNode;
68
63
 
69
64
  namespace testing {
70
65
  class CallCountingHelperPeer;
@@ -85,7 +80,7 @@ class BaseNode : public RefCounted<BaseNode> {
85
80
  kSocket,
86
81
  };
87
82
 
88
- explicit BaseNode(EntityType type);
83
+ BaseNode(EntityType type, UniquePtr<char> name);
89
84
  virtual ~BaseNode();
90
85
 
91
86
  // All children must implement this function.
@@ -97,12 +92,14 @@ class BaseNode : public RefCounted<BaseNode> {
97
92
 
98
93
  EntityType type() const { return type_; }
99
94
  intptr_t uuid() const { return uuid_; }
95
+ const char* name() const { return name_.get(); }
100
96
 
101
97
  private:
102
98
  // to allow the ChannelzRegistry to set uuid_ under its lock.
103
99
  friend class ChannelzRegistry;
104
100
  const EntityType type_;
105
101
  intptr_t uuid_;
102
+ UniquePtr<char> name_;
106
103
  };
107
104
 
108
105
  // This class is a helper class for channelz entities that deal with Channels,
@@ -154,6 +151,10 @@ class ChannelNode : public BaseNode {
154
151
  ChannelNode(UniquePtr<char> target, size_t channel_tracer_max_nodes,
155
152
  intptr_t parent_uuid);
156
153
 
154
+ // Returns the string description of the given connectivity state.
155
+ static const char* GetChannelConnectivityStateChangeString(
156
+ grpc_connectivity_state state);
157
+
157
158
  intptr_t parent_uuid() const { return parent_uuid_; }
158
159
 
159
160
  grpc_json* RenderJson() override;
@@ -174,9 +175,13 @@ class ChannelNode : public BaseNode {
174
175
 
175
176
  void SetConnectivityState(grpc_connectivity_state state);
176
177
 
178
+ // TODO(roth): take in a RefCountedPtr to the child channel so we can retrieve
179
+ // the human-readable name.
177
180
  void AddChildChannel(intptr_t child_uuid);
178
181
  void RemoveChildChannel(intptr_t child_uuid);
179
182
 
183
+ // TODO(roth): take in a RefCountedPtr to the child subchannel so we can
184
+ // retrieve the human-readable name.
180
185
  void AddChildSubchannel(intptr_t child_uuid);
181
186
  void RemoveChildSubchannel(intptr_t child_uuid);
182
187
 
@@ -207,12 +212,20 @@ class ChannelNode : public BaseNode {
207
212
  class ServerNode : public BaseNode {
208
213
  public:
209
214
  ServerNode(grpc_server* server, size_t channel_tracer_max_nodes);
215
+
210
216
  ~ServerNode() override;
211
217
 
212
218
  grpc_json* RenderJson() override;
213
219
 
214
- char* RenderServerSockets(intptr_t start_socket_id,
215
- intptr_t pagination_limit);
220
+ char* RenderServerSockets(intptr_t start_socket_id, intptr_t max_results);
221
+
222
+ void AddChildSocket(RefCountedPtr<SocketNode> node);
223
+
224
+ void RemoveChildSocket(intptr_t child_uuid);
225
+
226
+ void AddChildListenSocket(RefCountedPtr<ListenSocketNode> node);
227
+
228
+ void RemoveChildListenSocket(intptr_t child_uuid);
216
229
 
217
230
  // proxy methods to composed classes.
218
231
  void AddTraceEvent(ChannelTrace::Severity severity, const grpc_slice& data) {
@@ -229,15 +242,18 @@ class ServerNode : public BaseNode {
229
242
  void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
230
243
 
231
244
  private:
232
- grpc_server* server_;
233
245
  CallCountingHelper call_counter_;
234
246
  ChannelTrace trace_;
247
+ Mutex child_mu_; // Guards child maps below.
248
+ Map<intptr_t, RefCountedPtr<SocketNode>> child_sockets_;
249
+ Map<intptr_t, RefCountedPtr<ListenSocketNode>> child_listen_sockets_;
235
250
  };
236
251
 
237
252
  // Handles channelz bookkeeping for sockets
238
253
  class SocketNode : public BaseNode {
239
254
  public:
240
- SocketNode(UniquePtr<char> local, UniquePtr<char> remote);
255
+ SocketNode(UniquePtr<char> local, UniquePtr<char> remote,
256
+ UniquePtr<char> name);
241
257
  ~SocketNode() override {}
242
258
 
243
259
  grpc_json* RenderJson() override;
@@ -276,8 +292,7 @@ class SocketNode : public BaseNode {
276
292
  // Handles channelz bookkeeping for listen sockets
277
293
  class ListenSocketNode : public BaseNode {
278
294
  public:
279
- // ListenSocketNode takes ownership of host.
280
- explicit ListenSocketNode(UniquePtr<char> local_addr);
295
+ ListenSocketNode(UniquePtr<char> local_addr, UniquePtr<char> name);
281
296
  ~ListenSocketNode() override {}
282
297
 
283
298
  grpc_json* RenderJson() override;
@@ -59,12 +59,11 @@ int grpc_compression_algorithm_parse(grpc_slice name,
59
59
  } else {
60
60
  return 0;
61
61
  }
62
- return 0;
63
62
  }
64
63
 
65
64
  int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm,
66
65
  const char** name) {
67
- GRPC_API_TRACE("grpc_compression_algorithm_parse(algorithm=%d, name=%p)", 2,
66
+ GRPC_API_TRACE("grpc_compression_algorithm_name(algorithm=%d, name=%p)", 2,
68
67
  ((int)algorithm, name));
69
68
  switch (algorithm) {
70
69
  case GRPC_COMPRESS_NONE:
@@ -32,21 +32,25 @@
32
32
  #include "src/core/lib/gpr/string.h"
33
33
  #include "src/core/lib/gpr/useful.h"
34
34
 
35
- grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
35
+ grpc_compression_algorithm
36
+ grpc_channel_args_get_channel_default_compression_algorithm(
36
37
  const grpc_channel_args* a) {
37
38
  size_t i;
38
39
  if (a == nullptr) return GRPC_COMPRESS_NONE;
39
40
  for (i = 0; i < a->num_args; ++i) {
40
41
  if (a->args[i].type == GRPC_ARG_INTEGER &&
41
42
  !strcmp(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, a->args[i].key)) {
42
- return static_cast<grpc_compression_algorithm>(a->args[i].value.integer);
43
- break;
43
+ grpc_compression_algorithm default_algorithm =
44
+ static_cast<grpc_compression_algorithm>(a->args[i].value.integer);
45
+ return default_algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT
46
+ ? default_algorithm
47
+ : GRPC_COMPRESS_NONE;
44
48
  }
45
49
  }
46
50
  return GRPC_COMPRESS_NONE;
47
51
  }
48
52
 
49
- grpc_channel_args* grpc_channel_args_set_compression_algorithm(
53
+ grpc_channel_args* grpc_channel_args_set_channel_default_compression_algorithm(
50
54
  grpc_channel_args* a, grpc_compression_algorithm algorithm) {
51
55
  GPR_ASSERT(algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT);
52
56
  grpc_arg tmp;
@@ -68,7 +72,9 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a,
68
72
  !strcmp(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET,
69
73
  a->args[i].key)) {
70
74
  *states_arg = &a->args[i].value.integer;
71
- **states_arg |= 0x1; /* forcefully enable support for no compression */
75
+ **states_arg =
76
+ (**states_arg & ((1 << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1)) |
77
+ 0x1; /* forcefully enable support for no compression */
72
78
  return 1;
73
79
  }
74
80
  }
@@ -83,7 +89,8 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state(
83
89
  const int states_arg_found =
84
90
  find_compression_algorithm_states_bitset(*a, &states_arg);
85
91
 
86
- if (grpc_channel_args_get_compression_algorithm(*a) == algorithm &&
92
+ if (grpc_channel_args_get_channel_default_compression_algorithm(*a) ==
93
+ algorithm &&
87
94
  state == 0) {
88
95
  const char* algo_name = nullptr;
89
96
  GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name) != 0);
@@ -25,13 +25,14 @@
25
25
  #include <grpc/impl/codegen/grpc_types.h>
26
26
 
27
27
  /** Returns the compression algorithm set in \a a. */
28
- grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
28
+ grpc_compression_algorithm
29
+ grpc_channel_args_get_channel_default_compression_algorithm(
29
30
  const grpc_channel_args* a);
30
31
 
31
32
  /** Returns a channel arg instance with compression enabled. If \a a is
32
33
  * non-NULL, its args are copied. N.B. GRPC_COMPRESS_NONE disables compression
33
34
  * for the channel. */
34
- grpc_channel_args* grpc_channel_args_set_compression_algorithm(
35
+ grpc_channel_args* grpc_channel_args_set_channel_default_compression_algorithm(
35
36
  grpc_channel_args* a, grpc_compression_algorithm algorithm);
36
37
 
37
38
  /** Sets the support for the given compression algorithm. By default, all
@@ -171,7 +171,7 @@ int grpc_compression_algorithm_from_message_stream_compression_algorithm(
171
171
  int grpc_message_compression_algorithm_name(
172
172
  grpc_message_compression_algorithm algorithm, const char** name) {
173
173
  GRPC_API_TRACE(
174
- "grpc_message_compression_algorithm_parse(algorithm=%d, name=%p)", 2,
174
+ "grpc_message_compression_algorithm_name(algorithm=%d, name=%p)", 2,
175
175
  ((int)algorithm, name));
176
176
  switch (algorithm) {
177
177
  case GRPC_MESSAGE_COMPRESS_NONE:
@@ -38,19 +38,20 @@
38
38
  #include "src/core/lib/gpr/string.h"
39
39
  #include "src/core/lib/gpr/useful.h"
40
40
 
41
- static const char* gpr_getenv_silent(const char* name, char** dst) {
42
- const char* insecure_func_used = nullptr;
41
+ char* gpr_getenv(const char* name) {
43
42
  char* result = nullptr;
44
43
  #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
45
44
  typedef char* (*getenv_type)(const char*);
46
- static getenv_type getenv_func = NULL;
45
+ static getenv_type getenv_func = nullptr;
47
46
  /* Check to see which getenv variant is supported (go from most
48
47
  * to least secure) */
49
- const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
50
- for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) {
51
- getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
52
- if (getenv_func != NULL && strstr(names[i], "secure") == NULL) {
53
- insecure_func_used = names[i];
48
+ if (getenv_func == nullptr) {
49
+ const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
50
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) {
51
+ getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
52
+ if (getenv_func != nullptr) {
53
+ break;
54
+ }
54
55
  }
55
56
  }
56
57
  result = getenv_func(name);
@@ -58,20 +59,8 @@ static const char* gpr_getenv_silent(const char* name, char** dst) {
58
59
  result = secure_getenv(name);
59
60
  #else
60
61
  result = getenv(name);
61
- insecure_func_used = "getenv";
62
62
  #endif
63
- *dst = result == nullptr ? result : gpr_strdup(result);
64
- return insecure_func_used;
65
- }
66
-
67
- char* gpr_getenv(const char* name) {
68
- char* result = nullptr;
69
- const char* insecure_func_used = gpr_getenv_silent(name, &result);
70
- if (insecure_func_used != nullptr) {
71
- gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
72
- insecure_func_used);
73
- }
74
- return result;
63
+ return result == nullptr ? result : gpr_strdup(result);
75
64
  }
76
65
 
77
66
  void gpr_setenv(const char* name, const char* value) {
@@ -29,11 +29,6 @@
29
29
  #include <grpc/support/string_util.h>
30
30
  #include "src/core/lib/gpr/string.h"
31
31
 
32
- const char* gpr_getenv_silent(const char* name, char** dst) {
33
- *dst = gpr_getenv(name);
34
- return nullptr;
35
- }
36
-
37
32
  char* gpr_getenv(const char* name) {
38
33
  char* result = getenv(name);
39
34
  return result == nullptr ? result : gpr_strdup(result);
@@ -289,17 +289,22 @@ char* gpr_strvec_flatten(gpr_strvec* sv, size_t* final_length) {
289
289
  return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
290
290
  }
291
291
 
292
- int gpr_stricmp(const char* a, const char* b) {
292
+ int gpr_strincmp(const char* a, const char* b, size_t n) {
293
293
  int ca, cb;
294
294
  do {
295
295
  ca = tolower(*a);
296
296
  cb = tolower(*b);
297
297
  ++a;
298
298
  ++b;
299
- } while (ca == cb && ca && cb);
299
+ --n;
300
+ } while (ca == cb && ca != 0 && cb != 0 && n != 0);
300
301
  return ca - cb;
301
302
  }
302
303
 
304
+ int gpr_stricmp(const char* a, const char* b) {
305
+ return gpr_strincmp(a, b, SIZE_MAX);
306
+ }
307
+
303
308
  static void add_string_to_split(const char* beg, const char* end, char*** strs,
304
309
  size_t* nstrs, size_t* capstrs) {
305
310
  char* out =
@@ -115,6 +115,7 @@ char* gpr_strvec_flatten(gpr_strvec* strs, size_t* total_length);
115
115
  /** Case insensitive string comparison... return <0 if lower(a)<lower(b), ==0 if
116
116
  lower(a)==lower(b), >0 if lower(a)>lower(b) */
117
117
  int gpr_stricmp(const char* a, const char* b);
118
+ int gpr_strincmp(const char* a, const char* b, size_t n);
118
119
 
119
120
  void* gpr_memrchr(const void* s, int c, size_t n);
120
121
 
@@ -29,44 +29,6 @@
29
29
  #include <time.h>
30
30
  #include "src/core/lib/profiling/timers.h"
31
31
 
32
- // For debug of the timer manager crash only.
33
- // TODO (mxyan): remove after bug is fixed.
34
- #ifdef GRPC_DEBUG_TIMER_MANAGER
35
- #include <string.h>
36
- void (*g_grpc_debug_timer_manager_stats)(
37
- int64_t timer_manager_init_count, int64_t timer_manager_shutdown_count,
38
- int64_t fork_count, int64_t timer_wait_err, int64_t timer_cv_value,
39
- int64_t timer_mu_value, int64_t abstime_sec_value,
40
- int64_t abstime_nsec_value, int64_t abs_deadline_sec_value,
41
- int64_t abs_deadline_nsec_value, int64_t now1_sec_value,
42
- int64_t now1_nsec_value, int64_t now2_sec_value, int64_t now2_nsec_value,
43
- int64_t add_result_sec_value, int64_t add_result_nsec_value,
44
- int64_t sub_result_sec_value, int64_t sub_result_nsec_value,
45
- int64_t next_value, int64_t start_time_sec,
46
- int64_t start_time_nsec) = nullptr;
47
- int64_t g_timer_manager_init_count = 0;
48
- int64_t g_timer_manager_shutdown_count = 0;
49
- int64_t g_fork_count = 0;
50
- int64_t g_timer_wait_err = 0;
51
- int64_t g_timer_cv_value = 0;
52
- int64_t g_timer_mu_value = 0;
53
- int64_t g_abstime_sec_value = -1;
54
- int64_t g_abstime_nsec_value = -1;
55
- int64_t g_abs_deadline_sec_value = -1;
56
- int64_t g_abs_deadline_nsec_value = -1;
57
- int64_t g_now1_sec_value = -1;
58
- int64_t g_now1_nsec_value = -1;
59
- int64_t g_now2_sec_value = -1;
60
- int64_t g_now2_nsec_value = -1;
61
- int64_t g_add_result_sec_value = -1;
62
- int64_t g_add_result_nsec_value = -1;
63
- int64_t g_sub_result_sec_value = -1;
64
- int64_t g_sub_result_nsec_value = -1;
65
- int64_t g_next_value = -1;
66
- int64_t g_start_time_sec = -1;
67
- int64_t g_start_time_nsec = -1;
68
- #endif // GRPC_DEBUG_TIMER_MANAGER
69
-
70
32
  #ifdef GPR_LOW_LEVEL_COUNTERS
71
33
  gpr_atm gpr_mu_locks = 0;
72
34
  gpr_atm gpr_counter_atm_cas = 0;
@@ -152,63 +114,12 @@ void gpr_cv_destroy(gpr_cv* cv) {
152
114
  #endif
153
115
  }
154
116
 
155
- // For debug of the timer manager crash only.
156
- // TODO (mxyan): remove after bug is fixed.
157
- #ifdef GRPC_DEBUG_TIMER_MANAGER
158
- static gpr_timespec gpr_convert_clock_type_debug_timespec(
159
- gpr_timespec t, gpr_clock_type clock_type, gpr_timespec& now1,
160
- gpr_timespec& now2, gpr_timespec& add_result, gpr_timespec& sub_result) {
161
- if (t.clock_type == clock_type) {
162
- return t;
163
- }
164
-
165
- if (t.tv_sec == INT64_MAX || t.tv_sec == INT64_MIN) {
166
- t.clock_type = clock_type;
167
- return t;
168
- }
169
-
170
- if (clock_type == GPR_TIMESPAN) {
171
- return gpr_time_sub(t, gpr_now(t.clock_type));
172
- }
173
-
174
- if (t.clock_type == GPR_TIMESPAN) {
175
- return gpr_time_add(gpr_now(clock_type), t);
176
- }
177
-
178
- now1 = gpr_now(t.clock_type);
179
- sub_result = gpr_time_sub(t, now1);
180
- now2 = gpr_now(clock_type);
181
- add_result = gpr_time_add(now2, sub_result);
182
- return add_result;
183
- }
184
-
185
- #define gpr_convert_clock_type_debug(t, clock_type, now1, now2, add_result, \
186
- sub_result) \
187
- gpr_convert_clock_type_debug_timespec((t), (clock_type), (now1), (now2), \
188
- (add_result), (sub_result))
189
- #else
190
117
  #define gpr_convert_clock_type_debug(t, clock_type, now1, now2, add_result, \
191
118
  sub_result) \
192
119
  gpr_convert_clock_type((t), (clock_type))
193
- #endif
194
120
 
195
121
  int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
196
122
  int err = 0;
197
- #ifdef GRPC_DEBUG_TIMER_MANAGER
198
- // For debug of the timer manager crash only.
199
- // TODO (mxyan): remove after bug is fixed.
200
- gpr_timespec abs_deadline_copy;
201
- abs_deadline_copy.tv_sec = abs_deadline.tv_sec;
202
- abs_deadline_copy.tv_nsec = abs_deadline.tv_nsec;
203
- gpr_timespec now1;
204
- gpr_timespec now2;
205
- gpr_timespec add_result;
206
- gpr_timespec sub_result;
207
- memset(&now1, 0, sizeof(now1));
208
- memset(&now2, 0, sizeof(now2));
209
- memset(&add_result, 0, sizeof(add_result));
210
- memset(&sub_result, 0, sizeof(sub_result));
211
- #endif
212
123
  if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) ==
213
124
  0) {
214
125
  #ifdef GRPC_ASAN_ENABLED
@@ -232,47 +143,7 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
232
143
  #else
233
144
  err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
234
145
  #endif
235
-
236
- #ifdef GRPC_DEBUG_TIMER_MANAGER
237
- // For debug of the timer manager crash only.
238
- // TODO (mxyan): remove after bug is fixed.
239
- if (GPR_UNLIKELY(!(err == 0 || err == ETIMEDOUT || err == EAGAIN))) {
240
- g_abstime_sec_value = abs_deadline_ts.tv_sec;
241
- g_abstime_nsec_value = abs_deadline_ts.tv_nsec;
242
- }
243
- #endif
244
146
  }
245
-
246
- #ifdef GRPC_DEBUG_TIMER_MANAGER
247
- // For debug of the timer manager crash only.
248
- // TODO (mxyan): remove after bug is fixed.
249
- if (GPR_UNLIKELY(!(err == 0 || err == ETIMEDOUT || err == EAGAIN))) {
250
- if (g_grpc_debug_timer_manager_stats) {
251
- g_timer_wait_err = err;
252
- g_timer_cv_value = (int64_t)cv;
253
- g_timer_mu_value = (int64_t)mu;
254
- g_abs_deadline_sec_value = abs_deadline_copy.tv_sec;
255
- g_abs_deadline_nsec_value = abs_deadline_copy.tv_nsec;
256
- g_now1_sec_value = now1.tv_sec;
257
- g_now1_nsec_value = now1.tv_nsec;
258
- g_now2_sec_value = now2.tv_sec;
259
- g_now2_nsec_value = now2.tv_nsec;
260
- g_add_result_sec_value = add_result.tv_sec;
261
- g_add_result_nsec_value = add_result.tv_nsec;
262
- g_sub_result_sec_value = sub_result.tv_sec;
263
- g_sub_result_nsec_value = sub_result.tv_nsec;
264
- g_grpc_debug_timer_manager_stats(
265
- g_timer_manager_init_count, g_timer_manager_shutdown_count,
266
- g_fork_count, g_timer_wait_err, g_timer_cv_value, g_timer_mu_value,
267
- g_abstime_sec_value, g_abstime_nsec_value, g_abs_deadline_sec_value,
268
- g_abs_deadline_nsec_value, g_now1_sec_value, g_now1_nsec_value,
269
- g_now2_sec_value, g_now2_nsec_value, g_add_result_sec_value,
270
- g_add_result_nsec_value, g_sub_result_sec_value,
271
- g_sub_result_nsec_value, g_next_value, g_start_time_sec,
272
- g_start_time_nsec);
273
- }
274
- }
275
- #endif
276
147
  GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN);
277
148
  return err == ETIMEDOUT;
278
149
  }