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
@@ -92,6 +92,9 @@ struct grpc_tcp_server {
92
92
 
93
93
  /* channel args for this server */
94
94
  grpc_channel_args* channel_args;
95
+
96
+ /* a handler for external connections, owned */
97
+ grpc_core::TcpServerFdHandler* fd_handler;
95
98
  };
96
99
 
97
100
  /* If successful, add a listener to \a s for \a addr, set \a dsmode for the
@@ -372,6 +372,7 @@ static void on_accept(void* arg, grpc_error* error) {
372
372
  acceptor->from_server = sp->server;
373
373
  acceptor->port_index = sp->port_index;
374
374
  acceptor->fd_index = 0;
375
+ acceptor->external_connection = false;
375
376
  sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor);
376
377
  }
377
378
  /* As we were notified from the IOCP of one and exactly one accept,
@@ -545,16 +546,17 @@ static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index,
545
546
  return -1;
546
547
  }
547
548
 
549
+ static grpc_core::TcpServerFdHandler* tcp_server_create_fd_handler(
550
+ grpc_tcp_server* s) {
551
+ return nullptr;
552
+ }
553
+
548
554
  static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {}
549
555
 
550
556
  grpc_tcp_server_vtable grpc_windows_tcp_server_vtable = {
551
- tcp_server_create,
552
- tcp_server_start,
553
- tcp_server_add_port,
554
- tcp_server_port_fd_count,
555
- tcp_server_port_fd,
556
- tcp_server_ref,
557
- tcp_server_shutdown_starting_add,
558
- tcp_server_unref,
559
- tcp_server_shutdown_listeners};
557
+ tcp_server_create, tcp_server_start,
558
+ tcp_server_add_port, tcp_server_create_fd_handler,
559
+ tcp_server_port_fd_count, tcp_server_port_fd,
560
+ tcp_server_ref, tcp_server_shutdown_starting_add,
561
+ tcp_server_unref, tcp_server_shutdown_listeners};
560
562
  #endif /* GRPC_WINSOCK_SOCKET */
@@ -53,7 +53,7 @@ typedef struct uv_socket_t {
53
53
  char* read_buf;
54
54
  size_t read_len;
55
55
 
56
- bool pending_connection;
56
+ int pending_connections;
57
57
  grpc_custom_socket* accept_socket;
58
58
  grpc_error* accept_error;
59
59
 
@@ -206,7 +206,7 @@ static grpc_error* uv_socket_init_helper(uv_socket_t* uv_socket, int domain) {
206
206
  // Node uses a garbage collector to call destructors, so we don't
207
207
  // want to hold the uv loop open with active gRPC objects.
208
208
  uv_unref((uv_handle_t*)uv_socket->handle);
209
- uv_socket->pending_connection = false;
209
+ uv_socket->pending_connections = 0;
210
210
  uv_socket->accept_socket = nullptr;
211
211
  uv_socket->accept_error = GRPC_ERROR_NONE;
212
212
  return GRPC_ERROR_NONE;
@@ -243,14 +243,14 @@ static grpc_error* uv_socket_getsockname(grpc_custom_socket* socket,
243
243
 
244
244
  static void accept_new_connection(grpc_custom_socket* socket) {
245
245
  uv_socket_t* uv_socket = (uv_socket_t*)socket->impl;
246
- if (!uv_socket->pending_connection || !uv_socket->accept_socket) {
246
+ if (uv_socket->pending_connections == 0 || !uv_socket->accept_socket) {
247
247
  return;
248
248
  }
249
249
  grpc_custom_socket* new_socket = uv_socket->accept_socket;
250
250
  grpc_error* error = uv_socket->accept_error;
251
251
  uv_socket->accept_socket = nullptr;
252
252
  uv_socket->accept_error = GRPC_ERROR_NONE;
253
- uv_socket->pending_connection = false;
253
+ uv_socket->pending_connections -= 1;
254
254
  if (uv_socket->accept_error != GRPC_ERROR_NONE) {
255
255
  uv_stream_t dummy_handle;
256
256
  uv_accept((uv_stream_t*)uv_socket->handle, &dummy_handle);
@@ -270,8 +270,6 @@ static void accept_new_connection(grpc_custom_socket* socket) {
270
270
  static void uv_on_connect(uv_stream_t* server, int status) {
271
271
  grpc_custom_socket* socket = (grpc_custom_socket*)server->data;
272
272
  uv_socket_t* uv_socket = (uv_socket_t*)socket->impl;
273
- GPR_ASSERT(!uv_socket->pending_connection);
274
- uv_socket->pending_connection = true;
275
273
  if (status < 0) {
276
274
  switch (status) {
277
275
  case UV_EINTR:
@@ -281,6 +279,7 @@ static void uv_on_connect(uv_stream_t* server, int status) {
281
279
  uv_socket->accept_error = tcp_error_create("accept failed", status);
282
280
  }
283
281
  }
282
+ uv_socket->pending_connections += 1;
284
283
  accept_new_connection(socket);
285
284
  }
286
285
 
@@ -29,7 +29,8 @@
29
29
 
30
30
  typedef struct grpc_timer {
31
31
  grpc_millis deadline;
32
- uint32_t heap_index; /* INVALID_HEAP_INDEX if not in heap */
32
+ // Uninitialized if not using heap, or INVALID_HEAP_INDEX if not in heap.
33
+ uint32_t heap_index;
33
34
  bool pending;
34
35
  struct grpc_timer* next;
35
36
  struct grpc_timer* prev;
@@ -332,7 +332,7 @@ void GrpcUdpListener::OnFdAboutToOrphan() {
332
332
  GRPC_CLOSURE_INIT(&destroyed_closure_, destroyed_port, server_,
333
333
  grpc_schedule_on_exec_ctx);
334
334
  if (!orphan_notified_ && udp_handler_ != nullptr) {
335
- /* Singals udp_handler that the FD is about to be closed and
335
+ /* Signals udp_handler that the FD is about to be closed and
336
336
  * should no longer be used. */
337
337
  GRPC_CLOSURE_INIT(&orphan_fd_closure_, shutdown_fd, this,
338
338
  grpc_schedule_on_exec_ctx);
@@ -645,7 +645,7 @@ int grpc_udp_server_add_port(grpc_udp_server* s,
645
645
  grpc_sockaddr_set_port(addr, allocated_port1);
646
646
  port = allocated_port1;
647
647
  } else if (allocated_port1 >= 0) {
648
- /* The following sucessfully created socket should have same port as
648
+ /* The following successfully created socket should have same port as
649
649
  * the first one. */
650
650
  GPR_ASSERT(port == allocated_port1);
651
651
  }
@@ -85,7 +85,7 @@ static grpc_error* process_plugin_result(
85
85
  grpc_validate_header_key_is_legal(md[i].key))) {
86
86
  seen_illegal_header = true;
87
87
  break;
88
- } else if (!grpc_is_binary_header(md[i].key) &&
88
+ } else if (!grpc_is_binary_header_internal(md[i].key) &&
89
89
  !GRPC_LOG_IF_ERROR(
90
90
  "validate_metadata_from_plugin",
91
91
  grpc_validate_header_nonbin_value_is_legal(md[i].value))) {
@@ -46,7 +46,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp,
46
46
 
47
47
  grpc_ssl_credentials::grpc_ssl_credentials(
48
48
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
49
- const verify_peer_options* verify_options)
49
+ const grpc_ssl_verify_peer_options* verify_options)
50
50
  : grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_SSL) {
51
51
  build_config(pem_root_certs, pem_key_cert_pair, verify_options);
52
52
  }
@@ -94,7 +94,7 @@ grpc_ssl_credentials::create_security_connector(
94
94
 
95
95
  void grpc_ssl_credentials::build_config(
96
96
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
97
- const verify_peer_options* verify_options) {
97
+ const grpc_ssl_verify_peer_options* verify_options) {
98
98
  config_.pem_root_certs = gpr_strdup(pem_root_certs);
99
99
  if (pem_key_cert_pair != nullptr) {
100
100
  GPR_ASSERT(pem_key_cert_pair->private_key != nullptr);
@@ -117,6 +117,8 @@ void grpc_ssl_credentials::build_config(
117
117
  }
118
118
  }
119
119
 
120
+ /* Deprecated in favor of grpc_ssl_credentials_create_ex. Will be removed
121
+ * once all of its call sites are migrated to grpc_ssl_credentials_create_ex. */
120
122
  grpc_channel_credentials* grpc_ssl_credentials_create(
121
123
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
122
124
  const verify_peer_options* verify_options, void* reserved) {
@@ -128,6 +130,22 @@ grpc_channel_credentials* grpc_ssl_credentials_create(
128
130
  4, (pem_root_certs, pem_key_cert_pair, verify_options, reserved));
129
131
  GPR_ASSERT(reserved == nullptr);
130
132
 
133
+ return grpc_core::New<grpc_ssl_credentials>(
134
+ pem_root_certs, pem_key_cert_pair,
135
+ reinterpret_cast<const grpc_ssl_verify_peer_options*>(verify_options));
136
+ }
137
+
138
+ grpc_channel_credentials* grpc_ssl_credentials_create_ex(
139
+ const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
140
+ const grpc_ssl_verify_peer_options* verify_options, void* reserved) {
141
+ GRPC_API_TRACE(
142
+ "grpc_ssl_credentials_create(pem_root_certs=%s, "
143
+ "pem_key_cert_pair=%p, "
144
+ "verify_options=%p, "
145
+ "reserved=%p)",
146
+ 4, (pem_root_certs, pem_key_cert_pair, verify_options, reserved));
147
+ GPR_ASSERT(reserved == nullptr);
148
+
131
149
  return grpc_core::New<grpc_ssl_credentials>(pem_root_certs, pem_key_cert_pair,
132
150
  verify_options);
133
151
  }
@@ -28,7 +28,7 @@ class grpc_ssl_credentials : public grpc_channel_credentials {
28
28
  public:
29
29
  grpc_ssl_credentials(const char* pem_root_certs,
30
30
  grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
31
- const verify_peer_options* verify_options);
31
+ const grpc_ssl_verify_peer_options* verify_options);
32
32
 
33
33
  ~grpc_ssl_credentials() override;
34
34
 
@@ -41,7 +41,7 @@ class grpc_ssl_credentials : public grpc_channel_credentials {
41
41
  private:
42
42
  void build_config(const char* pem_root_certs,
43
43
  grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
44
- const verify_peer_options* verify_options);
44
+ const grpc_ssl_verify_peer_options* verify_options);
45
45
 
46
46
  grpc_ssl_config config_;
47
47
  };
@@ -102,7 +102,7 @@ class grpc_channel_security_connector : public grpc_security_connector {
102
102
  grpc_auth_context* auth_context,
103
103
  grpc_closure* on_call_host_checked,
104
104
  grpc_error** error) GRPC_ABSTRACT;
105
- /// Cancels a pending asychronous call to
105
+ /// Cancels a pending asynchronous call to
106
106
  /// grpc_channel_security_connector_check_call_host() with
107
107
  /// \a on_call_host_checked as its callback.
108
108
  virtual void cancel_check_call_host(grpc_closure* on_call_host_checked,
@@ -310,7 +310,7 @@ class grpc_ssl_server_security_connector
310
310
  private:
311
311
  /* Attempts to fetch the server certificate config if a callback is available.
312
312
  * Current certificate config will continue to be used if the callback returns
313
- * an error. Returns true if new credentials were sucessfully loaded. */
313
+ * an error. Returns true if new credentials were successfully loaded. */
314
314
  bool try_fetch_ssl_server_credentials() {
315
315
  grpc_ssl_server_certificate_config* certificate_config = nullptr;
316
316
  bool status;
@@ -32,6 +32,9 @@ void grpc_auth_metadata_context_build(
32
32
  const grpc_slice& call_method, grpc_auth_context* auth_context,
33
33
  grpc_auth_metadata_context* auth_md_context);
34
34
 
35
+ void grpc_auth_metadata_context_copy(grpc_auth_metadata_context* from,
36
+ grpc_auth_metadata_context* to);
37
+
35
38
  void grpc_auth_metadata_context_reset(grpc_auth_metadata_context* context);
36
39
 
37
40
  #endif /* GRPC_CORE_LIB_SECURITY_TRANSPORT_AUTH_FILTERS_H */
@@ -112,6 +112,19 @@ struct call_data {
112
112
 
113
113
  } // namespace
114
114
 
115
+ void grpc_auth_metadata_context_copy(grpc_auth_metadata_context* from,
116
+ grpc_auth_metadata_context* to) {
117
+ grpc_auth_metadata_context_reset(to);
118
+ to->channel_auth_context = from->channel_auth_context;
119
+ if (to->channel_auth_context != nullptr) {
120
+ const_cast<grpc_auth_context*>(to->channel_auth_context)
121
+ ->Ref(DEBUG_LOCATION, "grpc_auth_metadata_context_copy")
122
+ .release();
123
+ }
124
+ to->service_url = gpr_strdup(from->service_url);
125
+ to->method_name = gpr_strdup(from->method_name);
126
+ }
127
+
115
128
  void grpc_auth_metadata_context_reset(
116
129
  grpc_auth_metadata_context* auth_md_context) {
117
130
  if (auth_md_context->service_url != nullptr) {
@@ -144,11 +144,11 @@ size_t SecurityHandshaker::MoveReadBufferIntoHandshakeBuffer() {
144
144
  }
145
145
  size_t offset = 0;
146
146
  while (args_->read_buffer->count > 0) {
147
- grpc_slice next_slice = grpc_slice_buffer_take_first(args_->read_buffer);
148
- memcpy(handshake_buffer_ + offset, GRPC_SLICE_START_PTR(next_slice),
149
- GRPC_SLICE_LENGTH(next_slice));
150
- offset += GRPC_SLICE_LENGTH(next_slice);
151
- grpc_slice_unref_internal(next_slice);
147
+ grpc_slice* next_slice = grpc_slice_buffer_peek_first(args_->read_buffer);
148
+ memcpy(handshake_buffer_ + offset, GRPC_SLICE_START_PTR(*next_slice),
149
+ GRPC_SLICE_LENGTH(*next_slice));
150
+ offset += GRPC_SLICE_LENGTH(*next_slice);
151
+ grpc_slice_buffer_remove_first(args_->read_buffer);
152
152
  }
153
153
  return bytes_in_read_buffer;
154
154
  }
@@ -195,7 +195,7 @@ void SecurityHandshaker::HandshakeFailedLocked(grpc_error* error) {
195
195
  void SecurityHandshaker::OnPeerCheckedInner(grpc_error* error) {
196
196
  MutexLock lock(&mu_);
197
197
  if (error != GRPC_ERROR_NONE || is_shutdown_) {
198
- HandshakeFailedLocked(GRPC_ERROR_REF(error));
198
+ HandshakeFailedLocked(error);
199
199
  return;
200
200
  }
201
201
  // Create zero-copy frame protector, if implemented.
@@ -255,7 +255,7 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error* error) {
255
255
 
256
256
  void SecurityHandshaker::OnPeerCheckedFn(void* arg, grpc_error* error) {
257
257
  RefCountedPtr<SecurityHandshaker>(static_cast<SecurityHandshaker*>(arg))
258
- ->OnPeerCheckedInner(error);
258
+ ->OnPeerCheckedInner(GRPC_ERROR_REF(error));
259
259
  }
260
260
 
261
261
  grpc_error* SecurityHandshaker::CheckPeerLocked() {
@@ -23,7 +23,7 @@
23
23
 
24
24
  #include <grpc/slice.h>
25
25
 
26
- /* Encodes data using base64. It is the caller's responsability to free
26
+ /* Encodes data using base64. It is the caller's responsibility to free
27
27
  the returned char * using gpr_free. Returns NULL on NULL input.
28
28
  TODO(makdharma) : change the flags to bool from int */
29
29
  char* grpc_base64_encode(const void* data, size_t data_size, int url_safe,
@@ -35,7 +35,7 @@ size_t grpc_base64_estimate_encoded_size(size_t data_size, int url_safe,
35
35
  int multiline);
36
36
 
37
37
  /* Encodes data using base64 and write it to memory pointed to by result. It is
38
- * the caller's responsiblity to allocate enough memory in |result| to fit the
38
+ * the caller's responsibility to allocate enough memory in |result| to fit the
39
39
  * encoded data. */
40
40
  void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size,
41
41
  int url_safe, int multiline);
@@ -68,7 +68,8 @@ void grpc_slice_unref(grpc_slice slice) {
68
68
 
69
69
  /* grpc_slice_from_static_string support structure - a refcount that does
70
70
  nothing */
71
- static grpc_slice_refcount NoopRefcount;
71
+ static grpc_slice_refcount NoopRefcount =
72
+ grpc_slice_refcount(grpc_slice_refcount::Type::NOP);
72
73
 
73
74
  size_t grpc_slice_memory_usage(grpc_slice s) {
74
75
  if (s.refcount == nullptr || s.refcount == &NoopRefcount) {
@@ -101,18 +102,19 @@ class NewSliceRefcount {
101
102
  }
102
103
 
103
104
  NewSliceRefcount(void (*destroy)(void*), void* user_data)
104
- : rc_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this, &rc_),
105
+ : base_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this,
106
+ &base_),
105
107
  user_destroy_(destroy),
106
108
  user_data_(user_data) {}
107
109
 
108
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
110
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
109
111
 
110
- grpc_slice_refcount* base_refcount() { return &rc_; }
112
+ grpc_slice_refcount* base_refcount() { return &base_; }
111
113
 
112
114
  private:
113
115
  ~NewSliceRefcount() { user_destroy_(user_data_); }
114
116
 
115
- grpc_slice_refcount rc_;
117
+ grpc_slice_refcount base_;
116
118
  RefCount refs_;
117
119
  void (*user_destroy_)(void*);
118
120
  void* user_data_;
@@ -140,7 +142,6 @@ grpc_slice grpc_slice_new(void* p, size_t len, void (*destroy)(void*)) {
140
142
  namespace grpc_core {
141
143
  /* grpc_slice_new_with_len support structures - we create a refcount object
142
144
  extended with the user provided data pointer & destroy function */
143
-
144
145
  class NewWithLenSliceRefcount {
145
146
  public:
146
147
  static void Destroy(void* arg) {
@@ -149,25 +150,48 @@ class NewWithLenSliceRefcount {
149
150
 
150
151
  NewWithLenSliceRefcount(void (*destroy)(void*, size_t), void* user_data,
151
152
  size_t user_length)
152
- : rc_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this, &rc_),
153
+ : base_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this,
154
+ &base_),
153
155
  user_data_(user_data),
154
156
  user_length_(user_length),
155
157
  user_destroy_(destroy) {}
156
158
 
157
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
159
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
158
160
 
159
- grpc_slice_refcount* base_refcount() { return &rc_; }
161
+ grpc_slice_refcount* base_refcount() { return &base_; }
160
162
 
161
163
  private:
162
164
  ~NewWithLenSliceRefcount() { user_destroy_(user_data_, user_length_); }
163
165
 
164
- grpc_slice_refcount rc_;
166
+ grpc_slice_refcount base_;
165
167
  RefCount refs_;
166
168
  void* user_data_;
167
169
  size_t user_length_;
168
170
  void (*user_destroy_)(void*, size_t);
169
171
  };
170
172
 
173
+ /** grpc_slice_from_moved_(string|buffer) ref count .*/
174
+ class MovedStringSliceRefCount {
175
+ public:
176
+ MovedStringSliceRefCount(grpc_core::UniquePtr<char>&& str)
177
+ : base_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this,
178
+ &base_),
179
+ str_(std::move(str)) {}
180
+
181
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
182
+
183
+ grpc_slice_refcount* base_refcount() { return &base_; }
184
+
185
+ private:
186
+ static void Destroy(void* arg) {
187
+ Delete(static_cast<MovedStringSliceRefCount*>(arg));
188
+ }
189
+
190
+ grpc_slice_refcount base_;
191
+ grpc_core::RefCount refs_;
192
+ grpc_core::UniquePtr<char> str_;
193
+ };
194
+
171
195
  } // namespace grpc_core
172
196
 
173
197
  grpc_slice grpc_slice_new_with_len(void* p, size_t len,
@@ -192,6 +216,29 @@ grpc_slice grpc_slice_from_copied_string(const char* source) {
192
216
  return grpc_slice_from_copied_buffer(source, strlen(source));
193
217
  }
194
218
 
219
+ grpc_slice grpc_slice_from_moved_buffer(grpc_core::UniquePtr<char> p,
220
+ size_t len) {
221
+ uint8_t* ptr = reinterpret_cast<uint8_t*>(p.get());
222
+ grpc_slice slice;
223
+ if (len <= sizeof(slice.data.inlined.bytes)) {
224
+ slice.refcount = nullptr;
225
+ slice.data.inlined.length = len;
226
+ memcpy(GRPC_SLICE_START_PTR(slice), ptr, len);
227
+ } else {
228
+ slice.refcount =
229
+ grpc_core::New<grpc_core::MovedStringSliceRefCount>(std::move(p))
230
+ ->base_refcount();
231
+ slice.data.refcounted.bytes = ptr;
232
+ slice.data.refcounted.length = len;
233
+ }
234
+ return slice;
235
+ }
236
+
237
+ grpc_slice grpc_slice_from_moved_string(grpc_core::UniquePtr<char> p) {
238
+ const size_t len = strlen(p.get());
239
+ return grpc_slice_from_moved_buffer(std::move(p), len);
240
+ }
241
+
195
242
  namespace {
196
243
 
197
244
  class MallocRefCount {
@@ -410,6 +457,31 @@ int grpc_slice_eq(grpc_slice a, grpc_slice b) {
410
457
  return grpc_slice_default_eq_impl(a, b);
411
458
  }
412
459
 
460
+ int grpc_slice_differs_refcounted(const grpc_slice& a,
461
+ const grpc_slice& b_not_inline) {
462
+ size_t a_len;
463
+ const uint8_t* a_ptr;
464
+ if (a.refcount) {
465
+ a_len = a.data.refcounted.length;
466
+ a_ptr = a.data.refcounted.bytes;
467
+ } else {
468
+ a_len = a.data.inlined.length;
469
+ a_ptr = &a.data.inlined.bytes[0];
470
+ }
471
+ if (a_len != b_not_inline.data.refcounted.length) {
472
+ return true;
473
+ }
474
+ if (a_len == 0) {
475
+ return false;
476
+ }
477
+ // This check *must* occur after the a_len == 0 check
478
+ // to retain compatibility with grpc_slice_eq.
479
+ if (a_ptr == nullptr) {
480
+ return true;
481
+ }
482
+ return memcmp(a_ptr, b_not_inline.data.refcounted.bytes, a_len);
483
+ }
484
+
413
485
  int grpc_slice_cmp(grpc_slice a, grpc_slice b) {
414
486
  int d = static_cast<int>(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b));
415
487
  if (d != 0) return d;