grpc 1.20.0 → 1.21.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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +500 -29
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/grpc_types.h +10 -7
  6. data/include/grpc/impl/codegen/port_platform.h +11 -1
  7. data/include/grpc/impl/codegen/slice.h +1 -21
  8. data/include/grpc/impl/codegen/status.h +2 -1
  9. data/include/grpc/slice.h +1 -1
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
  11. data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
  12. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
  16. data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
  17. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  18. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
  21. data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
  32. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  45. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  46. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
  47. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
  48. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
  50. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
  51. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
  52. data/src/core/ext/filters/client_channel/service_config.cc +247 -27
  53. data/src/core/ext/filters/client_channel/service_config.h +119 -166
  54. data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
  55. data/src/core/ext/filters/client_channel/subchannel.h +7 -7
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  57. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  58. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  59. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  60. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  61. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  62. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  63. data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
  64. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  65. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
  70. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
  71. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
  75. data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
  76. data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
  77. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  78. data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
  79. data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
  80. data/src/core/lib/channel/channel_args.cc +0 -101
  81. data/src/core/lib/channel/channel_args.h +0 -37
  82. data/src/core/lib/channel/channel_stack.h +9 -5
  83. data/src/core/lib/channel/channelz_registry.cc +1 -1
  84. data/src/core/lib/channel/connected_channel.cc +2 -2
  85. data/src/core/lib/channel/context.h +3 -0
  86. data/src/core/lib/channel/handshaker.cc +4 -4
  87. data/src/core/lib/channel/handshaker.h +1 -1
  88. data/src/core/lib/compression/compression_args.cc +127 -0
  89. data/src/core/lib/compression/compression_args.h +55 -0
  90. data/src/core/lib/debug/trace.cc +13 -7
  91. data/src/core/lib/debug/trace.h +12 -0
  92. data/src/core/lib/gpr/arena.h +13 -9
  93. data/src/core/lib/gpr/env.h +2 -5
  94. data/src/core/lib/gpr/env_linux.cc +6 -1
  95. data/src/core/lib/gpr/env_posix.cc +5 -0
  96. data/src/core/lib/gpr/env_windows.cc +7 -5
  97. data/src/core/lib/gpr/log.cc +9 -13
  98. data/src/core/lib/gpr/string.cc +12 -6
  99. data/src/core/lib/gpr/string.h +4 -2
  100. data/src/core/lib/gpr/time_posix.cc +13 -0
  101. data/src/core/lib/gprpp/arena.cc +103 -0
  102. data/src/core/lib/gprpp/arena.h +121 -0
  103. data/src/core/lib/gprpp/fork.cc +12 -29
  104. data/src/core/lib/gprpp/global_config.h +87 -0
  105. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  106. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  107. data/src/core/lib/gprpp/global_config_env.h +131 -0
  108. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  109. data/src/core/lib/gprpp/map.h +419 -0
  110. data/src/core/lib/gprpp/optional.h +1 -0
  111. data/src/core/lib/gprpp/orphanable.h +2 -2
  112. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  113. data/src/core/lib/gprpp/ref_counted.h +18 -2
  114. data/src/core/lib/gprpp/sync.h +126 -0
  115. data/src/core/lib/http/parser.cc +1 -1
  116. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  117. data/src/core/lib/iomgr/call_combiner.h +75 -82
  118. data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
  119. data/src/core/lib/iomgr/cfstream_handle.h +82 -0
  120. data/src/core/lib/iomgr/combiner.h +1 -1
  121. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  122. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  123. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  124. data/src/core/lib/iomgr/error.h +23 -0
  125. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  126. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  127. data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
  128. data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
  129. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
  130. data/src/core/lib/iomgr/ev_posix.cc +15 -13
  131. data/src/core/lib/iomgr/ev_posix.h +4 -1
  132. data/src/core/lib/iomgr/executor.cc +13 -9
  133. data/src/core/lib/iomgr/fork_posix.cc +0 -1
  134. data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
  135. data/src/core/lib/iomgr/iomgr.cc +6 -5
  136. data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
  137. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  138. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  139. data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
  140. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  141. data/src/core/lib/iomgr/port.h +11 -0
  142. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  143. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  144. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  145. data/src/core/lib/iomgr/socket_windows.h +8 -0
  146. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  147. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  148. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  149. data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
  150. data/src/core/lib/iomgr/tcp_custom.cc +9 -9
  151. data/src/core/lib/iomgr/tcp_posix.cc +41 -41
  152. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
  153. data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
  154. data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
  155. data/src/core/lib/iomgr/tcp_windows.cc +7 -9
  156. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  157. data/src/core/lib/iomgr/timer_manager.cc +12 -11
  158. data/src/core/lib/profiling/basic_timers.cc +10 -4
  159. data/src/core/lib/security/context/security_context.cc +6 -7
  160. data/src/core/lib/security/context/security_context.h +3 -4
  161. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
  162. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
  163. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  164. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
  165. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  166. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  167. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
  168. data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
  169. data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
  170. data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
  171. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  172. data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
  173. data/src/core/lib/slice/slice.cc +99 -116
  174. data/src/core/lib/slice/slice_buffer.cc +5 -0
  175. data/src/core/lib/slice/slice_intern.cc +38 -95
  176. data/src/core/lib/slice/slice_internal.h +200 -2
  177. data/src/core/lib/surface/api_trace.h +1 -1
  178. data/src/core/lib/surface/call.cc +41 -35
  179. data/src/core/lib/surface/call.h +7 -2
  180. data/src/core/lib/surface/call_details.cc +0 -1
  181. data/src/core/lib/surface/completion_queue.cc +36 -27
  182. data/src/core/lib/surface/init.cc +3 -4
  183. data/src/core/lib/surface/lame_client.cc +1 -1
  184. data/src/core/lib/surface/server.cc +18 -25
  185. data/src/core/lib/surface/version.cc +1 -1
  186. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  187. data/src/core/lib/transport/bdp_estimator.h +2 -2
  188. data/src/core/lib/transport/connectivity_state.cc +10 -40
  189. data/src/core/lib/transport/connectivity_state.h +0 -8
  190. data/src/core/lib/transport/error_utils.cc +12 -0
  191. data/src/core/lib/transport/metadata.cc +206 -278
  192. data/src/core/lib/transport/metadata.h +205 -10
  193. data/src/core/lib/transport/static_metadata.cc +108 -116
  194. data/src/core/lib/transport/static_metadata.h +1 -2
  195. data/src/core/lib/transport/status_metadata.cc +3 -3
  196. data/src/core/lib/transport/transport.cc +29 -66
  197. data/src/core/lib/transport/transport.h +36 -8
  198. data/src/core/lib/transport/transport_impl.h +1 -1
  199. data/src/core/tsi/fake_transport_security.cc +4 -4
  200. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  201. data/src/core/tsi/ssl_transport_security.cc +1 -1
  202. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  203. data/src/ruby/lib/grpc/errors.rb +22 -3
  204. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  205. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  206. data/src/ruby/lib/grpc/version.rb +1 -1
  207. data/src/ruby/spec/errors_spec.rb +141 -0
  208. metadata +57 -33
  209. data/src/core/lib/gpr/arena.cc +0 -192
@@ -0,0 +1,55 @@
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_CORE_LIB_COMPRESSION_COMPRESSION_ARGS_H
20
+ #define GRPC_CORE_LIB_COMPRESSION_COMPRESSION_ARGS_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <grpc/compression.h>
25
+ #include <grpc/impl/codegen/grpc_types.h>
26
+
27
+ /** Returns the compression algorithm set in \a a. */
28
+ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
29
+ const grpc_channel_args* a);
30
+
31
+ /** Returns a channel arg instance with compression enabled. If \a a is
32
+ * non-NULL, its args are copied. N.B. GRPC_COMPRESS_NONE disables compression
33
+ * for the channel. */
34
+ grpc_channel_args* grpc_channel_args_set_compression_algorithm(
35
+ grpc_channel_args* a, grpc_compression_algorithm algorithm);
36
+
37
+ /** Sets the support for the given compression algorithm. By default, all
38
+ * compression algorithms are enabled. It's an error to disable an algorithm set
39
+ * by grpc_channel_args_set_compression_algorithm.
40
+ *
41
+ * Returns an instance with the updated algorithm states. The \a a pointer is
42
+ * modified to point to the returned instance (which may be different from the
43
+ * input value of \a a). */
44
+ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state(
45
+ grpc_channel_args** a, grpc_compression_algorithm algorithm, int state);
46
+
47
+ /** Returns the bitset representing the support state (true for enabled, false
48
+ * for disabled) for compression algorithms.
49
+ *
50
+ * The i-th bit of the returned bitset corresponds to the i-th entry in the
51
+ * grpc_compression_algorithm enum. */
52
+ uint32_t grpc_channel_args_compression_algorithm_get_states(
53
+ const grpc_channel_args* a);
54
+
55
+ #endif /* GRPC_CORE_LIB_COMPRESSION_COMPRESSION_ARGS_H */
@@ -26,7 +26,11 @@
26
26
  #include <grpc/grpc.h>
27
27
  #include <grpc/support/alloc.h>
28
28
  #include <grpc/support/log.h>
29
- #include "src/core/lib/gpr/env.h"
29
+
30
+ GPR_GLOBAL_CONFIG_DEFINE_STRING(
31
+ grpc_trace, "",
32
+ "A comma separated list of tracers that provide additional insight into "
33
+ "how gRPC C core is processing requests via debug logs.");
30
34
 
31
35
  int grpc_tracer_set_enabled(const char* name, int enabled);
32
36
 
@@ -133,12 +137,14 @@ static void parse(const char* s) {
133
137
  gpr_free(strings);
134
138
  }
135
139
 
136
- void grpc_tracer_init(const char* env_var) {
137
- char* e = gpr_getenv(env_var);
138
- if (e != nullptr) {
139
- parse(e);
140
- gpr_free(e);
141
- }
140
+ void grpc_tracer_init(const char* env_var_name) {
141
+ (void)env_var_name; // suppress unused variable error
142
+ grpc_tracer_init();
143
+ }
144
+
145
+ void grpc_tracer_init() {
146
+ grpc_core::UniquePtr<char> value = GPR_GLOBAL_CONFIG_GET(grpc_trace);
147
+ parse(value.get());
142
148
  }
143
149
 
144
150
  void grpc_tracer_shutdown(void) {}
@@ -24,7 +24,15 @@
24
24
  #include <grpc/support/atm.h>
25
25
  #include <stdbool.h>
26
26
 
27
+ #include "src/core/lib/gprpp/global_config.h"
28
+
29
+ GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_trace);
30
+
31
+ // TODO(veblush): Remove this deprecated function once codes depending on this
32
+ // function are updated in the internal repo.
27
33
  void grpc_tracer_init(const char* env_var_name);
34
+
35
+ void grpc_tracer_init();
28
36
  void grpc_tracer_shutdown(void);
29
37
 
30
38
  #if defined(__has_feature)
@@ -65,6 +73,8 @@ class TraceFlag {
65
73
  // wrapped language (wr don't want to force recompilation to get tracing).
66
74
  // Internally, however, for performance reasons, we compile them out by
67
75
  // default, since internal build systems make recompiling trivial.
76
+ //
77
+ // Prefer GRPC_TRACE_FLAG_ENABLED() macro instead of using enabled() directly.
68
78
  #define GRPC_USE_TRACERS // tracers on by default in OSS
69
79
  #if defined(GRPC_USE_TRACERS) || !defined(NDEBUG)
70
80
  bool enabled() {
@@ -99,6 +109,8 @@ class TraceFlag {
99
109
  #endif
100
110
  };
101
111
 
112
+ #define GRPC_TRACE_FLAG_ENABLED(f) GPR_UNLIKELY((f).enabled())
113
+
102
114
  #ifndef NDEBUG
103
115
  typedef TraceFlag DebugOnlyTraceFlag;
104
116
  #else
@@ -21,23 +21,27 @@
21
21
  // the arena as a whole is freed
22
22
  // Tracks the total memory allocated against it, so that future arenas can
23
23
  // pre-allocate the right amount of memory
24
+ // This transitional API is deprecated and will be removed soon in favour of
25
+ // src/core/lib/gprpp/arena.h .
24
26
 
25
27
  #ifndef GRPC_CORE_LIB_GPR_ARENA_H
26
28
  #define GRPC_CORE_LIB_GPR_ARENA_H
27
29
 
28
30
  #include <grpc/support/port_platform.h>
29
31
 
30
- #include <stddef.h>
31
-
32
- typedef struct gpr_arena gpr_arena;
32
+ #include "src/core/lib/gprpp/arena.h"
33
33
 
34
+ // TODO(arjunroy) : Remove deprecated gpr_arena API once all callers are gone.
35
+ typedef class grpc_core::Arena gpr_arena;
34
36
  // Create an arena, with \a initial_size bytes in the first allocated buffer
35
- gpr_arena* gpr_arena_create(size_t initial_size);
36
- // Allocate \a size bytes from the arena
37
- void* gpr_arena_alloc(gpr_arena* arena, size_t size);
37
+ inline gpr_arena* gpr_arena_create(size_t initial_size) {
38
+ return grpc_core::Arena::Create(initial_size);
39
+ }
38
40
  // Destroy an arena, returning the total number of bytes allocated
39
- size_t gpr_arena_destroy(gpr_arena* arena);
40
- // Initializes the Arena component.
41
- void gpr_arena_init();
41
+ inline size_t gpr_arena_destroy(gpr_arena* arena) { return arena->Destroy(); }
42
+ // Allocate \a size bytes from the arena
43
+ inline void* gpr_arena_alloc(gpr_arena* arena, size_t size) {
44
+ return arena->Alloc(size);
45
+ }
42
46
 
43
47
  #endif /* GRPC_CORE_LIB_GPR_ARENA_H */
@@ -34,10 +34,7 @@ char* gpr_getenv(const char* name);
34
34
  /* Sets the environment with the specified name to the specified value. */
35
35
  void gpr_setenv(const char* name, const char* value);
36
36
 
37
- /* This is a version of gpr_getenv that does not produce any output if it has to
38
- use an insecure version of the function. It is ONLY to be used to solve the
39
- problem in which we need to check an env variable to configure the verbosity
40
- level of logging. So DO NOT USE THIS. */
41
- const char* gpr_getenv_silent(const char* name, char** dst);
37
+ /* Deletes the variable name from the environment. */
38
+ void gpr_unsetenv(const char* name);
42
39
 
43
40
  #endif /* GRPC_CORE_LIB_GPR_ENV_H */
@@ -38,7 +38,7 @@
38
38
  #include "src/core/lib/gpr/string.h"
39
39
  #include "src/core/lib/gpr/useful.h"
40
40
 
41
- const char* gpr_getenv_silent(const char* name, char** dst) {
41
+ static const char* gpr_getenv_silent(const char* name, char** dst) {
42
42
  const char* insecure_func_used = nullptr;
43
43
  char* result = nullptr;
44
44
  #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
@@ -79,4 +79,9 @@ void gpr_setenv(const char* name, const char* value) {
79
79
  GPR_ASSERT(res == 0);
80
80
  }
81
81
 
82
+ void gpr_unsetenv(const char* name) {
83
+ int res = unsetenv(name);
84
+ GPR_ASSERT(res == 0);
85
+ }
86
+
82
87
  #endif /* GPR_LINUX_ENV */
@@ -44,4 +44,9 @@ void gpr_setenv(const char* name, const char* value) {
44
44
  GPR_ASSERT(res == 0);
45
45
  }
46
46
 
47
+ void gpr_unsetenv(const char* name) {
48
+ int res = unsetenv(name);
49
+ GPR_ASSERT(res == 0);
50
+ }
51
+
47
52
  #endif /* GPR_POSIX_ENV */
@@ -30,11 +30,6 @@
30
30
  #include "src/core/lib/gpr/string.h"
31
31
  #include "src/core/lib/gpr/string_windows.h"
32
32
 
33
- const char* gpr_getenv_silent(const char* name, char** dst) {
34
- *dst = gpr_getenv(name);
35
- return NULL;
36
- }
37
-
38
33
  char* gpr_getenv(const char* name) {
39
34
  char* result = NULL;
40
35
  DWORD size;
@@ -69,4 +64,11 @@ void gpr_setenv(const char* name, const char* value) {
69
64
  GPR_ASSERT(res);
70
65
  }
71
66
 
67
+ void gpr_unsetenv(const char* name) {
68
+ LPTSTR tname = gpr_char_to_tchar(name);
69
+ BOOL res = SetEnvironmentVariable(tname, NULL);
70
+ gpr_free(tname);
71
+ GPR_ASSERT(res);
72
+ }
73
+
72
74
  #endif /* GPR_WINDOWS_ENV */
@@ -22,12 +22,15 @@
22
22
  #include <grpc/support/atm.h>
23
23
  #include <grpc/support/log.h>
24
24
 
25
- #include "src/core/lib/gpr/env.h"
26
25
  #include "src/core/lib/gpr/string.h"
26
+ #include "src/core/lib/gprpp/global_config.h"
27
27
 
28
28
  #include <stdio.h>
29
29
  #include <string.h>
30
30
 
31
+ GPR_GLOBAL_CONFIG_DEFINE_STRING(grpc_verbosity, "ERROR",
32
+ "Default gRPC logging verbosity")
33
+
31
34
  void gpr_default_log(gpr_log_func_args* args);
32
35
  static gpr_atm g_log_func = (gpr_atm)gpr_default_log;
33
36
  static gpr_atm g_min_severity_to_print = GPR_LOG_VERBOSITY_UNSET;
@@ -72,29 +75,22 @@ void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) {
72
75
  }
73
76
 
74
77
  void gpr_log_verbosity_init() {
75
- char* verbosity = nullptr;
76
- const char* insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity);
78
+ grpc_core::UniquePtr<char> verbosity = GPR_GLOBAL_CONFIG_GET(grpc_verbosity);
77
79
 
78
80
  gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR;
79
- if (verbosity != nullptr) {
80
- if (gpr_stricmp(verbosity, "DEBUG") == 0) {
81
+ if (strlen(verbosity.get()) > 0) {
82
+ if (gpr_stricmp(verbosity.get(), "DEBUG") == 0) {
81
83
  min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_DEBUG);
82
- } else if (gpr_stricmp(verbosity, "INFO") == 0) {
84
+ } else if (gpr_stricmp(verbosity.get(), "INFO") == 0) {
83
85
  min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_INFO);
84
- } else if (gpr_stricmp(verbosity, "ERROR") == 0) {
86
+ } else if (gpr_stricmp(verbosity.get(), "ERROR") == 0) {
85
87
  min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_ERROR);
86
88
  }
87
- gpr_free(verbosity);
88
89
  }
89
90
  if ((gpr_atm_no_barrier_load(&g_min_severity_to_print)) ==
90
91
  GPR_LOG_VERBOSITY_UNSET) {
91
92
  gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print);
92
93
  }
93
-
94
- if (insecure_getenv != nullptr) {
95
- gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
96
- insecure_getenv);
97
- }
98
94
  }
99
95
 
100
96
  void gpr_set_log_function(gpr_log_func f) {
@@ -332,16 +332,22 @@ void* gpr_memrchr(const void* s, int c, size_t n) {
332
332
  return nullptr;
333
333
  }
334
334
 
335
- bool gpr_is_true(const char* s) {
336
- size_t i;
335
+ bool gpr_parse_bool_value(const char* s, bool* dst) {
336
+ const char* kTrue[] = {"1", "t", "true", "y", "yes"};
337
+ const char* kFalse[] = {"0", "f", "false", "n", "no"};
338
+ static_assert(sizeof(kTrue) == sizeof(kFalse), "true_false_equal");
339
+
337
340
  if (s == nullptr) {
338
341
  return false;
339
342
  }
340
- static const char* truthy[] = {"yes", "true", "1"};
341
- for (i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
342
- if (0 == gpr_stricmp(s, truthy[i])) {
343
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(kTrue); ++i) {
344
+ if (gpr_stricmp(s, kTrue[i]) == 0) {
345
+ *dst = true;
346
+ return true;
347
+ } else if (gpr_stricmp(s, kFalse[i]) == 0) {
348
+ *dst = false;
343
349
  return true;
344
350
  }
345
351
  }
346
- return false;
352
+ return false; // didn't match a legal input
347
353
  }
@@ -113,7 +113,9 @@ int gpr_stricmp(const char* a, const char* b);
113
113
 
114
114
  void* gpr_memrchr(const void* s, int c, size_t n);
115
115
 
116
- /** Return true if lower(s) equals "true", "yes" or "1", otherwise false. */
117
- bool gpr_is_true(const char* s);
116
+ /* Try to parse given string into a boolean value.
117
+ When parsed successfully, dst will have the value and returns true.
118
+ Otherwise, it returns false. */
119
+ bool gpr_parse_bool_value(const char* value, bool* dst);
118
120
 
119
121
  #endif /* GRPC_CORE_LIB_GPR_STRING_H */
@@ -108,6 +108,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
108
108
  now.clock_type = clock;
109
109
  switch (clock) {
110
110
  case GPR_CLOCK_REALTIME:
111
+ // gettimeofday(...) function may return with a value whose tv_usec is
112
+ // greater than 1e6 on iOS The case is resolved with the guard at end of
113
+ // this function.
111
114
  gettimeofday(&now_tv, nullptr);
112
115
  now.tv_sec = now_tv.tv_sec;
113
116
  now.tv_nsec = now_tv.tv_usec * 1000;
@@ -124,6 +127,16 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
124
127
  abort();
125
128
  }
126
129
 
130
+ // Guard the tv_nsec field in valid range for all clock types
131
+ while (GPR_UNLIKELY(now.tv_nsec >= 1e9)) {
132
+ now.tv_sec++;
133
+ now.tv_nsec -= 1e9;
134
+ }
135
+ while (GPR_UNLIKELY(now.tv_nsec < 0)) {
136
+ now.tv_sec--;
137
+ now.tv_nsec += 1e9;
138
+ }
139
+
127
140
  return now;
128
141
  }
129
142
  #endif
@@ -0,0 +1,103 @@
1
+ /*
2
+ *
3
+ * Copyright 2017 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 <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/lib/gprpp/arena.h"
22
+
23
+ #include <string.h>
24
+ #include <new>
25
+
26
+ #include <grpc/support/alloc.h>
27
+ #include <grpc/support/atm.h>
28
+ #include <grpc/support/log.h>
29
+ #include <grpc/support/sync.h>
30
+
31
+ #include "src/core/lib/gpr/alloc.h"
32
+ #include "src/core/lib/gprpp/memory.h"
33
+
34
+ namespace {
35
+
36
+ void* ArenaStorage(size_t initial_size) {
37
+ static constexpr size_t base_size =
38
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_core::Arena));
39
+ initial_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(initial_size);
40
+ size_t alloc_size = base_size + initial_size;
41
+ static constexpr size_t alignment =
42
+ (GPR_CACHELINE_SIZE > GPR_MAX_ALIGNMENT &&
43
+ GPR_CACHELINE_SIZE % GPR_MAX_ALIGNMENT == 0)
44
+ ? GPR_CACHELINE_SIZE
45
+ : GPR_MAX_ALIGNMENT;
46
+ return gpr_malloc_aligned(alloc_size, alignment);
47
+ }
48
+
49
+ } // namespace
50
+
51
+ namespace grpc_core {
52
+
53
+ Arena::~Arena() {
54
+ Zone* z = last_zone_;
55
+ while (z) {
56
+ Zone* prev_z = z->prev;
57
+ z->~Zone();
58
+ gpr_free_aligned(z);
59
+ z = prev_z;
60
+ }
61
+ }
62
+
63
+ Arena* Arena::Create(size_t initial_size) {
64
+ return new (ArenaStorage(initial_size)) Arena(initial_size);
65
+ }
66
+
67
+ Pair<Arena*, void*> Arena::CreateWithAlloc(size_t initial_size,
68
+ size_t alloc_size) {
69
+ static constexpr size_t base_size =
70
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena));
71
+ auto* new_arena =
72
+ new (ArenaStorage(initial_size)) Arena(initial_size, alloc_size);
73
+ void* first_alloc = reinterpret_cast<char*>(new_arena) + base_size;
74
+ return MakePair(new_arena, first_alloc);
75
+ }
76
+
77
+ size_t Arena::Destroy() {
78
+ size_t size = total_used_.Load(MemoryOrder::RELAXED);
79
+ this->~Arena();
80
+ gpr_free_aligned(this);
81
+ return size;
82
+ }
83
+
84
+ void* Arena::AllocZone(size_t size) {
85
+ // If the allocation isn't able to end in the initial zone, create a new
86
+ // zone for this allocation, and any unused space in the initial zone is
87
+ // wasted. This overflowing and wasting is uncommon because of our arena
88
+ // sizing hysteresis (that is, most calls should have a large enough initial
89
+ // zone and will not need to grow the arena).
90
+ static constexpr size_t zone_base_size =
91
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Zone));
92
+ size_t alloc_size = zone_base_size + size;
93
+ Zone* z = new (gpr_malloc_aligned(alloc_size, GPR_MAX_ALIGNMENT)) Zone();
94
+ {
95
+ gpr_spinlock_lock(&arena_growth_spinlock_);
96
+ z->prev = last_zone_;
97
+ last_zone_ = z;
98
+ gpr_spinlock_unlock(&arena_growth_spinlock_);
99
+ }
100
+ return reinterpret_cast<char*>(z) + zone_base_size;
101
+ }
102
+
103
+ } // namespace grpc_core