wearefair-grpc 1.3.1.pre.c → 1.4.0.fair

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +418 -126
  3. data/include/grpc/grpc.h +15 -69
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/compression_types.h +3 -4
  6. data/include/grpc/impl/codegen/gpr_types.h +0 -1
  7. data/include/grpc/impl/codegen/grpc_types.h +69 -3
  8. data/include/grpc/impl/codegen/port_platform.h +6 -0
  9. data/include/grpc/impl/codegen/slice.h +2 -1
  10. data/include/grpc/load_reporting.h +6 -6
  11. data/include/grpc/slice.h +25 -3
  12. data/include/grpc/slice_buffer.h +4 -0
  13. data/src/core/ext/census/context.c +1 -1
  14. data/src/core/ext/census/resource.c +3 -1
  15. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  16. data/src/core/ext/filters/client_channel/client_channel.c +158 -100
  17. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  18. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  19. data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  29. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  33. data/src/core/ext/filters/client_channel/parse_address.c +37 -7
  34. data/src/core/ext/filters/client_channel/parse_address.h +11 -8
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  36. data/src/core/ext/filters/client_channel/subchannel.c +19 -16
  37. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  38. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  39. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  40. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  41. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  42. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  43. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  44. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  45. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  46. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  47. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  48. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  49. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  50. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  51. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  52. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  53. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  54. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  57. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  58. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
  59. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  60. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  61. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  62. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  63. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  66. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  69. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  70. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  71. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  72. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  73. data/src/core/lib/channel/channel_args.c +28 -9
  74. data/src/core/lib/channel/channel_args.h +5 -1
  75. data/src/core/lib/channel/channel_stack.c +1 -1
  76. data/src/core/lib/channel/channel_stack.h +2 -2
  77. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  78. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  79. data/src/core/lib/channel/connected_channel.c +3 -1
  80. data/src/core/lib/channel/context.h +2 -2
  81. data/src/core/lib/compression/message_compress.c +2 -2
  82. data/src/core/lib/debug/trace.c +13 -6
  83. data/src/core/lib/debug/trace.h +27 -1
  84. data/src/core/lib/http/httpcli.c +1 -1
  85. data/src/core/lib/http/httpcli_security_connector.c +6 -10
  86. data/src/core/lib/http/parser.c +2 -2
  87. data/src/core/lib/http/parser.h +2 -1
  88. data/src/core/lib/iomgr/combiner.c +6 -6
  89. data/src/core/lib/iomgr/combiner.h +2 -1
  90. data/src/core/lib/iomgr/error.c +12 -5
  91. data/src/core/lib/iomgr/error.h +13 -13
  92. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  93. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  94. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  95. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  96. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  97. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  98. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  99. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  100. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
  101. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  102. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  103. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  104. data/src/core/lib/iomgr/ev_posix.c +22 -8
  105. data/src/core/lib/iomgr/ev_posix.h +4 -3
  106. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  107. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  108. data/src/core/lib/iomgr/iomgr.c +4 -0
  109. data/src/core/lib/iomgr/iomgr.h +3 -0
  110. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  111. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  112. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  113. data/src/core/lib/iomgr/pollset.h +2 -5
  114. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  115. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  116. data/src/core/lib/iomgr/resource_quota.c +9 -8
  117. data/src/core/lib/iomgr/resource_quota.h +2 -1
  118. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  119. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  120. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  121. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  122. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  123. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  124. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  125. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  126. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  127. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  128. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  129. data/src/core/lib/iomgr/timer_generic.c +24 -25
  130. data/src/core/lib/iomgr/timer_manager.c +276 -0
  131. data/src/core/lib/iomgr/timer_manager.h +52 -0
  132. data/src/core/lib/iomgr/timer_uv.c +6 -0
  133. data/src/core/lib/iomgr/udp_server.c +42 -9
  134. data/src/core/lib/iomgr/udp_server.h +3 -1
  135. data/src/core/lib/security/credentials/credentials.c +0 -1
  136. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  137. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  138. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  139. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  140. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  141. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  142. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  143. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  144. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  145. data/src/core/lib/security/transport/security_connector.c +32 -51
  146. data/src/core/lib/security/transport/security_connector.h +10 -14
  147. data/src/core/lib/slice/b64.c +1 -1
  148. data/src/core/lib/slice/percent_encoding.c +3 -3
  149. data/src/core/lib/slice/slice.c +66 -33
  150. data/src/core/lib/slice/slice_buffer.c +25 -6
  151. data/src/core/lib/slice/slice_hash_table.c +33 -35
  152. data/src/core/lib/slice/slice_hash_table.h +7 -12
  153. data/src/core/lib/support/atomic.h +45 -0
  154. data/src/core/lib/support/atomic_with_atm.h +70 -0
  155. data/src/core/lib/support/atomic_with_std.h +48 -0
  156. data/src/core/lib/support/avl.c +14 -14
  157. data/src/core/lib/support/memory.h +74 -0
  158. data/src/core/lib/support/mpscq.c +12 -1
  159. data/src/core/lib/support/mpscq.h +4 -0
  160. data/src/core/lib/support/stack_lockfree.c +3 -36
  161. data/src/core/lib/support/time_posix.c +8 -0
  162. data/src/core/lib/support/tmpfile_posix.c +10 -10
  163. data/src/core/lib/surface/alarm.c +3 -1
  164. data/src/core/lib/surface/api_trace.c +2 -1
  165. data/src/core/lib/surface/api_trace.h +2 -2
  166. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  167. data/src/core/lib/surface/call.c +65 -22
  168. data/src/core/lib/surface/call.h +4 -2
  169. data/src/core/lib/surface/channel_init.c +2 -19
  170. data/src/core/lib/surface/channel_stack_type.c +18 -0
  171. data/src/core/lib/surface/channel_stack_type.h +2 -0
  172. data/src/core/lib/surface/completion_queue.c +249 -83
  173. data/src/core/lib/surface/completion_queue.h +18 -13
  174. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  175. data/src/core/lib/surface/init.c +1 -52
  176. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  177. data/src/core/lib/surface/server.c +50 -27
  178. data/src/core/lib/surface/server.h +2 -1
  179. data/src/core/lib/surface/version.c +2 -2
  180. data/src/core/lib/transport/bdp_estimator.c +20 -9
  181. data/src/core/lib/transport/bdp_estimator.h +5 -1
  182. data/src/core/lib/transport/byte_stream.c +23 -9
  183. data/src/core/lib/transport/byte_stream.h +15 -6
  184. data/src/core/lib/transport/connectivity_state.c +6 -6
  185. data/src/core/lib/transport/connectivity_state.h +2 -1
  186. data/src/core/lib/transport/service_config.c +6 -13
  187. data/src/core/lib/transport/service_config.h +2 -2
  188. data/src/core/lib/transport/static_metadata.c +403 -389
  189. data/src/core/lib/transport/static_metadata.h +127 -114
  190. data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
  191. data/src/core/tsi/fake_transport_security.c +5 -4
  192. data/src/core/tsi/ssl_transport_security.c +71 -82
  193. data/src/core/tsi/ssl_transport_security.h +39 -61
  194. data/src/core/tsi/transport_security.c +83 -2
  195. data/src/core/tsi/transport_security.h +27 -2
  196. data/src/core/tsi/transport_security_adapter.c +236 -0
  197. data/src/core/tsi/transport_security_adapter.h +62 -0
  198. data/src/core/tsi/transport_security_interface.h +179 -66
  199. data/src/ruby/ext/grpc/extconf.rb +2 -1
  200. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  201. data/src/ruby/ext/grpc/rb_call.c +56 -48
  202. data/src/ruby/ext/grpc/rb_call.h +3 -4
  203. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  204. data/src/ruby/ext/grpc/rb_channel.c +45 -29
  205. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  206. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  207. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  208. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  209. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  210. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  211. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  212. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  213. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
  214. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
  215. data/src/ruby/ext/grpc/rb_server.c +26 -28
  216. data/src/ruby/lib/grpc/version.rb +1 -1
  217. metadata +40 -18
  218. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  219. data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -37,15 +37,16 @@
37
37
  /* Internal API for completion queues */
38
38
 
39
39
  #include <grpc/grpc.h>
40
+ #include "src/core/lib/debug/trace.h"
40
41
  #include "src/core/lib/iomgr/pollset.h"
41
42
 
42
43
  /* These trace flags default to 1. The corresponding lines are only traced
43
44
  if grpc_api_trace is also truthy */
44
- extern int grpc_cq_pluck_trace;
45
- extern int grpc_cq_event_timeout_trace;
46
- extern int grpc_trace_operation_failures;
45
+ extern grpc_tracer_flag grpc_cq_pluck_trace;
46
+ extern grpc_tracer_flag grpc_cq_event_timeout_trace;
47
+ extern grpc_tracer_flag grpc_trace_operation_failures;
47
48
  #ifndef NDEBUG
48
- extern int grpc_trace_pending_tags;
49
+ extern grpc_tracer_flag grpc_trace_pending_tags;
49
50
  #endif
50
51
 
51
52
  typedef struct grpc_cq_completion {
@@ -65,17 +66,17 @@ typedef struct grpc_cq_completion {
65
66
  #ifdef GRPC_CQ_REF_COUNT_DEBUG
66
67
  void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
67
68
  const char *file, int line);
68
- void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason,
69
- const char *file, int line);
69
+ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc,
70
+ const char *reason, const char *file, int line);
70
71
  #define GRPC_CQ_INTERNAL_REF(cc, reason) \
71
72
  grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__)
72
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) \
73
- grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__)
73
+ #define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) \
74
+ grpc_cq_internal_unref(ec, cc, reason, __FILE__, __LINE__)
74
75
  #else
75
76
  void grpc_cq_internal_ref(grpc_completion_queue *cc);
76
- void grpc_cq_internal_unref(grpc_completion_queue *cc);
77
+ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc);
77
78
  #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc)
78
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc)
79
+ #define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) grpc_cq_internal_unref(ec, cc)
79
80
  #endif
80
81
 
81
82
  /* Flag that an operation is beginning: the completion channel will not finish
@@ -94,9 +95,13 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc,
94
95
  grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc);
95
96
  grpc_completion_queue *grpc_cq_from_pollset(grpc_pollset *ps);
96
97
 
97
- void grpc_cq_mark_non_listening_server_cq(grpc_completion_queue *cc);
98
- bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc);
99
98
  void grpc_cq_mark_server_cq(grpc_completion_queue *cc);
100
- int grpc_cq_is_server_cq(grpc_completion_queue *cc);
99
+ bool grpc_cq_is_server_cq(grpc_completion_queue *cc);
100
+ bool grpc_cq_can_listen(grpc_completion_queue *cc);
101
+
102
+ grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cc);
103
+
104
+ grpc_completion_queue *grpc_completion_queue_create_internal(
105
+ grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type);
101
106
 
102
107
  #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */
@@ -36,12 +36,15 @@
36
36
 
37
37
  #include <grpc/support/log.h>
38
38
 
39
- /* TODO (sreek) - Currently this does not use the attributes arg. This will be
40
- added in a future PR */
39
+ /*
40
+ * == Default completion queue factory implementation ==
41
+ */
42
+
41
43
  static grpc_completion_queue* default_create(
42
44
  const grpc_completion_queue_factory* factory,
43
- const grpc_completion_queue_attributes* attributes) {
44
- return grpc_completion_queue_create(NULL);
45
+ const grpc_completion_queue_attributes* attr) {
46
+ return grpc_completion_queue_create_internal(attr->cq_completion_type,
47
+ attr->cq_polling_type);
45
48
  }
46
49
 
47
50
  static grpc_completion_queue_factory_vtable default_vtable = {default_create};
@@ -49,19 +52,24 @@ static grpc_completion_queue_factory_vtable default_vtable = {default_create};
49
52
  static const grpc_completion_queue_factory g_default_cq_factory = {
50
53
  "Default Factory", NULL, &default_vtable};
51
54
 
55
+ /*
56
+ * == Completion queue factory APIs
57
+ */
58
+
52
59
  const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup(
53
60
  const grpc_completion_queue_attributes* attributes) {
54
- /* As we add more fields to grpc_completion_queue_attributes, we may have to
55
- change this assert to:
56
- GPR_ASSERT (attributes->version >= 1 &&
57
- attributes->version <= GRPC_CQ_CURRENT_VERSION) */
58
- GPR_ASSERT(attributes->version == 1);
61
+ GPR_ASSERT(attributes->version >= 1 &&
62
+ attributes->version <= GRPC_CQ_CURRENT_VERSION);
59
63
 
60
64
  /* The default factory can handle version 1 of the attributes structure. We
61
65
  may have to change this as more fields are added to the structure */
62
66
  return &g_default_cq_factory;
63
67
  }
64
68
 
69
+ /*
70
+ * == Completion queue creation APIs ==
71
+ */
72
+
65
73
  grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) {
66
74
  GPR_ASSERT(!reserved);
67
75
  grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT,
@@ -75,3 +83,10 @@ grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) {
75
83
  GRPC_CQ_DEFAULT_POLLING};
76
84
  return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr);
77
85
  }
86
+
87
+ grpc_completion_queue* grpc_completion_queue_create(
88
+ const grpc_completion_queue_factory* factory,
89
+ const grpc_completion_queue_attributes* attr, void* reserved) {
90
+ GPR_ASSERT(!reserved);
91
+ return factory->vtable->create(factory, attr);
92
+ }
@@ -41,13 +41,8 @@
41
41
  #include <grpc/support/log.h>
42
42
  #include <grpc/support/time.h>
43
43
  #include "src/core/lib/channel/channel_stack.h"
44
- #include "src/core/lib/channel/compress_filter.h"
45
44
  #include "src/core/lib/channel/connected_channel.h"
46
- #include "src/core/lib/channel/deadline_filter.h"
47
45
  #include "src/core/lib/channel/handshaker_registry.h"
48
- #include "src/core/lib/channel/http_client_filter.h"
49
- #include "src/core/lib/channel/http_server_filter.h"
50
- #include "src/core/lib/channel/message_size_filter.h"
51
46
  #include "src/core/lib/debug/trace.h"
52
47
  #include "src/core/lib/http/parser.h"
53
48
  #include "src/core/lib/iomgr/combiner.h"
@@ -95,57 +90,13 @@ static bool prepend_filter(grpc_exec_ctx *exec_ctx,
95
90
  builder, (const grpc_channel_filter *)arg, NULL, NULL);
96
91
  }
97
92
 
98
- static bool maybe_add_http_filter(grpc_exec_ctx *exec_ctx,
99
- grpc_channel_stack_builder *builder,
100
- void *arg) {
101
- grpc_transport *t = grpc_channel_stack_builder_get_transport(builder);
102
- if (t && strstr(t->vtable->name, "http")) {
103
- return grpc_channel_stack_builder_prepend_filter(
104
- builder, (const grpc_channel_filter *)arg, NULL, NULL);
105
- }
106
- return true;
107
- }
108
-
109
93
  static void register_builtin_channel_init() {
110
- grpc_channel_init_register_stage(
111
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
112
- prepend_filter, (void *)&grpc_client_deadline_filter);
113
- grpc_channel_init_register_stage(
114
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
115
- (void *)&grpc_server_deadline_filter);
116
- grpc_channel_init_register_stage(
117
- GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
118
- prepend_filter, (void *)&grpc_message_size_filter);
119
- grpc_channel_init_register_stage(
120
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
121
- prepend_filter, (void *)&grpc_message_size_filter);
122
- grpc_channel_init_register_stage(
123
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
124
- (void *)&grpc_message_size_filter);
125
- grpc_channel_init_register_stage(
126
- GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
127
- (void *)&grpc_compress_filter);
128
- grpc_channel_init_register_stage(
129
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
130
- prepend_filter, (void *)&grpc_compress_filter);
131
- grpc_channel_init_register_stage(
132
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
133
- (void *)&grpc_compress_filter);
134
- grpc_channel_init_register_stage(
135
- GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
136
- maybe_add_http_filter, (void *)&grpc_http_client_filter);
137
94
  grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
138
95
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
139
96
  grpc_add_connected_filter, NULL);
140
- grpc_channel_init_register_stage(
141
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
142
- maybe_add_http_filter, (void *)&grpc_http_client_filter);
143
97
  grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
144
98
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
145
99
  grpc_add_connected_filter, NULL);
146
- grpc_channel_init_register_stage(
147
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
148
- maybe_add_http_filter, (void *)&grpc_http_server_filter);
149
100
  grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
150
101
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
151
102
  grpc_add_connected_filter, NULL);
@@ -189,16 +140,13 @@ void grpc_init(void) {
189
140
  grpc_register_tracer("channel_stack_builder",
190
141
  &grpc_trace_channel_stack_builder);
191
142
  grpc_register_tracer("http1", &grpc_http1_trace);
192
- grpc_register_tracer("compression", &grpc_compression_trace);
193
143
  grpc_register_tracer("queue_pluck", &grpc_cq_pluck_trace);
194
144
  grpc_register_tracer("combiner", &grpc_combiner_trace);
195
145
  grpc_register_tracer("server_channel", &grpc_server_channel_trace);
196
146
  grpc_register_tracer("bdp_estimator", &grpc_bdp_estimator_trace);
197
147
  // Default pluck trace to 1
198
- grpc_cq_pluck_trace = 1;
199
148
  grpc_register_tracer("queue_timeout", &grpc_cq_event_timeout_trace);
200
149
  // Default timeout trace to 1
201
- grpc_cq_event_timeout_trace = 1;
202
150
  grpc_register_tracer("op_failure", &grpc_trace_operation_failures);
203
151
  grpc_register_tracer("resource_quota", &grpc_resource_quota_trace);
204
152
  grpc_register_tracer("call_error", &grpc_call_error_trace);
@@ -223,6 +171,7 @@ void grpc_init(void) {
223
171
  grpc_tracer_init("GRPC_TRACE");
224
172
  /* no more changes to channel init pipelines */
225
173
  grpc_channel_init_finalize();
174
+ grpc_iomgr_start();
226
175
  }
227
176
  gpr_mu_unlock(&g_init_mu);
228
177
  GRPC_API_TRACE("grpc_init(void)", 0, ());
@@ -31,39 +31,50 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/lib/surface/lame_client.h"
35
-
36
34
  #include <grpc/grpc.h>
37
35
 
38
36
  #include <string.h>
39
37
 
40
38
  #include <grpc/support/alloc.h>
41
39
  #include <grpc/support/log.h>
40
+
41
+ #include "src/core/lib/support/atomic.h"
42
+
43
+ extern "C" {
42
44
  #include "src/core/lib/channel/channel_stack.h"
43
45
  #include "src/core/lib/support/string.h"
44
46
  #include "src/core/lib/surface/api_trace.h"
45
47
  #include "src/core/lib/surface/call.h"
46
48
  #include "src/core/lib/surface/channel.h"
49
+ #include "src/core/lib/surface/lame_client.h"
47
50
  #include "src/core/lib/transport/static_metadata.h"
51
+ }
48
52
 
49
- typedef struct {
53
+ namespace grpc_core {
54
+
55
+ namespace {
56
+
57
+ struct CallData {
50
58
  grpc_linked_mdelem status;
51
59
  grpc_linked_mdelem details;
52
- gpr_atm filled_metadata;
53
- } call_data;
60
+ grpc_core::atomic<bool> filled_metadata;
61
+ };
54
62
 
55
- typedef struct {
63
+ struct ChannelData {
56
64
  grpc_status_code error_code;
57
65
  const char *error_message;
58
- } channel_data;
66
+ };
59
67
 
60
68
  static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
61
69
  grpc_metadata_batch *mdb) {
62
- call_data *calld = elem->call_data;
63
- if (!gpr_atm_no_barrier_cas(&calld->filled_metadata, 0, 1)) {
70
+ CallData *calld = static_cast<CallData *>(elem->call_data);
71
+ bool expected = false;
72
+ if (!calld->filled_metadata.compare_exchange_strong(
73
+ expected, true, grpc_core::memory_order_relaxed,
74
+ grpc_core::memory_order_relaxed)) {
64
75
  return;
65
76
  }
66
- channel_data *chand = elem->channel_data;
77
+ ChannelData *chand = static_cast<ChannelData *>(elem->channel_data);
67
78
  char tmp[GPR_LTOA_MIN_BUFSIZE];
68
79
  gpr_ltoa(chand->error_code, tmp);
69
80
  calld->status.md = grpc_mdelem_from_slices(
@@ -83,7 +94,6 @@ static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
83
94
  static void lame_start_transport_stream_op_batch(
84
95
  grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
85
96
  grpc_transport_stream_op_batch *op) {
86
- GRPC_CALL_LOG_OP(GPR_INFO, elem, op);
87
97
  if (op->recv_initial_metadata) {
88
98
  fill_metadata(exec_ctx, elem,
89
99
  op->payload->recv_initial_metadata.recv_initial_metadata);
@@ -127,8 +137,6 @@ static void lame_start_transport_op(grpc_exec_ctx *exec_ctx,
127
137
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
128
138
  grpc_call_element *elem,
129
139
  const grpc_call_element_args *args) {
130
- call_data *calld = elem->call_data;
131
- gpr_atm_no_barrier_store(&calld->filled_metadata, 0);
132
140
  return GRPC_ERROR_NONE;
133
141
  }
134
142
 
@@ -149,18 +157,22 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
149
157
  static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
150
158
  grpc_channel_element *elem) {}
151
159
 
152
- const grpc_channel_filter grpc_lame_filter = {
153
- lame_start_transport_stream_op_batch,
154
- lame_start_transport_op,
155
- sizeof(call_data),
156
- init_call_elem,
160
+ } // namespace
161
+
162
+ } // namespace grpc_core
163
+
164
+ extern "C" const grpc_channel_filter grpc_lame_filter = {
165
+ grpc_core::lame_start_transport_stream_op_batch,
166
+ grpc_core::lame_start_transport_op,
167
+ sizeof(grpc_core::CallData),
168
+ grpc_core::init_call_elem,
157
169
  grpc_call_stack_ignore_set_pollset_or_pollset_set,
158
- destroy_call_elem,
159
- sizeof(channel_data),
160
- init_channel_elem,
161
- destroy_channel_elem,
162
- lame_get_peer,
163
- lame_get_channel_info,
170
+ grpc_core::destroy_call_elem,
171
+ sizeof(grpc_core::ChannelData),
172
+ grpc_core::init_channel_elem,
173
+ grpc_core::destroy_channel_elem,
174
+ grpc_core::lame_get_peer,
175
+ grpc_core::lame_get_channel_info,
164
176
  "lame-client",
165
177
  };
166
178
 
@@ -171,7 +183,6 @@ grpc_channel *grpc_lame_client_channel_create(const char *target,
171
183
  const char *error_message) {
172
184
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
173
185
  grpc_channel_element *elem;
174
- channel_data *chand;
175
186
  grpc_channel *channel = grpc_channel_create(&exec_ctx, target, NULL,
176
187
  GRPC_CLIENT_LAME_CHANNEL, NULL);
177
188
  elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
@@ -180,7 +191,7 @@ grpc_channel *grpc_lame_client_channel_create(const char *target,
180
191
  "error_message=%s)",
181
192
  3, (target, (int)error_code, error_message));
182
193
  GPR_ASSERT(elem->filter == &grpc_lame_filter);
183
- chand = (channel_data *)elem->channel_data;
194
+ auto chand = static_cast<grpc_core::ChannelData *>(elem->channel_data);
184
195
  chand->error_code = error_code;
185
196
  chand->error_message = error_message;
186
197
  grpc_exec_ctx_finish(&exec_ctx);
@@ -44,6 +44,7 @@
44
44
 
45
45
  #include "src/core/lib/channel/channel_args.h"
46
46
  #include "src/core/lib/channel/connected_channel.h"
47
+ #include "src/core/lib/iomgr/executor.h"
47
48
  #include "src/core/lib/iomgr/iomgr.h"
48
49
  #include "src/core/lib/slice/slice_internal.h"
49
50
  #include "src/core/lib/support/stack_lockfree.h"
@@ -72,7 +73,7 @@ typedef struct registered_method registered_method;
72
73
 
73
74
  typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type;
74
75
 
75
- int grpc_server_channel_trace = 0;
76
+ grpc_tracer_flag grpc_server_channel_trace = GRPC_TRACER_INITIALIZER(false);
76
77
 
77
78
  typedef struct requested_call {
78
79
  requested_call_type type;
@@ -211,6 +212,11 @@ struct grpc_server {
211
212
  gpr_mu mu_global; /* mutex for server and channel state */
212
213
  gpr_mu mu_call; /* mutex for call-specific state */
213
214
 
215
+ /* startup synchronization: flag is protected by mu_global, signals whether
216
+ we are doing the listener start routine or not */
217
+ bool starting;
218
+ gpr_cv starting_cv;
219
+
214
220
  registered_method *registered_methods;
215
221
  /** one request matcher for unregistered methods */
216
222
  request_matcher unregistered_request_matcher;
@@ -339,7 +345,7 @@ static void request_matcher_destroy(request_matcher *rm) {
339
345
 
340
346
  static void kill_zombie(grpc_exec_ctx *exec_ctx, void *elem,
341
347
  grpc_error *error) {
342
- grpc_call_destroy(grpc_call_from_top_element(elem));
348
+ grpc_call_unref(grpc_call_from_top_element(elem));
343
349
  }
344
350
 
345
351
  static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx,
@@ -388,6 +394,7 @@ static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) {
388
394
  grpc_channel_args_destroy(exec_ctx, server->channel_args);
389
395
  gpr_mu_destroy(&server->mu_global);
390
396
  gpr_mu_destroy(&server->mu_call);
397
+ gpr_cv_destroy(&server->starting_cv);
391
398
  while ((rm = server->registered_methods) != NULL) {
392
399
  server->registered_methods = rm->next;
393
400
  if (server->started) {
@@ -401,7 +408,7 @@ static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) {
401
408
  request_matcher_destroy(&server->unregistered_request_matcher);
402
409
  }
403
410
  for (i = 0; i < server->cq_count; i++) {
404
- GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server");
411
+ GRPC_CQ_INTERNAL_UNREF(exec_ctx, server->cqs[i], "server");
405
412
  if (server->started) {
406
413
  gpr_stack_lockfree_destroy(server->request_freelist_per_cq[i]);
407
414
  gpr_free(server->requested_calls_per_cq[i]);
@@ -449,7 +456,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
449
456
  grpc_closure_init(&chand->finish_destroy_channel_closure,
450
457
  finish_destroy_channel, chand, grpc_schedule_on_exec_ctx);
451
458
 
452
- if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) {
459
+ if (GRPC_TRACER_ON(grpc_server_channel_trace) && error != GRPC_ERROR_NONE) {
453
460
  const char *msg = grpc_error_string(error);
454
461
  gpr_log(GPR_INFO, "Disconnected client: %s", msg);
455
462
  }
@@ -974,7 +981,7 @@ const grpc_channel_filter grpc_server_top_filter = {
974
981
 
975
982
  static void register_completion_queue(grpc_server *server,
976
983
  grpc_completion_queue *cq,
977
- bool is_non_listening, void *reserved) {
984
+ void *reserved) {
978
985
  size_t i, n;
979
986
  GPR_ASSERT(!reserved);
980
987
  for (i = 0; i < server->cq_count; i++) {
@@ -983,10 +990,6 @@ static void register_completion_queue(grpc_server *server,
983
990
 
984
991
  grpc_cq_mark_server_cq(cq);
985
992
 
986
- if (is_non_listening) {
987
- grpc_cq_mark_non_listening_server_cq(cq);
988
- }
989
-
990
993
  GRPC_CQ_INTERNAL_REF(cq, "server");
991
994
  n = server->cq_count++;
992
995
  server->cqs = gpr_realloc(server->cqs,
@@ -1000,16 +1003,16 @@ void grpc_server_register_completion_queue(grpc_server *server,
1000
1003
  GRPC_API_TRACE(
1001
1004
  "grpc_server_register_completion_queue(server=%p, cq=%p, reserved=%p)", 3,
1002
1005
  (server, cq, reserved));
1003
- register_completion_queue(server, cq, false, reserved);
1004
- }
1005
1006
 
1006
- void grpc_server_register_non_listening_completion_queue(
1007
- grpc_server *server, grpc_completion_queue *cq, void *reserved) {
1008
- GRPC_API_TRACE(
1009
- "grpc_server_register_non_listening_completion_queue(server=%p, cq=%p, "
1010
- "reserved=%p)",
1011
- 3, (server, cq, reserved));
1012
- register_completion_queue(server, cq, true, reserved);
1007
+ if (grpc_get_cq_completion_type(cq) != GRPC_CQ_NEXT) {
1008
+ gpr_log(GPR_INFO,
1009
+ "Completion queue which is not of type GRPC_CQ_NEXT is being "
1010
+ "registered as a server-completion-queue");
1011
+ /* Ideally we should log an error and abort but ruby-wrapped-language API
1012
+ calls grpc_completion_queue_pluck() on server completion queues */
1013
+ }
1014
+
1015
+ register_completion_queue(server, cq, reserved);
1013
1016
  }
1014
1017
 
1015
1018
  grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
@@ -1017,10 +1020,9 @@ grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
1017
1020
 
1018
1021
  grpc_server *server = gpr_zalloc(sizeof(grpc_server));
1019
1022
 
1020
- GPR_ASSERT(grpc_is_initialized() && "call grpc_init()");
1021
-
1022
1023
  gpr_mu_init(&server->mu_global);
1023
1024
  gpr_mu_init(&server->mu_call);
1025
+ gpr_cv_init(&server->starting_cv);
1024
1026
 
1025
1027
  /* decremented by grpc_server_destroy */
1026
1028
  gpr_ref_init(&server->internal_refcount, 1);
@@ -1077,8 +1079,22 @@ void *grpc_server_register_method(
1077
1079
  return m;
1078
1080
  }
1079
1081
 
1082
+ static void start_listeners(grpc_exec_ctx *exec_ctx, void *s,
1083
+ grpc_error *error) {
1084
+ grpc_server *server = s;
1085
+ for (listener *l = server->listeners; l; l = l->next) {
1086
+ l->start(exec_ctx, server, l->arg, server->pollsets, server->pollset_count);
1087
+ }
1088
+
1089
+ gpr_mu_lock(&server->mu_global);
1090
+ server->starting = false;
1091
+ gpr_cv_signal(&server->starting_cv);
1092
+ gpr_mu_unlock(&server->mu_global);
1093
+
1094
+ server_unref(exec_ctx, server);
1095
+ }
1096
+
1080
1097
  void grpc_server_start(grpc_server *server) {
1081
- listener *l;
1082
1098
  size_t i;
1083
1099
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
1084
1100
 
@@ -1092,7 +1108,7 @@ void grpc_server_start(grpc_server *server) {
1092
1108
  server->requested_calls_per_cq =
1093
1109
  gpr_malloc(sizeof(*server->requested_calls_per_cq) * server->cq_count);
1094
1110
  for (i = 0; i < server->cq_count; i++) {
1095
- if (!grpc_cq_is_non_listening_server_cq(server->cqs[i])) {
1111
+ if (grpc_cq_can_listen(server->cqs[i])) {
1096
1112
  server->pollsets[server->pollset_count++] =
1097
1113
  grpc_cq_pollset(server->cqs[i]);
1098
1114
  }
@@ -1112,10 +1128,11 @@ void grpc_server_start(grpc_server *server) {
1112
1128
  (size_t)server->max_requested_calls_per_cq, server);
1113
1129
  }
1114
1130
 
1115
- for (l = server->listeners; l; l = l->next) {
1116
- l->start(&exec_ctx, server, l->arg, server->pollsets,
1117
- server->pollset_count);
1118
- }
1131
+ server_ref(server);
1132
+ server->starting = true;
1133
+ grpc_closure_sched(&exec_ctx, grpc_closure_create(start_listeners, server,
1134
+ grpc_executor_scheduler),
1135
+ GRPC_ERROR_NONE);
1119
1136
 
1120
1137
  grpc_exec_ctx_finish(&exec_ctx);
1121
1138
  }
@@ -1249,8 +1266,14 @@ void grpc_server_shutdown_and_notify(grpc_server *server,
1249
1266
  GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
1250
1267
  (server, cq, tag));
1251
1268
 
1252
- /* lock, and gather up some stuff to do */
1269
+ /* wait for startup to be finished: locks mu_global */
1253
1270
  gpr_mu_lock(&server->mu_global);
1271
+ while (server->starting) {
1272
+ gpr_cv_wait(&server->starting_cv, &server->mu_global,
1273
+ gpr_inf_future(GPR_CLOCK_REALTIME));
1274
+ }
1275
+
1276
+ /* stay locked, and gather up some stuff to do */
1254
1277
  grpc_cq_begin_op(cq, tag);
1255
1278
  if (server->shutdown_published) {
1256
1279
  grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown,