grpc 1.21.0 → 1.22.0.pre1

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 (141) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +422 -62
  3. data/include/grpc/grpc_security.h +61 -5
  4. data/include/grpc/grpc_security_constants.h +1 -1
  5. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  6. data/include/grpc/slice.h +2 -2
  7. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
  8. data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
  10. data/src/core/ext/filters/client_channel/client_channel.h +0 -8
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
  16. data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  27. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
  31. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
  34. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
  35. data/src/core/ext/filters/client_channel/server_address.cc +4 -6
  36. data/src/core/ext/filters/client_channel/server_address.h +1 -3
  37. data/src/core/ext/filters/client_channel/service_config.cc +20 -22
  38. data/src/core/ext/filters/client_channel/service_config.h +26 -28
  39. data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
  40. data/src/core/ext/filters/client_channel/subchannel.h +97 -23
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
  43. data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
  45. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  46. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
  47. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
  48. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
  49. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
  50. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
  51. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  52. data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
  53. data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
  54. data/src/core/lib/channel/channelz.cc +136 -19
  55. data/src/core/lib/channel/channelz.h +36 -40
  56. data/src/core/lib/channel/channelz_registry.cc +74 -106
  57. data/src/core/lib/channel/channelz_registry.h +10 -28
  58. data/src/core/lib/channel/context.h +1 -1
  59. data/src/core/lib/channel/handshaker.cc +6 -0
  60. data/src/core/lib/compression/compression.cc +13 -8
  61. data/src/core/lib/compression/compression_internal.cc +14 -10
  62. data/src/core/lib/compression/compression_internal.h +1 -1
  63. data/src/core/lib/compression/stream_compression.cc +3 -2
  64. data/src/core/lib/compression/stream_compression.h +2 -2
  65. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  66. data/src/core/lib/gpr/env.h +1 -1
  67. data/src/core/lib/gpr/string.cc +8 -1
  68. data/src/core/lib/gpr/string.h +6 -1
  69. data/src/core/lib/gprpp/fork.cc +1 -1
  70. data/src/core/lib/gprpp/fork.h +5 -1
  71. data/src/core/lib/gprpp/global_config.h +9 -0
  72. data/src/core/lib/gprpp/global_config_custom.h +1 -1
  73. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  74. data/src/core/lib/gprpp/map.h +38 -21
  75. data/src/core/lib/gprpp/memory.h +2 -2
  76. data/src/core/lib/gprpp/orphanable.h +1 -1
  77. data/src/core/lib/gprpp/ref_counted.h +9 -4
  78. data/src/core/lib/http/httpcli.cc +3 -3
  79. data/src/core/lib/iomgr/buffer_list.h +1 -1
  80. data/src/core/lib/iomgr/call_combiner.cc +1 -1
  81. data/src/core/lib/iomgr/call_combiner.h +1 -1
  82. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  83. data/src/core/lib/iomgr/cfstream_handle.h +4 -0
  84. data/src/core/lib/iomgr/error.cc +3 -3
  85. data/src/core/lib/iomgr/error.h +9 -3
  86. data/src/core/lib/iomgr/error_internal.h +1 -1
  87. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
  88. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  89. data/src/core/lib/iomgr/ev_posix.h +3 -2
  90. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  91. data/src/core/lib/iomgr/iomgr.cc +4 -4
  92. data/src/core/lib/iomgr/lockfree_event.cc +1 -1
  93. data/src/core/lib/iomgr/port.h +5 -1
  94. data/src/core/lib/iomgr/tcp_posix.cc +1 -3
  95. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  96. data/src/core/lib/iomgr/tcp_server.h +24 -0
  97. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
  98. data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
  99. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  100. data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
  101. data/src/core/lib/iomgr/tcp_uv.cc +5 -6
  102. data/src/core/lib/iomgr/timer.h +2 -1
  103. data/src/core/lib/iomgr/udp_server.cc +2 -2
  104. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  105. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  106. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  107. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  108. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
  109. data/src/core/lib/security/transport/auth_filters.h +3 -0
  110. data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
  111. data/src/core/lib/security/transport/security_handshaker.cc +7 -7
  112. data/src/core/lib/slice/b64.h +2 -2
  113. data/src/core/lib/slice/slice.cc +82 -10
  114. data/src/core/lib/slice/slice_buffer.cc +49 -21
  115. data/src/core/lib/slice/slice_hash_table.h +2 -2
  116. data/src/core/lib/slice/slice_intern.cc +15 -16
  117. data/src/core/lib/slice/slice_internal.h +52 -0
  118. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  119. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  120. data/src/core/lib/slice/slice_utils.h +50 -0
  121. data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
  122. data/src/core/lib/surface/call.cc +14 -8
  123. data/src/core/lib/surface/channel.cc +89 -97
  124. data/src/core/lib/surface/channel.h +60 -6
  125. data/src/core/lib/surface/completion_queue.cc +49 -36
  126. data/src/core/lib/surface/completion_queue.h +2 -1
  127. data/src/core/lib/surface/server.cc +8 -8
  128. data/src/core/lib/surface/validate_metadata.cc +14 -8
  129. data/src/core/lib/surface/validate_metadata.h +13 -2
  130. data/src/core/lib/surface/version.cc +1 -1
  131. data/src/core/lib/transport/metadata.cc +56 -26
  132. data/src/core/lib/transport/metadata.h +91 -75
  133. data/src/core/lib/transport/static_metadata.cc +262 -176
  134. data/src/core/lib/transport/static_metadata.h +272 -180
  135. data/src/core/lib/transport/transport.cc +1 -1
  136. data/src/core/lib/transport/transport.h +8 -2
  137. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  138. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
  140. data/src/ruby/lib/grpc/version.rb +1 -1
  141. metadata +37 -35
@@ -36,7 +36,7 @@ typedef enum {
36
36
  GRPC_CONTEXT_TRAFFIC,
37
37
 
38
38
  /// Holds a pointer to ServiceConfig::CallData associated with this call.
39
- GRPC_SERVICE_CONFIG_CALL_DATA,
39
+ GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA,
40
40
 
41
41
  GRPC_CONTEXT_COUNT
42
42
  } grpc_context_index;
@@ -20,6 +20,7 @@
20
20
 
21
21
  #include <string.h>
22
22
 
23
+ #include <grpc/impl/codegen/slice.h>
23
24
  #include <grpc/support/alloc.h>
24
25
  #include <grpc/support/log.h>
25
26
  #include <grpc/support/string_util.h>
@@ -226,6 +227,11 @@ void HandshakeManager::DoHandshake(grpc_endpoint* endpoint,
226
227
  args_.read_buffer =
227
228
  static_cast<grpc_slice_buffer*>(gpr_malloc(sizeof(*args_.read_buffer)));
228
229
  grpc_slice_buffer_init(args_.read_buffer);
230
+ if (acceptor != nullptr && acceptor->external_connection &&
231
+ acceptor->pending_data != nullptr) {
232
+ grpc_slice_buffer_swap(args_.read_buffer,
233
+ &(acceptor->pending_data->data.raw.slice_buffer));
234
+ }
229
235
  // Initialize state needed for calling handshakers.
230
236
  acceptor_ = acceptor;
231
237
  GRPC_CLOSURE_INIT(&call_next_handshaker_,
@@ -26,6 +26,7 @@
26
26
  #include "src/core/lib/compression/algorithm_metadata.h"
27
27
  #include "src/core/lib/compression/compression_internal.h"
28
28
  #include "src/core/lib/gpr/useful.h"
29
+ #include "src/core/lib/slice/slice_utils.h"
29
30
  #include "src/core/lib/surface/api_trace.h"
30
31
  #include "src/core/lib/transport/static_metadata.h"
31
32
 
@@ -42,16 +43,17 @@ int grpc_compression_algorithm_is_stream(grpc_compression_algorithm algorithm) {
42
43
 
43
44
  int grpc_compression_algorithm_parse(grpc_slice name,
44
45
  grpc_compression_algorithm* algorithm) {
45
- if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) {
46
+ if (grpc_slice_eq_static_interned(name, GRPC_MDSTR_IDENTITY)) {
46
47
  *algorithm = GRPC_COMPRESS_NONE;
47
48
  return 1;
48
- } else if (grpc_slice_eq(name, GRPC_MDSTR_DEFLATE)) {
49
+ } else if (grpc_slice_eq_static_interned(name, GRPC_MDSTR_DEFLATE)) {
49
50
  *algorithm = GRPC_COMPRESS_DEFLATE;
50
51
  return 1;
51
- } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) {
52
+ } else if (grpc_slice_eq_static_interned(name, GRPC_MDSTR_GZIP)) {
52
53
  *algorithm = GRPC_COMPRESS_GZIP;
53
54
  return 1;
54
- } else if (grpc_slice_eq(name, GRPC_MDSTR_STREAM_SLASH_GZIP)) {
55
+ } else if (grpc_slice_eq_static_interned(name,
56
+ GRPC_MDSTR_STREAM_SLASH_GZIP)) {
55
57
  *algorithm = GRPC_COMPRESS_STREAM_GZIP;
56
58
  return 1;
57
59
  } else {
@@ -148,10 +150,13 @@ grpc_slice grpc_compression_algorithm_slice(
148
150
 
149
151
  grpc_compression_algorithm grpc_compression_algorithm_from_slice(
150
152
  const grpc_slice& str) {
151
- if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE;
152
- if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) return GRPC_COMPRESS_DEFLATE;
153
- if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_COMPRESS_GZIP;
154
- if (grpc_slice_eq(str, GRPC_MDSTR_STREAM_SLASH_GZIP))
153
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_IDENTITY))
154
+ return GRPC_COMPRESS_NONE;
155
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_DEFLATE))
156
+ return GRPC_COMPRESS_DEFLATE;
157
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_GZIP))
158
+ return GRPC_COMPRESS_GZIP;
159
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_STREAM_SLASH_GZIP))
155
160
  return GRPC_COMPRESS_STREAM_GZIP;
156
161
  return GRPC_COMPRESS_ALGORITHMS_COUNT;
157
162
  }
@@ -26,6 +26,7 @@
26
26
  #include "src/core/lib/compression/algorithm_metadata.h"
27
27
  #include "src/core/lib/compression/compression_internal.h"
28
28
  #include "src/core/lib/gpr/useful.h"
29
+ #include "src/core/lib/slice/slice_utils.h"
29
30
  #include "src/core/lib/surface/api_trace.h"
30
31
  #include "src/core/lib/transport/static_metadata.h"
31
32
 
@@ -33,18 +34,21 @@
33
34
 
34
35
  grpc_message_compression_algorithm
35
36
  grpc_message_compression_algorithm_from_slice(const grpc_slice& str) {
36
- if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY))
37
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_IDENTITY))
37
38
  return GRPC_MESSAGE_COMPRESS_NONE;
38
- if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE))
39
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_DEFLATE))
39
40
  return GRPC_MESSAGE_COMPRESS_DEFLATE;
40
- if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_MESSAGE_COMPRESS_GZIP;
41
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_GZIP))
42
+ return GRPC_MESSAGE_COMPRESS_GZIP;
41
43
  return GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT;
42
44
  }
43
45
 
44
46
  grpc_stream_compression_algorithm grpc_stream_compression_algorithm_from_slice(
45
47
  const grpc_slice& str) {
46
- if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_STREAM_COMPRESS_NONE;
47
- if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_STREAM_COMPRESS_GZIP;
48
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_IDENTITY))
49
+ return GRPC_STREAM_COMPRESS_NONE;
50
+ if (grpc_slice_eq_static_interned(str, GRPC_MDSTR_GZIP))
51
+ return GRPC_STREAM_COMPRESS_GZIP;
48
52
  return GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT;
49
53
  }
50
54
 
@@ -244,13 +248,13 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level(
244
248
 
245
249
  int grpc_message_compression_algorithm_parse(
246
250
  grpc_slice value, grpc_message_compression_algorithm* algorithm) {
247
- if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) {
251
+ if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_IDENTITY)) {
248
252
  *algorithm = GRPC_MESSAGE_COMPRESS_NONE;
249
253
  return 1;
250
- } else if (grpc_slice_eq(value, GRPC_MDSTR_DEFLATE)) {
254
+ } else if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_DEFLATE)) {
251
255
  *algorithm = GRPC_MESSAGE_COMPRESS_DEFLATE;
252
256
  return 1;
253
- } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) {
257
+ } else if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_GZIP)) {
254
258
  *algorithm = GRPC_MESSAGE_COMPRESS_GZIP;
255
259
  return 1;
256
260
  } else {
@@ -263,10 +267,10 @@ int grpc_message_compression_algorithm_parse(
263
267
 
264
268
  int grpc_stream_compression_algorithm_parse(
265
269
  grpc_slice value, grpc_stream_compression_algorithm* algorithm) {
266
- if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) {
270
+ if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_IDENTITY)) {
267
271
  *algorithm = GRPC_STREAM_COMPRESS_NONE;
268
272
  return 1;
269
- } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) {
273
+ } else if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_GZIP)) {
270
274
  *algorithm = GRPC_STREAM_COMPRESS_GZIP;
271
275
  return 1;
272
276
  } else {
@@ -35,7 +35,7 @@ typedef enum {
35
35
  GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT
36
36
  } grpc_message_compression_algorithm;
37
37
 
38
- /** Stream compresssion algorithms supported by gRPC */
38
+ /** Stream compression algorithms supported by gRPC */
39
39
  typedef enum {
40
40
  GRPC_STREAM_COMPRESS_NONE = 0,
41
41
  GRPC_STREAM_COMPRESS_GZIP,
@@ -22,6 +22,7 @@
22
22
 
23
23
  #include "src/core/lib/compression/stream_compression.h"
24
24
  #include "src/core/lib/compression/stream_compression_gzip.h"
25
+ #include "src/core/lib/slice/slice_utils.h"
25
26
 
26
27
  extern const grpc_stream_compression_vtable
27
28
  grpc_stream_compression_identity_vtable;
@@ -65,11 +66,11 @@ void grpc_stream_compression_context_destroy(
65
66
  int grpc_stream_compression_method_parse(
66
67
  grpc_slice value, bool is_compress,
67
68
  grpc_stream_compression_method* method) {
68
- if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) {
69
+ if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_IDENTITY)) {
69
70
  *method = is_compress ? GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS
70
71
  : GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS;
71
72
  return 1;
72
- } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) {
73
+ } else if (grpc_slice_eq_static_interned(value, GRPC_MDSTR_GZIP)) {
73
74
  *method = is_compress ? GRPC_STREAM_COMPRESSION_GZIP_COMPRESS
74
75
  : GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS;
75
76
  return 1;
@@ -68,7 +68,7 @@ struct grpc_stream_compression_vtable {
68
68
  * at the end of compression. Emits at most \a max_output_size compressed bytes
69
69
  * into \a out. If all the bytes in input buffer \a in are depleted and \a flush
70
70
  * is not GRPC_STREAM_COMPRESSION_FLUSH_NONE, the corresponding flush method is
71
- * executed. The total number of bytes emitted is outputed in \a output_size.
71
+ * executed. The total number of bytes emitted is outputted in \a output_size.
72
72
  *
73
73
  * A SYNC flush indicates that the entire messages in \a in can be decompressed
74
74
  * from \a out. A FINISH flush implies a SYNC flush, and that any further
@@ -85,7 +85,7 @@ bool grpc_stream_compress(grpc_stream_compression_context* ctx,
85
85
  * Decompress bytes provided in \a in with a given context. Emits at most \a
86
86
  * max_output_size decompressed bytes into \a out. If decompression process
87
87
  * reached the end of a gzip stream, \a end_of_context is set to true; otherwise
88
- * it is set to false. The total number of bytes emitted is outputed in \a
88
+ * it is set to false. The total number of bytes emitted is outputted in \a
89
89
  * output_size.
90
90
  */
91
91
  bool grpc_stream_decompress(grpc_stream_compression_context* ctx,
@@ -53,25 +53,25 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx,
53
53
  ctx->zs.avail_out = static_cast<uInt>(slice_size);
54
54
  ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out);
55
55
  while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) {
56
- grpc_slice slice = grpc_slice_buffer_take_first(in);
57
- ctx->zs.avail_in = static_cast<uInt> GRPC_SLICE_LENGTH(slice);
58
- ctx->zs.next_in = GRPC_SLICE_START_PTR(slice);
56
+ grpc_slice* slice = grpc_slice_buffer_peek_first(in);
57
+ ctx->zs.avail_in = static_cast<uInt> GRPC_SLICE_LENGTH(*slice);
58
+ ctx->zs.next_in = GRPC_SLICE_START_PTR(*slice);
59
59
  r = ctx->flate(&ctx->zs, Z_NO_FLUSH);
60
60
  if (r < 0 && r != Z_BUF_ERROR) {
61
61
  gpr_log(GPR_ERROR, "zlib error (%d)", r);
62
62
  grpc_slice_unref_internal(slice_out);
63
- grpc_slice_unref_internal(slice);
63
+ grpc_slice_buffer_remove_first(in);
64
64
  return false;
65
65
  } else if (r == Z_STREAM_END && ctx->flate == inflate) {
66
66
  eoc = true;
67
67
  }
68
68
  if (ctx->zs.avail_in > 0) {
69
- grpc_slice_buffer_undo_take_first(
70
- in,
71
- grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in,
72
- GRPC_SLICE_LENGTH(slice)));
69
+ grpc_slice_buffer_sub_first(
70
+ in, GRPC_SLICE_LENGTH(*slice) - ctx->zs.avail_in,
71
+ GRPC_SLICE_LENGTH(*slice));
72
+ } else {
73
+ grpc_slice_buffer_remove_first(in);
73
74
  }
74
- grpc_slice_unref_internal(slice);
75
75
  }
76
76
  if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) {
77
77
  GPR_ASSERT(in->length == 0);
@@ -26,7 +26,7 @@
26
26
  /* Env utility functions */
27
27
 
28
28
  /* Gets the environment variable value with the specified name.
29
- Returns a newly allocated string. It is the responsability of the caller to
29
+ Returns a newly allocated string. It is the responsibility of the caller to
30
30
  gpr_free the return value if not NULL (which means that the environment
31
31
  variable exists). */
32
32
  char* gpr_getenv(const char* name);
@@ -126,7 +126,8 @@ static void asciidump(dump_out* out, const char* buf, size_t len) {
126
126
  }
127
127
  }
128
128
 
129
- char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
129
+ char* gpr_dump_return_len(const char* buf, size_t len, uint32_t flags,
130
+ size_t* out_len) {
130
131
  dump_out out = dump_out_create();
131
132
  if (flags & GPR_DUMP_HEX) {
132
133
  hexdump(&out, buf, len);
@@ -135,9 +136,15 @@ char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
135
136
  asciidump(&out, buf, len);
136
137
  }
137
138
  dump_out_append(&out, 0);
139
+ *out_len = out.length;
138
140
  return out.data;
139
141
  }
140
142
 
143
+ char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
144
+ size_t unused;
145
+ return gpr_dump_return_len(buf, len, flags, &unused);
146
+ }
147
+
141
148
  int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) {
142
149
  uint32_t out = 0;
143
150
  uint32_t new_val;
@@ -32,9 +32,14 @@
32
32
  #define GPR_DUMP_HEX 0x00000001
33
33
  #define GPR_DUMP_ASCII 0x00000002
34
34
 
35
- /* Converts array buf, of length len, into a C string according to the flags.
35
+ /* Converts array buf, of length len, into a C string according to the flags.
36
36
  Result should be freed with gpr_free() */
37
37
  char* gpr_dump(const char* buf, size_t len, uint32_t flags);
38
+ /* Converts array buf, of length len, into a C string according to the flags.
39
+ The length of the returned buffer is stored in out_len.
40
+ Result should be freed with gpr_free() */
41
+ char* gpr_dump_return_len(const char* buf, size_t len, uint32_t flags,
42
+ size_t* out_len);
38
43
 
39
44
  /* Parses an array of bytes into an integer (base 10). Returns 1 on success,
40
45
  0 on failure. */
@@ -243,7 +243,7 @@ void Fork::AwaitThreads() {
243
243
 
244
244
  internal::ExecCtxState* Fork::exec_ctx_state_ = nullptr;
245
245
  internal::ThreadState* Fork::thread_state_ = nullptr;
246
- bool Fork::support_enabled_ = false;
246
+ std::atomic<bool> Fork::support_enabled_;
247
247
  bool Fork::override_enabled_ = false;
248
248
  Fork::child_postfork_func Fork::reset_child_polling_engine_ = nullptr;
249
249
  } // namespace grpc_core
@@ -19,6 +19,10 @@
19
19
  #ifndef GRPC_CORE_LIB_GPRPP_FORK_H
20
20
  #define GRPC_CORE_LIB_GPRPP_FORK_H
21
21
 
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <atomic>
25
+
22
26
  /*
23
27
  * NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
24
28
  * AROUND VERY SPECIFIC USE CASES.
@@ -78,7 +82,7 @@ class Fork {
78
82
  private:
79
83
  static internal::ExecCtxState* exec_ctx_state_;
80
84
  static internal::ThreadState* thread_state_;
81
- static bool support_enabled_;
85
+ static std::atomic<bool> support_enabled_;
82
86
  static bool override_enabled_;
83
87
  static child_postfork_func reset_child_polling_engine_;
84
88
  };
@@ -59,6 +59,15 @@
59
59
  //
60
60
  // Declaring config variables for other modules to access:
61
61
  // GPR_GLOBAL_CONFIG_DECLARE_*TYPE*(name)
62
+ //
63
+ // * Caveat for setting global configs at runtime
64
+ //
65
+ // Setting global configs at runtime multiple times is safe but it doesn't
66
+ // mean that it will have a valid effect on the module depending configs.
67
+ // In unit tests, it may be unpredictable to set different global configs
68
+ // between test cases because grpc init and shutdown can ignore changes.
69
+ // It's considered safe to set global configs before the first call to
70
+ // grpc_init().
62
71
 
63
72
  // --------------------------------------------------------------------
64
73
  // How to customize the global configuration system:
@@ -19,7 +19,7 @@
19
19
  #ifndef GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H
20
20
  #define GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_CUSTOM_H
21
21
 
22
- // This is a placeholder for custom global configuration implementaion.
22
+ // This is a placeholder for custom global configuration implementation.
23
23
  // To use the custom one, please define following macros here.
24
24
  //
25
25
  // GPR_GLOBAL_CONFIG_DEFINE_BOOL
@@ -97,6 +97,14 @@ class InlinedVector {
97
97
  return data()[offset];
98
98
  }
99
99
 
100
+ bool operator==(const InlinedVector& other) const {
101
+ if (size_ != other.size_) return false;
102
+ for (size_t i = 0; i < size_; ++i) {
103
+ if (data()[i] != other.data()[i]) return false;
104
+ }
105
+ return true;
106
+ }
107
+
100
108
  void reserve(size_t capacity) {
101
109
  if (capacity > capacity_) {
102
110
  T* new_dynamic = static_cast<T*>(gpr_malloc(sizeof(T) * capacity));
@@ -22,8 +22,11 @@
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
24
  #include <string.h>
25
+
26
+ #include <algorithm>
25
27
  #include <functional>
26
28
  #include <iterator>
29
+
27
30
  #include "src/core/lib/gpr/useful.h"
28
31
  #include "src/core/lib/gprpp/memory.h"
29
32
  #include "src/core/lib/gprpp/pair.h"
@@ -88,6 +91,13 @@ class Map {
88
91
 
89
92
  iterator end() { return iterator(this, nullptr); }
90
93
 
94
+ iterator lower_bound(const Key& k) {
95
+ key_compare compare;
96
+ return std::find_if(begin(), end(), [&k, &compare](const value_type& v) {
97
+ return !compare(v.first, k);
98
+ });
99
+ }
100
+
91
101
  private:
92
102
  friend class testing::MapTest;
93
103
  struct Entry {
@@ -112,7 +122,10 @@ class Map {
112
122
  // inserted entry and the second value being the new root of the subtree
113
123
  // after a rebalance
114
124
  Pair<iterator, Entry*> InsertRecursive(Entry* root, value_type&& p);
115
- static Entry* RemoveRecursive(Entry* root, const key_type& k);
125
+ // Returns a pair with the first value being an iterator pointing to the
126
+ // successor of the deleted entry and the second value being the new root of
127
+ // the subtree after a rebalance
128
+ Pair<iterator, Entry*> RemoveRecursive(Entry* root, const key_type& k);
116
129
  // Return 0 if lhs = rhs
117
130
  // 1 if lhs > rhs
118
131
  // -1 if lhs < rhs
@@ -233,10 +246,10 @@ typename Map<Key, T, Compare>::iterator Map<Key, T, Compare>::erase(
233
246
  iterator iter) {
234
247
  if (iter == end()) return iter;
235
248
  key_type& del_key = iter->first;
236
- iter++;
237
- root_ = RemoveRecursive(root_, del_key);
249
+ Pair<iterator, Entry*> ret = RemoveRecursive(root_, del_key);
250
+ root_ = ret.second;
238
251
  size_--;
239
- return iter;
252
+ return ret.first;
240
253
  }
241
254
 
242
255
  template <class Key, class T, class Compare>
@@ -373,34 +386,38 @@ Map<Key, T, Compare>::RebalanceTreeAfterDeletion(Entry* root) {
373
386
  }
374
387
 
375
388
  template <class Key, class T, class Compare>
376
- typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RemoveRecursive(
377
- Entry* root, const key_type& k) {
378
- if (root == nullptr) return root;
389
+ typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator,
390
+ typename Map<Key, T, Compare>::Entry*>
391
+ Map<Key, T, Compare>::RemoveRecursive(Entry* root, const key_type& k) {
392
+ Pair<iterator, Entry*> ret = MakePair(end(), root);
393
+ if (root == nullptr) return ret;
379
394
  int comp = CompareKeys(root->pair.first, k);
380
395
  if (comp > 0) {
381
- root->left = RemoveRecursive(root->left, k);
396
+ ret = RemoveRecursive(root->left, k);
397
+ root->left = ret.second;
382
398
  } else if (comp < 0) {
383
- root->right = RemoveRecursive(root->right, k);
399
+ ret = RemoveRecursive(root->right, k);
400
+ root->right = ret.second;
384
401
  } else {
385
- Entry* ret;
402
+ Entry* entry;
403
+ Entry* successor = InOrderSuccessor(root);
386
404
  if (root->left == nullptr) {
387
- ret = root->right;
405
+ entry = root->right;
388
406
  Delete(root);
389
- return ret;
407
+ return MakePair(iterator(this, successor), entry);
390
408
  } else if (root->right == nullptr) {
391
- ret = root->left;
409
+ entry = root->left;
392
410
  Delete(root);
393
- return ret;
411
+ return MakePair(iterator(this, successor), entry);
394
412
  } else {
395
- ret = root->right;
396
- while (ret->left != nullptr) {
397
- ret = ret->left;
398
- }
399
- root->pair.swap(ret->pair);
400
- root->right = RemoveRecursive(root->right, ret->pair.first);
413
+ entry = successor;
414
+ root->pair.swap(entry->pair);
415
+ ret = RemoveRecursive(root->right, entry->pair.first);
416
+ root->right = ret.second;
417
+ ret.first = iterator(this, root);
401
418
  }
402
419
  }
403
- return RebalanceTreeAfterDeletion(root);
420
+ return MakePair(ret.first, RebalanceTreeAfterDeletion(root));
404
421
  }
405
422
 
406
423
  template <class Key, class T, class Compare>