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,121 @@
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
+ // \file Arena based allocator
20
+ // Allows very fast allocation of memory, but that memory cannot be freed until
21
+ // the arena as a whole is freed
22
+ // Tracks the total memory allocated against it, so that future arenas can
23
+ // pre-allocate the right amount of memory
24
+
25
+ #ifndef GRPC_CORE_LIB_GPRPP_ARENA_H
26
+ #define GRPC_CORE_LIB_GPRPP_ARENA_H
27
+
28
+ #include <grpc/support/port_platform.h>
29
+
30
+ #include <new>
31
+ #include <utility>
32
+
33
+ #include <grpc/support/alloc.h>
34
+ #include <grpc/support/sync.h>
35
+
36
+ #include "src/core/lib/gpr/alloc.h"
37
+ #include "src/core/lib/gpr/spinlock.h"
38
+ #include "src/core/lib/gprpp/atomic.h"
39
+ #include "src/core/lib/gprpp/pair.h"
40
+
41
+ #include <stddef.h>
42
+
43
+ namespace grpc_core {
44
+
45
+ class Arena {
46
+ public:
47
+ // Create an arena, with \a initial_size bytes in the first allocated buffer.
48
+ static Arena* Create(size_t initial_size);
49
+
50
+ // Create an arena, with \a initial_size bytes in the first allocated buffer,
51
+ // and return both a void pointer to the returned arena and a void* with the
52
+ // first allocation.
53
+ static Pair<Arena*, void*> CreateWithAlloc(size_t initial_size,
54
+ size_t alloc_size);
55
+
56
+ // Destroy an arena, returning the total number of bytes allocated.
57
+ size_t Destroy();
58
+ // Allocate \a size bytes from the arena.
59
+ void* Alloc(size_t size) {
60
+ static constexpr size_t base_size =
61
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena));
62
+ size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(size);
63
+ size_t begin = total_used_.FetchAdd(size, MemoryOrder::RELAXED);
64
+ if (begin + size <= initial_zone_size_) {
65
+ return reinterpret_cast<char*>(this) + base_size + begin;
66
+ } else {
67
+ return AllocZone(size);
68
+ }
69
+ }
70
+
71
+ // TODO(roth): We currently assume that all callers need alignment of 16
72
+ // bytes, which may be wrong in some cases. When we have time, we should
73
+ // change this to instead use the alignment of the type being allocated by
74
+ // this method.
75
+ template <typename T, typename... Args>
76
+ T* New(Args&&... args) {
77
+ T* t = static_cast<T*>(Alloc(sizeof(T)));
78
+ new (t) T(std::forward<Args>(args)...);
79
+ return t;
80
+ }
81
+
82
+ private:
83
+ struct Zone {
84
+ Zone* prev;
85
+ };
86
+
87
+ // Initialize an arena.
88
+ // Parameters:
89
+ // initial_size: The initial size of the whole arena in bytes. These bytes
90
+ // are contained within 'zone 0'. If the arena user ends up requiring more
91
+ // memory than the arena contains in zone 0, subsequent zones are allocated
92
+ // on demand and maintained in a tail-linked list.
93
+ //
94
+ // initial_alloc: Optionally, construct the arena as though a call to
95
+ // Alloc() had already been made for initial_alloc bytes. This provides a
96
+ // quick optimization (avoiding an atomic fetch-add) for the common case
97
+ // where we wish to create an arena and then perform an immediate
98
+ // allocation.
99
+ explicit Arena(size_t initial_size, size_t initial_alloc = 0)
100
+ : total_used_(initial_alloc), initial_zone_size_(initial_size) {}
101
+
102
+ ~Arena();
103
+
104
+ void* AllocZone(size_t size);
105
+
106
+ // Keep track of the total used size. We use this in our call sizing
107
+ // hysteresis.
108
+ Atomic<size_t> total_used_;
109
+ size_t initial_zone_size_;
110
+ gpr_spinlock arena_growth_spinlock_ = GPR_SPINLOCK_STATIC_INITIALIZER;
111
+ // If the initial arena allocation wasn't enough, we allocate additional zones
112
+ // in a reverse linked list. Each additional zone consists of (1) a pointer to
113
+ // the zone added before this zone (null if this is the first additional zone)
114
+ // and (2) the allocated memory. The arena itself maintains a pointer to the
115
+ // last zone; the zone list is reverse-walked during arena destruction only.
116
+ Zone* last_zone_ = nullptr;
117
+ };
118
+
119
+ } // namespace grpc_core
120
+
121
+ #endif /* GRPC_CORE_LIB_GPRPP_ARENA_H */
@@ -26,8 +26,8 @@
26
26
  #include <grpc/support/sync.h>
27
27
  #include <grpc/support/time.h>
28
28
 
29
- #include "src/core/lib/gpr/env.h"
30
29
  #include "src/core/lib/gpr/useful.h"
30
+ #include "src/core/lib/gprpp/global_config.h"
31
31
  #include "src/core/lib/gprpp/memory.h"
32
32
 
33
33
  /*
@@ -35,6 +35,16 @@
35
35
  * AROUND VERY SPECIFIC USE CASES.
36
36
  */
37
37
 
38
+ #ifdef GRPC_ENABLE_FORK_SUPPORT
39
+ #define GRPC_ENABLE_FORK_SUPPORT_DEFAULT true
40
+ #else
41
+ #define GRPC_ENABLE_FORK_SUPPORT_DEFAULT false
42
+ #endif // GRPC_ENABLE_FORK_SUPPORT
43
+
44
+ GPR_GLOBAL_CONFIG_DEFINE_BOOL(grpc_enable_fork_support,
45
+ GRPC_ENABLE_FORK_SUPPORT_DEFAULT,
46
+ "Enable folk support");
47
+
38
48
  namespace grpc_core {
39
49
  namespace internal {
40
50
  // The exec_ctx_count has 2 modes, blocked and unblocked.
@@ -158,34 +168,7 @@ class ThreadState {
158
168
 
159
169
  void Fork::GlobalInit() {
160
170
  if (!override_enabled_) {
161
- #ifdef GRPC_ENABLE_FORK_SUPPORT
162
- support_enabled_ = true;
163
- #endif
164
- bool env_var_set = false;
165
- char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
166
- if (env != nullptr) {
167
- static const char* truthy[] = {"yes", "Yes", "YES", "true",
168
- "True", "TRUE", "1"};
169
- static const char* falsey[] = {"no", "No", "NO", "false",
170
- "False", "FALSE", "0"};
171
- for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
172
- if (0 == strcmp(env, truthy[i])) {
173
- support_enabled_ = true;
174
- env_var_set = true;
175
- break;
176
- }
177
- }
178
- if (!env_var_set) {
179
- for (size_t i = 0; i < GPR_ARRAY_SIZE(falsey); i++) {
180
- if (0 == strcmp(env, falsey[i])) {
181
- support_enabled_ = false;
182
- env_var_set = true;
183
- break;
184
- }
185
- }
186
- }
187
- gpr_free(env);
188
- }
171
+ support_enabled_ = GPR_GLOBAL_CONFIG_GET(grpc_enable_fork_support);
189
172
  }
190
173
  if (support_enabled_) {
191
174
  exec_ctx_state_ = grpc_core::New<internal::ExecCtxState>();
@@ -0,0 +1,87 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H
20
+ #define GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <stdint.h>
25
+
26
+ // --------------------------------------------------------------------
27
+ // How to use global configuration variables:
28
+ //
29
+ // Defining config variables of a specified type:
30
+ // GPR_GLOBAL_CONFIG_DEFINE_*TYPE*(name, default_value, help);
31
+ //
32
+ // Supported TYPEs: BOOL, INT32, STRING
33
+ //
34
+ // It's recommended to use lowercase letters for 'name' like
35
+ // regular variables. The builtin configuration system uses
36
+ // environment variable and the name is converted to uppercase
37
+ // when looking up the value. For example,
38
+ // GPR_GLOBAL_CONFIG_DEFINE(grpc_latency) looks up the value with the
39
+ // name, "GRPC_LATENCY".
40
+ //
41
+ // The variable initially has the specified 'default_value'
42
+ // which must be an expression convertible to 'Type'.
43
+ // 'default_value' may be evaluated 0 or more times,
44
+ // and at an unspecified time; keep it
45
+ // simple and usually free of side-effects.
46
+ //
47
+ // GPR_GLOBAL_CONFIG_DEFINE_*TYPE* should not be called in a C++ header.
48
+ // It should be called at the top-level (outside any namespaces)
49
+ // in a .cc file.
50
+ //
51
+ // Getting the variables:
52
+ // GPR_GLOBAL_CONFIG_GET(name)
53
+ //
54
+ // If error happens during getting variables, error messages will
55
+ // be logged and default value will be returned.
56
+ //
57
+ // Setting the variables with new value:
58
+ // GPR_GLOBAL_CONFIG_SET(name, new_value)
59
+ //
60
+ // Declaring config variables for other modules to access:
61
+ // GPR_GLOBAL_CONFIG_DECLARE_*TYPE*(name)
62
+
63
+ // --------------------------------------------------------------------
64
+ // How to customize the global configuration system:
65
+ //
66
+ // How to read and write configuration value can be customized.
67
+ // Builtin system uses environment variables but it can be extended to
68
+ // support command-line flag, file, etc.
69
+ //
70
+ // To customize it, following macros should be redefined.
71
+ //
72
+ // GPR_GLOBAL_CONFIG_DEFINE_BOOL
73
+ // GPR_GLOBAL_CONFIG_DEFINE_INT32
74
+ // GPR_GLOBAL_CONFIG_DEFINE_STRING
75
+ //
76
+ // These macros should define functions for getting and setting variable.
77
+ // For example, GPR_GLOBAL_CONFIG_DEFINE_BOOL(test, ...) would define two
78
+ // functions.
79
+ //
80
+ // bool gpr_global_config_get_test();
81
+ // void gpr_global_config_set_test(bool value);
82
+
83
+ #include "src/core/lib/gprpp/global_config_env.h"
84
+
85
+ #include "src/core/lib/gprpp/global_config_custom.h"
86
+
87
+ #endif /* GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H */
@@ -0,0 +1,29 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H
20
+ #define GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H
21
+
22
+ // This is a placeholder for custom global configuration implementaion.
23
+ // To use the custom one, please define following macros here.
24
+ //
25
+ // GPR_GLOBAL_CONFIG_DEFINE_BOOL
26
+ // GPR_GLOBAL_CONFIG_DEFINE_INT32
27
+ // GPR_GLOBAL_CONFIG_DEFINE_STRING
28
+
29
+ #endif /* GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H */
@@ -0,0 +1,135 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/lib/gprpp/global_config_env.h"
22
+
23
+ #include <grpc/support/alloc.h>
24
+ #include <grpc/support/log.h>
25
+ #include <grpc/support/string_util.h>
26
+
27
+ #include "src/core/lib/gpr/env.h"
28
+ #include "src/core/lib/gpr/string.h"
29
+
30
+ #include <ctype.h>
31
+ #include <string.h>
32
+
33
+ namespace grpc_core {
34
+
35
+ namespace {
36
+
37
+ void DefaultGlobalConfigEnvErrorFunction(const char* error_message) {
38
+ gpr_log(GPR_ERROR, "%s", error_message);
39
+ }
40
+
41
+ GlobalConfigEnvErrorFunctionType g_global_config_env_error_func =
42
+ DefaultGlobalConfigEnvErrorFunction;
43
+
44
+ void LogParsingError(const char* name, const char* value) {
45
+ char* error_message;
46
+ gpr_asprintf(&error_message,
47
+ "Illegal value '%s' specified for environment variable '%s'",
48
+ value, name);
49
+ (*g_global_config_env_error_func)(error_message);
50
+ gpr_free(error_message);
51
+ }
52
+
53
+ } // namespace
54
+
55
+ void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func) {
56
+ g_global_config_env_error_func = func;
57
+ }
58
+
59
+ UniquePtr<char> GlobalConfigEnv::GetValue() {
60
+ return UniquePtr<char>(gpr_getenv(GetName()));
61
+ }
62
+
63
+ void GlobalConfigEnv::SetValue(const char* value) {
64
+ gpr_setenv(GetName(), value);
65
+ }
66
+
67
+ void GlobalConfigEnv::Unset() { gpr_unsetenv(GetName()); }
68
+
69
+ char* GlobalConfigEnv::GetName() {
70
+ // This makes sure that name_ is in a canonical form having uppercase
71
+ // letters. This is okay to be called serveral times.
72
+ for (char* c = name_; *c != 0; ++c) {
73
+ *c = toupper(*c);
74
+ }
75
+ return name_;
76
+ }
77
+ static_assert(std::is_trivially_destructible<GlobalConfigEnvBool>::value,
78
+ "GlobalConfigEnvBool needs to be trivially destructible.");
79
+
80
+ bool GlobalConfigEnvBool::Get() {
81
+ UniquePtr<char> str = GetValue();
82
+ if (str == nullptr) {
83
+ return default_value_;
84
+ }
85
+ // parsing given value string.
86
+ bool result = false;
87
+ if (!gpr_parse_bool_value(str.get(), &result)) {
88
+ LogParsingError(GetName(), str.get());
89
+ result = default_value_;
90
+ }
91
+ return result;
92
+ }
93
+
94
+ void GlobalConfigEnvBool::Set(bool value) {
95
+ SetValue(value ? "true" : "false");
96
+ }
97
+
98
+ static_assert(std::is_trivially_destructible<GlobalConfigEnvInt32>::value,
99
+ "GlobalConfigEnvInt32 needs to be trivially destructible.");
100
+
101
+ int32_t GlobalConfigEnvInt32::Get() {
102
+ UniquePtr<char> str = GetValue();
103
+ if (str == nullptr) {
104
+ return default_value_;
105
+ }
106
+ // parsing given value string.
107
+ char* end = str.get();
108
+ long result = strtol(str.get(), &end, 10);
109
+ if (*end != 0) {
110
+ LogParsingError(GetName(), str.get());
111
+ result = default_value_;
112
+ }
113
+ return static_cast<int32_t>(result);
114
+ }
115
+
116
+ void GlobalConfigEnvInt32::Set(int32_t value) {
117
+ char buffer[GPR_LTOA_MIN_BUFSIZE];
118
+ gpr_ltoa(value, buffer);
119
+ SetValue(buffer);
120
+ }
121
+
122
+ static_assert(std::is_trivially_destructible<GlobalConfigEnvString>::value,
123
+ "GlobalConfigEnvString needs to be trivially destructible.");
124
+
125
+ UniquePtr<char> GlobalConfigEnvString::Get() {
126
+ UniquePtr<char> str = GetValue();
127
+ if (str == nullptr) {
128
+ return UniquePtr<char>(gpr_strdup(default_value_));
129
+ }
130
+ return str;
131
+ }
132
+
133
+ void GlobalConfigEnvString::Set(const char* value) { SetValue(value); }
134
+
135
+ } // namespace grpc_core
@@ -0,0 +1,131 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_ENV_H
20
+ #define GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_ENV_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/lib/gprpp/global_config_generic.h"
25
+ #include "src/core/lib/gprpp/memory.h"
26
+
27
+ namespace grpc_core {
28
+
29
+ typedef void (*GlobalConfigEnvErrorFunctionType)(const char* error_message);
30
+
31
+ /*
32
+ * Set global_config_env_error_function which is called when config system
33
+ * encounters errors such as parsing error. What the default function does
34
+ * is logging error message.
35
+ */
36
+ void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func);
37
+
38
+ // Base class for all classes to access environment variables.
39
+ class GlobalConfigEnv {
40
+ protected:
41
+ // `name` should be writable and alive after constructor is called.
42
+ constexpr explicit GlobalConfigEnv(char* name) : name_(name) {}
43
+
44
+ public:
45
+ // Returns the value of `name` variable.
46
+ UniquePtr<char> GetValue();
47
+
48
+ // Sets the value of `name` variable.
49
+ void SetValue(const char* value);
50
+
51
+ // Unsets `name` variable.
52
+ void Unset();
53
+
54
+ protected:
55
+ char* GetName();
56
+
57
+ private:
58
+ char* name_;
59
+ };
60
+
61
+ class GlobalConfigEnvBool : public GlobalConfigEnv {
62
+ public:
63
+ constexpr GlobalConfigEnvBool(char* name, bool default_value)
64
+ : GlobalConfigEnv(name), default_value_(default_value) {}
65
+
66
+ bool Get();
67
+ void Set(bool value);
68
+
69
+ private:
70
+ bool default_value_;
71
+ };
72
+
73
+ class GlobalConfigEnvInt32 : public GlobalConfigEnv {
74
+ public:
75
+ constexpr GlobalConfigEnvInt32(char* name, int32_t default_value)
76
+ : GlobalConfigEnv(name), default_value_(default_value) {}
77
+
78
+ int32_t Get();
79
+ void Set(int32_t value);
80
+
81
+ private:
82
+ int32_t default_value_;
83
+ };
84
+
85
+ class GlobalConfigEnvString : public GlobalConfigEnv {
86
+ public:
87
+ constexpr GlobalConfigEnvString(char* name, const char* default_value)
88
+ : GlobalConfigEnv(name), default_value_(default_value) {}
89
+
90
+ UniquePtr<char> Get();
91
+ void Set(const char* value);
92
+
93
+ private:
94
+ const char* default_value_;
95
+ };
96
+
97
+ } // namespace grpc_core
98
+
99
+ // Macros for defining global config instances using environment variables.
100
+ // This defines a GlobalConfig*Type* instance with arguments for
101
+ // mutable variable name and default value.
102
+ // Mutable name (g_env_str_##name) is here for having an array
103
+ // for the canonical name without dynamic allocation.
104
+ // `help` argument is ignored for this implementation.
105
+
106
+ #define GPR_GLOBAL_CONFIG_DEFINE_BOOL(name, default_value, help) \
107
+ static char g_env_str_##name[] = #name; \
108
+ static ::grpc_core::GlobalConfigEnvBool g_env_##name(g_env_str_##name, \
109
+ default_value); \
110
+ bool gpr_global_config_get_##name() { return g_env_##name.Get(); } \
111
+ void gpr_global_config_set_##name(bool value) { g_env_##name.Set(value); }
112
+
113
+ #define GPR_GLOBAL_CONFIG_DEFINE_INT32(name, default_value, help) \
114
+ static char g_env_str_##name[] = #name; \
115
+ static ::grpc_core::GlobalConfigEnvInt32 g_env_##name(g_env_str_##name, \
116
+ default_value); \
117
+ int32_t gpr_global_config_get_##name() { return g_env_##name.Get(); } \
118
+ void gpr_global_config_set_##name(int32_t value) { g_env_##name.Set(value); }
119
+
120
+ #define GPR_GLOBAL_CONFIG_DEFINE_STRING(name, default_value, help) \
121
+ static char g_env_str_##name[] = #name; \
122
+ static ::grpc_core::GlobalConfigEnvString g_env_##name(g_env_str_##name, \
123
+ default_value); \
124
+ ::grpc_core::UniquePtr<char> gpr_global_config_get_##name() { \
125
+ return g_env_##name.Get(); \
126
+ } \
127
+ void gpr_global_config_set_##name(const char* value) { \
128
+ g_env_##name.Set(value); \
129
+ }
130
+
131
+ #endif /* GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_ENV_H */