grpc 1.15.0 → 1.16.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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +158 -80
  3. data/etc/roots.pem +23 -0
  4. data/include/grpc/grpc.h +13 -1
  5. data/include/grpc/grpc_security.h +2 -2
  6. data/include/grpc/grpc_security_constants.h +24 -19
  7. data/include/grpc/impl/codegen/grpc_types.h +23 -5
  8. data/include/grpc/impl/codegen/port_platform.h +1 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +95 -10
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +71 -0
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +45 -11
  12. data/src/core/ext/filters/client_channel/connector.h +3 -0
  13. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -3
  15. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -32
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +20 -15
  18. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -4
  19. data/src/core/ext/filters/client_channel/parse_address.cc +27 -4
  20. data/src/core/ext/filters/client_channel/parse_address.h +3 -0
  21. data/src/core/ext/filters/client_channel/resolver.h +1 -12
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -11
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -19
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +9 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +5 -0
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +70 -0
  27. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -11
  28. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -16
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +0 -7
  31. data/src/core/ext/filters/client_channel/subchannel.cc +45 -7
  32. data/src/core/ext/filters/client_channel/subchannel.h +16 -1
  33. data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -1
  34. data/src/core/ext/filters/client_channel/subchannel_index.h +1 -4
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +32 -3
  36. data/src/core/ext/filters/http/server/http_server_filter.cc +59 -1
  37. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -2
  38. data/src/core/ext/filters/message_size/message_size_filter.cc +59 -3
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
  40. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  41. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +286 -228
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
  44. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -0
  45. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +14 -3
  46. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +29 -0
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -0
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -0
  49. data/src/core/ext/transport/chttp2/transport/parsing.cc +85 -54
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -0
  51. data/src/core/lib/channel/channel_trace.cc +51 -56
  52. data/src/core/lib/channel/channel_trace.h +30 -25
  53. data/src/core/lib/channel/channelz.cc +235 -61
  54. data/src/core/lib/channel/channelz.h +179 -48
  55. data/src/core/lib/channel/channelz_registry.cc +95 -23
  56. data/src/core/lib/channel/channelz_registry.h +15 -42
  57. data/src/core/lib/gpr/sync_posix.cc +42 -0
  58. data/src/core/lib/http/httpcli.cc +1 -1
  59. data/src/core/lib/iomgr/buffer_list.cc +134 -0
  60. data/src/core/lib/iomgr/buffer_list.h +96 -0
  61. data/src/core/lib/iomgr/endpoint.cc +2 -2
  62. data/src/core/lib/iomgr/endpoint.h +6 -2
  63. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  64. data/src/core/lib/iomgr/error.cc +29 -18
  65. data/src/core/lib/iomgr/error.h +8 -0
  66. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  67. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  68. data/src/core/lib/iomgr/ev_posix.cc +16 -10
  69. data/src/core/lib/iomgr/exec_ctx.h +0 -7
  70. data/src/core/lib/iomgr/{ev_epollsig_linux.h → internal_errqueue.cc} +13 -12
  71. data/src/core/lib/iomgr/internal_errqueue.h +83 -0
  72. data/src/core/lib/iomgr/port.h +11 -2
  73. data/src/core/lib/iomgr/socket_utils_common_posix.cc +90 -0
  74. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  75. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
  76. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  77. data/src/core/lib/iomgr/tcp_posix.cc +306 -13
  78. data/src/core/lib/iomgr/tcp_posix.h +3 -0
  79. data/src/core/lib/iomgr/tcp_server_posix.cc +2 -2
  80. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +4 -1
  81. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  82. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  83. data/src/core/lib/iomgr/timer_heap.cc +2 -2
  84. data/src/core/lib/iomgr/timer_heap.h +3 -3
  85. data/src/core/lib/iomgr/timer_manager.cc +28 -3
  86. data/src/core/lib/iomgr/timer_manager.h +2 -2
  87. data/src/core/lib/iomgr/udp_server.cc +1 -1
  88. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +2 -1
  89. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +2 -1
  90. data/src/core/lib/security/security_connector/security_connector.cc +7 -7
  91. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  92. data/src/core/lib/security/transport/security_handshaker.cc +1 -1
  93. data/src/core/lib/security/transport/server_auth_filter.cc +53 -4
  94. data/src/core/lib/slice/slice.cc +8 -0
  95. data/src/core/lib/slice/slice_internal.h +5 -0
  96. data/src/core/lib/surface/call.cc +149 -253
  97. data/src/core/lib/surface/call.h +1 -0
  98. data/src/core/lib/surface/channel.cc +17 -13
  99. data/src/core/lib/surface/completion_queue.cc +21 -17
  100. data/src/core/lib/surface/completion_queue.h +1 -18
  101. data/src/core/lib/surface/completion_queue_factory.cc +3 -3
  102. data/src/core/lib/surface/init_secure.cc +1 -1
  103. data/src/core/lib/surface/server.cc +77 -4
  104. data/src/core/lib/surface/server.h +4 -0
  105. data/src/core/lib/surface/version.cc +2 -2
  106. data/src/core/lib/transport/metadata.cc +0 -18
  107. data/src/core/lib/transport/metadata.h +0 -3
  108. data/src/core/lib/transport/metadata_batch.cc +2 -2
  109. data/src/core/lib/transport/metadata_batch.h +2 -0
  110. data/src/core/lib/transport/static_metadata.cc +220 -249
  111. data/src/core/lib/transport/static_metadata.h +189 -191
  112. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  113. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +3 -1
  114. data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +4 -2
  115. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +6 -5
  116. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -1
  117. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +2 -2
  118. data/src/core/tsi/alts_transport_security.cc +3 -1
  119. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +2 -1
  120. data/src/ruby/ext/grpc/rb_call.c +1 -0
  121. data/src/ruby/ext/grpc/rb_channel.c +3 -0
  122. data/src/ruby/ext/grpc/rb_grpc.c +31 -1
  123. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  124. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  125. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +12 -3
  126. data/src/ruby/ext/grpc/rb_server.c +2 -0
  127. data/src/ruby/lib/grpc/errors.rb +0 -1
  128. data/src/ruby/lib/grpc/generic/rpc_desc.rb +3 -3
  129. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  130. data/src/ruby/lib/grpc/version.rb +1 -1
  131. data/src/ruby/spec/channel_spec.rb +44 -0
  132. data/src/ruby/spec/client_auth_spec.rb +5 -5
  133. data/src/ruby/spec/generic/client_stub_spec.rb +13 -9
  134. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  135. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -0
  136. data/src/ruby/spec/support/services.rb +28 -22
  137. metadata +35 -31
  138. data/src/core/lib/iomgr/ev_epollsig_linux.cc +0 -1743
@@ -33,6 +33,7 @@ typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success,
33
33
 
34
34
  typedef struct grpc_call_create_args {
35
35
  grpc_channel* channel;
36
+ grpc_server* server;
36
37
 
37
38
  grpc_call* parent;
38
39
  uint32_t propagation_mask;
@@ -100,11 +100,10 @@ grpc_channel* grpc_channel_create_with_builder(
100
100
  return channel;
101
101
  }
102
102
 
103
- memset(channel, 0, sizeof(*channel));
104
103
  channel->target = target;
105
104
  channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type);
106
- size_t channel_tracer_max_nodes = 0; // default to off
107
- bool channelz_enabled = false;
105
+ bool channelz_enabled = GRPC_ENABLE_CHANNELZ_DEFAULT;
106
+ size_t channel_tracer_max_memory = 0; // default to off
108
107
  bool internal_channel = false;
109
108
  // this creates the default ChannelNode. Different types of channels may
110
109
  // override this to ensure a correct ChannelNode is created.
@@ -142,16 +141,17 @@ grpc_channel* grpc_channel_create_with_builder(
142
141
  static_cast<uint32_t>(args->args[i].value.integer) |
143
142
  0x1; /* always support no compression */
144
143
  } else if (0 == strcmp(args->args[i].key,
145
- GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE)) {
146
- GPR_ASSERT(channel_tracer_max_nodes == 0);
147
- // max_nodes defaults to 0 (which is off), clamped between 0 and INT_MAX
148
- const grpc_integer_options options = {0, 0, INT_MAX};
149
- channel_tracer_max_nodes =
144
+ GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE)) {
145
+ GPR_ASSERT(channel_tracer_max_memory == 0);
146
+ const grpc_integer_options options = {
147
+ GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX};
148
+ channel_tracer_max_memory =
150
149
  (size_t)grpc_channel_arg_get_integer(&args->args[i], options);
151
150
  } else if (0 == strcmp(args->args[i].key, GRPC_ARG_ENABLE_CHANNELZ)) {
152
151
  // channelz will not be enabled by default until all concerns in
153
152
  // https://github.com/grpc/grpc/issues/15986 are addressed.
154
- channelz_enabled = grpc_channel_arg_get_bool(&args->args[i], false);
153
+ channelz_enabled = grpc_channel_arg_get_bool(
154
+ &args->args[i], GRPC_ENABLE_CHANNELZ_DEFAULT);
155
155
  } else if (0 == strcmp(args->args[i].key,
156
156
  GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC)) {
157
157
  GPR_ASSERT(args->args[i].type == GRPC_ARG_POINTER);
@@ -166,11 +166,12 @@ grpc_channel* grpc_channel_create_with_builder(
166
166
  }
167
167
 
168
168
  grpc_channel_args_destroy(args);
169
- if (channelz_enabled) {
170
- bool is_top_level_channel = channel->is_client && !internal_channel;
169
+ // we only need to do the channelz bookkeeping for clients here. The channelz
170
+ // bookkeeping for server channels occurs in src/core/lib/surface/server.cc
171
+ if (channelz_enabled && channel->is_client) {
171
172
  channel->channelz_channel = channel_node_create_func(
172
- channel, channel_tracer_max_nodes, is_top_level_channel);
173
- channel->channelz_channel->trace()->AddTraceEvent(
173
+ channel, channel_tracer_max_memory, !internal_channel);
174
+ channel->channelz_channel->AddTraceEvent(
174
175
  grpc_core::channelz::ChannelTrace::Severity::Info,
175
176
  grpc_slice_from_static_string("Channel created"));
176
177
  }
@@ -428,6 +429,9 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) {
428
429
  static void destroy_channel(void* arg, grpc_error* error) {
429
430
  grpc_channel* channel = static_cast<grpc_channel*>(arg);
430
431
  if (channel->channelz_channel != nullptr) {
432
+ channel->channelz_channel->AddTraceEvent(
433
+ grpc_core::channelz::ChannelTrace::Severity::Info,
434
+ grpc_slice_from_static_string("Channel destroyed"));
431
435
  channel->channelz_channel->MarkChannelDestroyed();
432
436
  channel->channelz_channel.reset();
433
437
  }
@@ -184,7 +184,8 @@ static const cq_poller_vtable g_poller_vtable_by_poller_type[] = {
184
184
  typedef struct cq_vtable {
185
185
  grpc_cq_completion_type cq_completion_type;
186
186
  size_t data_size;
187
- void (*init)(void* data, grpc_core::CQCallbackInterface* shutdown_callback);
187
+ void (*init)(void* data,
188
+ grpc_experimental_completion_queue_functor* shutdown_callback);
188
189
  void (*shutdown)(grpc_completion_queue* cq);
189
190
  void (*destroy)(void* data);
190
191
  bool (*begin_op)(grpc_completion_queue* cq, void* tag);
@@ -267,7 +268,7 @@ typedef struct cq_callback_data {
267
268
  bool shutdown_called;
268
269
 
269
270
  /** A callback that gets invoked when the CQ completes shutdown */
270
- grpc_core::CQCallbackInterface* shutdown_callback;
271
+ grpc_experimental_completion_queue_functor* shutdown_callback;
271
272
  } cq_callback_data;
272
273
 
273
274
  /* Completion queue structure */
@@ -333,12 +334,12 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
333
334
  gpr_timespec deadline, void* reserved);
334
335
 
335
336
  // Note that cq_init_next and cq_init_pluck do not use the shutdown_callback
336
- static void cq_init_next(void* data,
337
- grpc_core::CQCallbackInterface* shutdown_callback);
338
- static void cq_init_pluck(void* data,
339
- grpc_core::CQCallbackInterface* shutdown_callback);
340
- static void cq_init_callback(void* data,
341
- grpc_core::CQCallbackInterface* shutdown_callback);
337
+ static void cq_init_next(
338
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback);
339
+ static void cq_init_pluck(
340
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback);
341
+ static void cq_init_callback(
342
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback);
342
343
  static void cq_destroy_next(void* data);
343
344
  static void cq_destroy_pluck(void* data);
344
345
  static void cq_destroy_callback(void* data);
@@ -462,7 +463,7 @@ static long cq_event_queue_num_items(grpc_cq_event_queue* q) {
462
463
 
463
464
  grpc_completion_queue* grpc_completion_queue_create_internal(
464
465
  grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
465
- grpc_core::CQCallbackInterface* shutdown_callback) {
466
+ grpc_experimental_completion_queue_functor* shutdown_callback) {
466
467
  GPR_TIMER_SCOPE("grpc_completion_queue_create_internal", 0);
467
468
 
468
469
  grpc_completion_queue* cq;
@@ -497,8 +498,8 @@ grpc_completion_queue* grpc_completion_queue_create_internal(
497
498
  return cq;
498
499
  }
499
500
 
500
- static void cq_init_next(void* data,
501
- grpc_core::CQCallbackInterface* shutdown_callback) {
501
+ static void cq_init_next(
502
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback) {
502
503
  cq_next_data* cqd = static_cast<cq_next_data*>(data);
503
504
  /* Initial count is dropped by grpc_completion_queue_shutdown */
504
505
  gpr_atm_no_barrier_store(&cqd->pending_events, 1);
@@ -513,8 +514,8 @@ static void cq_destroy_next(void* data) {
513
514
  cq_event_queue_destroy(&cqd->queue);
514
515
  }
515
516
 
516
- static void cq_init_pluck(void* data,
517
- grpc_core::CQCallbackInterface* shutdown_callback) {
517
+ static void cq_init_pluck(
518
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback) {
518
519
  cq_pluck_data* cqd = static_cast<cq_pluck_data*>(data);
519
520
  /* Initial count is dropped by grpc_completion_queue_shutdown */
520
521
  gpr_atm_no_barrier_store(&cqd->pending_events, 1);
@@ -532,7 +533,7 @@ static void cq_destroy_pluck(void* data) {
532
533
  }
533
534
 
534
535
  static void cq_init_callback(
535
- void* data, grpc_core::CQCallbackInterface* shutdown_callback) {
536
+ void* data, grpc_experimental_completion_queue_functor* shutdown_callback) {
536
537
  cq_callback_data* cqd = static_cast<cq_callback_data*>(data);
537
538
  /* Initial count is dropped by grpc_completion_queue_shutdown */
538
539
  gpr_atm_no_barrier_store(&cqd->pending_events, 1);
@@ -859,7 +860,8 @@ static void cq_end_op_for_callback(
859
860
 
860
861
  GRPC_ERROR_UNREF(error);
861
862
 
862
- (static_cast<grpc_core::CQCallbackInterface*>(tag))->Run(is_success);
863
+ auto* functor = static_cast<grpc_experimental_completion_queue_functor*>(tag);
864
+ (*functor->functor_run)(functor, is_success);
863
865
  }
864
866
 
865
867
  void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error,
@@ -1343,7 +1345,7 @@ static void cq_finish_shutdown_callback(grpc_completion_queue* cq) {
1343
1345
  GPR_ASSERT(cqd->shutdown_called);
1344
1346
 
1345
1347
  cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done);
1346
- callback->Run(true);
1348
+ (*callback->functor_run)(callback, true);
1347
1349
  }
1348
1350
 
1349
1351
  static void cq_shutdown_callback(grpc_completion_queue* cq) {
@@ -1364,9 +1366,11 @@ static void cq_shutdown_callback(grpc_completion_queue* cq) {
1364
1366
  }
1365
1367
  cqd->shutdown_called = true;
1366
1368
  if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) {
1369
+ gpr_mu_unlock(cq->mu);
1367
1370
  cq_finish_shutdown_callback(cq);
1371
+ } else {
1372
+ gpr_mu_unlock(cq->mu);
1368
1373
  }
1369
- gpr_mu_unlock(cq->mu);
1370
1374
  GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (callback cq)");
1371
1375
  }
1372
1376
 
@@ -48,23 +48,6 @@ typedef struct grpc_cq_completion {
48
48
  uintptr_t next;
49
49
  } grpc_cq_completion;
50
50
 
51
- /// For callback CQs, the tag that is passed in for an operation must
52
- /// actually be a pointer to an implementation of the following class.
53
- /// When the operation completes, the tag will be typecasted from void*
54
- /// to grpc_core::CQCallbackInterface* and then the Run method will be
55
- /// invoked on it. In practice, the language binding (e.g., C++ API
56
- /// implementation) is responsible for providing and using an implementation
57
- /// of this abstract base class.
58
- namespace grpc_core {
59
- class CQCallbackInterface {
60
- public:
61
- virtual ~CQCallbackInterface() {}
62
- virtual void Run(bool) GRPC_ABSTRACT;
63
-
64
- GRPC_ABSTRACT_BASE_CLASS
65
- };
66
- } // namespace grpc_core
67
-
68
51
  #ifndef NDEBUG
69
52
  void grpc_cq_internal_ref(grpc_completion_queue* cc, const char* reason,
70
53
  const char* file, int line);
@@ -106,6 +89,6 @@ int grpc_get_cq_poll_num(grpc_completion_queue* cc);
106
89
 
107
90
  grpc_completion_queue* grpc_completion_queue_create_internal(
108
91
  grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
109
- grpc_core::CQCallbackInterface* shutdown_callback);
92
+ grpc_experimental_completion_queue_functor* shutdown_callback);
110
93
 
111
94
  #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */
@@ -31,8 +31,7 @@ static grpc_completion_queue* default_create(
31
31
  const grpc_completion_queue_factory* factory,
32
32
  const grpc_completion_queue_attributes* attr) {
33
33
  return grpc_completion_queue_create_internal(
34
- attr->cq_completion_type, attr->cq_polling_type,
35
- static_cast<grpc_core::CQCallbackInterface*>(attr->cq_shutdown_cb));
34
+ attr->cq_completion_type, attr->cq_polling_type, attr->cq_shutdown_cb);
36
35
  }
37
36
 
38
37
  static grpc_completion_queue_factory_vtable default_vtable = {default_create};
@@ -73,7 +72,8 @@ grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) {
73
72
  }
74
73
 
75
74
  grpc_completion_queue* grpc_completion_queue_create_for_callback(
76
- void* shutdown_callback, void* reserved) {
75
+ grpc_experimental_completion_queue_functor* shutdown_callback,
76
+ void* reserved) {
77
77
  GPR_ASSERT(!reserved);
78
78
  grpc_completion_queue_attributes attr = {
79
79
  2, GRPC_CQ_CALLBACK, GRPC_CQ_DEFAULT_POLLING, shutdown_callback};
@@ -74,7 +74,7 @@ void grpc_register_security_filters(void) {
74
74
  maybe_prepend_client_auth_filter, nullptr);
75
75
  grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX - 1,
76
76
  maybe_prepend_client_auth_filter, nullptr);
77
- grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
77
+ grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX - 1,
78
78
  maybe_prepend_server_auth_filter, nullptr);
79
79
  }
80
80
 
@@ -149,10 +149,16 @@ struct call_data {
149
149
  grpc_closure server_on_recv_initial_metadata;
150
150
  grpc_closure kill_zombie_closure;
151
151
  grpc_closure* on_done_recv_initial_metadata;
152
+ grpc_closure recv_trailing_metadata_ready;
153
+ grpc_error* recv_initial_metadata_error;
154
+ grpc_closure* original_recv_trailing_metadata_ready;
155
+ grpc_error* recv_trailing_metadata_error;
156
+ bool seen_recv_trailing_metadata_ready;
152
157
 
153
158
  grpc_closure publish;
154
159
 
155
160
  call_data* pending_next;
161
+ grpc_call_combiner* call_combiner;
156
162
  };
157
163
 
158
164
  struct request_matcher {
@@ -219,6 +225,8 @@ struct grpc_server {
219
225
 
220
226
  /** when did we print the last shutdown progress message */
221
227
  gpr_timespec last_shutdown_message_time;
228
+
229
+ grpc_core::RefCountedPtr<grpc_core::channelz::ServerNode> channelz_server;
222
230
  };
223
231
 
224
232
  #define SERVER_FROM_CALL_ELEM(elem) \
@@ -364,6 +372,7 @@ static void server_ref(grpc_server* server) {
364
372
  static void server_delete(grpc_server* server) {
365
373
  registered_method* rm;
366
374
  size_t i;
375
+ server->channelz_server.reset();
367
376
  grpc_channel_args_destroy(server->channel_args);
368
377
  gpr_mu_destroy(&server->mu_global);
369
378
  gpr_mu_destroy(&server->mu_call);
@@ -721,13 +730,43 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
721
730
  if (calld->host_set && calld->path_set) {
722
731
  /* do nothing */
723
732
  } else {
733
+ /* Pass the error reference to calld->recv_initial_metadata_error */
724
734
  grpc_error* src_error = error;
725
735
  error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
726
- "Missing :authority or :path", &error, 1);
736
+ "Missing :authority or :path", &src_error, 1);
727
737
  GRPC_ERROR_UNREF(src_error);
738
+ calld->recv_initial_metadata_error = GRPC_ERROR_REF(error);
739
+ }
740
+ grpc_closure* closure = calld->on_done_recv_initial_metadata;
741
+ calld->on_done_recv_initial_metadata = nullptr;
742
+ if (calld->seen_recv_trailing_metadata_ready) {
743
+ GRPC_CALL_COMBINER_START(calld->call_combiner,
744
+ &calld->recv_trailing_metadata_ready,
745
+ calld->recv_trailing_metadata_error,
746
+ "continue server_recv_trailing_metadata_ready");
728
747
  }
748
+ GRPC_CLOSURE_RUN(closure, error);
749
+ }
729
750
 
730
- GRPC_CLOSURE_RUN(calld->on_done_recv_initial_metadata, error);
751
+ static void server_recv_trailing_metadata_ready(void* user_data,
752
+ grpc_error* error) {
753
+ grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
754
+ call_data* calld = static_cast<call_data*>(elem->call_data);
755
+ if (calld->on_done_recv_initial_metadata != nullptr) {
756
+ calld->recv_trailing_metadata_error = GRPC_ERROR_REF(error);
757
+ calld->seen_recv_trailing_metadata_ready = true;
758
+ GRPC_CLOSURE_INIT(&calld->recv_trailing_metadata_ready,
759
+ server_recv_trailing_metadata_ready, elem,
760
+ grpc_schedule_on_exec_ctx);
761
+ GRPC_CALL_COMBINER_STOP(calld->call_combiner,
762
+ "deferring server_recv_trailing_metadata_ready "
763
+ "until after server_on_recv_initial_metadata");
764
+ return;
765
+ }
766
+ error =
767
+ grpc_error_add_child(GRPC_ERROR_REF(error),
768
+ GRPC_ERROR_REF(calld->recv_initial_metadata_error));
769
+ GRPC_CLOSURE_RUN(calld->original_recv_trailing_metadata_ready, error);
731
770
  }
732
771
 
733
772
  static void server_mutate_op(grpc_call_element* elem,
@@ -745,6 +784,12 @@ static void server_mutate_op(grpc_call_element* elem,
745
784
  op->payload->recv_initial_metadata.recv_flags =
746
785
  &calld->recv_initial_metadata_flags;
747
786
  }
787
+ if (op->recv_trailing_metadata) {
788
+ calld->original_recv_trailing_metadata_ready =
789
+ op->payload->recv_trailing_metadata.recv_trailing_metadata_ready;
790
+ op->payload->recv_trailing_metadata.recv_trailing_metadata_ready =
791
+ &calld->recv_trailing_metadata_ready;
792
+ }
748
793
  }
749
794
 
750
795
  static void server_start_transport_stream_op_batch(
@@ -779,6 +824,7 @@ static void accept_stream(void* cd, grpc_transport* transport,
779
824
  args.channel = chand->channel;
780
825
  args.server_transport_data = transport_server_data;
781
826
  args.send_deadline = GRPC_MILLIS_INF_FUTURE;
827
+ args.server = chand->server;
782
828
  grpc_call* call;
783
829
  grpc_error* error = grpc_call_create(&args, &call);
784
830
  grpc_call_element* elem =
@@ -824,11 +870,14 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
824
870
  memset(calld, 0, sizeof(call_data));
825
871
  calld->deadline = GRPC_MILLIS_INF_FUTURE;
826
872
  calld->call = grpc_call_from_top_element(elem);
873
+ calld->call_combiner = args->call_combiner;
827
874
 
828
875
  GRPC_CLOSURE_INIT(&calld->server_on_recv_initial_metadata,
829
876
  server_on_recv_initial_metadata, elem,
830
877
  grpc_schedule_on_exec_ctx);
831
-
878
+ GRPC_CLOSURE_INIT(&calld->recv_trailing_metadata_ready,
879
+ server_recv_trailing_metadata_ready, elem,
880
+ grpc_schedule_on_exec_ctx);
832
881
  server_ref(chand->server);
833
882
  return GRPC_ERROR_NONE;
834
883
  }
@@ -840,7 +889,7 @@ static void destroy_call_elem(grpc_call_element* elem,
840
889
  call_data* calld = static_cast<call_data*>(elem->call_data);
841
890
 
842
891
  GPR_ASSERT(calld->state != PENDING);
843
-
892
+ GRPC_ERROR_UNREF(calld->recv_initial_metadata_error);
844
893
  if (calld->host_set) {
845
894
  grpc_slice_unref_internal(calld->host);
846
895
  }
@@ -941,6 +990,7 @@ void grpc_server_register_completion_queue(grpc_server* server,
941
990
  }
942
991
 
943
992
  grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
993
+ grpc_core::ExecCtx exec_ctx;
944
994
  GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
945
995
 
946
996
  grpc_server* server =
@@ -957,6 +1007,21 @@ grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
957
1007
 
958
1008
  server->channel_args = grpc_channel_args_copy(args);
959
1009
 
1010
+ const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_ENABLE_CHANNELZ);
1011
+ if (grpc_channel_arg_get_bool(arg, GRPC_ENABLE_CHANNELZ_DEFAULT)) {
1012
+ arg = grpc_channel_args_find(
1013
+ args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE);
1014
+ size_t channel_tracer_max_memory = grpc_channel_arg_get_integer(
1015
+ arg,
1016
+ {GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
1017
+ server->channelz_server =
1018
+ grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
1019
+ channel_tracer_max_memory);
1020
+ server->channelz_server->AddTraceEvent(
1021
+ grpc_core::channelz::ChannelTrace::Severity::Info,
1022
+ grpc_slice_from_static_string("Server created"));
1023
+ }
1024
+
960
1025
  return server;
961
1026
  }
962
1027
 
@@ -1459,3 +1524,11 @@ int grpc_server_has_open_connections(grpc_server* server) {
1459
1524
  gpr_mu_unlock(&server->mu_global);
1460
1525
  return r;
1461
1526
  }
1527
+
1528
+ grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
1529
+ grpc_server* server) {
1530
+ if (server == nullptr) {
1531
+ return nullptr;
1532
+ }
1533
+ return server->channelz_server.get();
1534
+ }
@@ -23,6 +23,7 @@
23
23
 
24
24
  #include <grpc/grpc.h>
25
25
  #include "src/core/lib/channel/channel_stack.h"
26
+ #include "src/core/lib/channel/channelz.h"
26
27
  #include "src/core/lib/debug/trace.h"
27
28
  #include "src/core/lib/transport/transport.h"
28
29
 
@@ -46,6 +47,9 @@ void grpc_server_setup_transport(grpc_server* server, grpc_transport* transport,
46
47
  grpc_pollset* accepting_pollset,
47
48
  const grpc_channel_args* args);
48
49
 
50
+ grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
51
+ grpc_server* server);
52
+
49
53
  const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server);
50
54
 
51
55
  int grpc_server_has_open_connections(grpc_server* server);
@@ -23,6 +23,6 @@
23
23
 
24
24
  #include <grpc/grpc.h>
25
25
 
26
- const char* grpc_version_string(void) { return "6.0.0"; }
26
+ const char* grpc_version_string(void) { return "6.0.0-pre1"; }
27
27
 
28
- const char* grpc_g_stands_for(void) { return "glider"; }
28
+ const char* grpc_g_stands_for(void) { return "gao"; }
@@ -342,24 +342,6 @@ grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) {
342
342
  changed ? nullptr : reinterpret_cast<grpc_mdelem_data*>(metadata));
343
343
  }
344
344
 
345
- static size_t get_base64_encoded_size(size_t raw_length) {
346
- static const uint8_t tail_xtra[3] = {0, 2, 3};
347
- return raw_length / 3 * 4 + tail_xtra[raw_length % 3];
348
- }
349
-
350
- size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem,
351
- bool use_true_binary_metadata) {
352
- size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(GRPC_MDKEY(elem));
353
- size_t value_len = GRPC_SLICE_LENGTH(GRPC_MDVALUE(elem));
354
- if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
355
- return overhead_and_key + (use_true_binary_metadata
356
- ? value_len + 1
357
- : get_base64_encoded_size(value_len));
358
- } else {
359
- return overhead_and_key + value_len;
360
- }
361
- }
362
-
363
345
  grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) {
364
346
  switch (GRPC_MDELEM_STORAGE(gmd)) {
365
347
  case GRPC_MDELEM_STORAGE_EXTERNAL: