grpc 1.19.0 → 1.20.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 (224) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +4131 -7903
  3. data/include/grpc/grpc.h +11 -6
  4. data/include/grpc/grpc_security.h +51 -9
  5. data/include/grpc/impl/codegen/byte_buffer.h +13 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +4 -0
  7. data/include/grpc/impl/codegen/port_platform.h +37 -6
  8. data/include/grpc/impl/codegen/sync_posix.h +18 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +560 -236
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -2
  11. data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
  12. data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
  13. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +7 -4
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -2
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +105 -28
  16. data/src/core/ext/filters/client_channel/lb_policy.h +259 -141
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +789 -803
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +1 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +7 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +8 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +2 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +127 -219
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +103 -282
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +4 -10
  28. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +709 -906
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +8 -8
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -6
  33. data/src/core/ext/filters/client_channel/resolver.cc +54 -1
  34. data/src/core/ext/filters/client_channel/resolver.h +51 -22
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +34 -86
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +29 -41
  37. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +32 -78
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +109 -72
  39. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
  41. data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
  42. data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
  43. data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +69 -49
  45. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +11 -8
  46. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +568 -0
  47. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +141 -0
  48. data/src/core/ext/filters/client_channel/server_address.cc +0 -48
  49. data/src/core/ext/filters/client_channel/server_address.h +0 -10
  50. data/src/core/{lib/transport → ext/filters/client_channel}/service_config.cc +10 -5
  51. data/src/core/{lib/transport → ext/filters/client_channel}/service_config.h +16 -12
  52. data/src/core/ext/filters/client_channel/subchannel.cc +11 -16
  53. data/src/core/ext/filters/client_channel/subchannel.h +3 -0
  54. data/src/core/ext/filters/max_age/max_age_filter.cc +4 -1
  55. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -2
  56. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -45
  57. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +133 -134
  58. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
  59. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
  60. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
  61. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
  62. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -29
  63. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_data.cc +2 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
  67. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
  68. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
  69. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
  70. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +5 -4
  71. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
  72. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -1
  73. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  74. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -4
  75. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
  76. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +7 -6
  77. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
  78. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
  79. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -1
  80. data/src/core/ext/transport/chttp2/transport/internal.h +5 -4
  81. data/src/core/ext/transport/chttp2/transport/parsing.cc +9 -9
  82. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -1
  83. data/src/core/ext/transport/inproc/inproc_transport.cc +8 -0
  84. data/src/core/lib/channel/channel_args.cc +2 -0
  85. data/src/core/lib/channel/channel_args.h +3 -0
  86. data/src/core/lib/channel/channel_stack.h +1 -1
  87. data/src/core/lib/channel/channel_trace.cc +4 -4
  88. data/src/core/lib/channel/channel_trace.h +4 -4
  89. data/src/core/lib/channel/channelz.cc +32 -19
  90. data/src/core/lib/channel/channelz.h +4 -4
  91. data/src/core/lib/channel/channelz_registry.cc +1 -1
  92. data/src/core/lib/channel/context.h +0 -3
  93. data/src/core/lib/channel/handshaker_registry.cc +7 -3
  94. data/src/core/lib/compression/algorithm_metadata.h +3 -3
  95. data/src/core/lib/compression/compression.cc +1 -1
  96. data/src/core/lib/compression/compression_internal.cc +2 -2
  97. data/src/core/lib/compression/stream_compression_gzip.cc +1 -1
  98. data/src/core/lib/debug/trace.h +2 -1
  99. data/src/core/lib/gpr/cpu_posix.cc +5 -3
  100. data/src/core/lib/gpr/sync_posix.cc +65 -4
  101. data/src/core/lib/gprpp/atomic.h +75 -5
  102. data/src/core/lib/gprpp/fork.cc +0 -2
  103. data/src/core/lib/gprpp/orphanable.h +3 -2
  104. data/src/core/lib/gprpp/ref_counted.h +9 -11
  105. data/src/core/lib/gprpp/thd.h +42 -7
  106. data/src/core/lib/gprpp/thd_posix.cc +31 -13
  107. data/src/core/lib/gprpp/thd_windows.cc +47 -34
  108. data/src/core/lib/http/httpcli.cc +3 -2
  109. data/src/core/lib/http/httpcli_security_connector.cc +0 -1
  110. data/src/core/lib/http/parser.cc +2 -1
  111. data/src/core/lib/http/parser.h +2 -1
  112. data/src/core/lib/iomgr/buffer_list.h +1 -1
  113. data/src/core/lib/iomgr/endpoint.cc +2 -2
  114. data/src/core/lib/iomgr/endpoint.h +3 -2
  115. data/src/core/lib/iomgr/error.cc +9 -9
  116. data/src/core/lib/iomgr/error.h +4 -3
  117. data/src/core/lib/iomgr/ev_epoll1_linux.cc +6 -0
  118. data/src/core/lib/iomgr/ev_epollex_linux.cc +14 -9
  119. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -481
  120. data/src/core/lib/iomgr/ev_posix.cc +7 -3
  121. data/src/core/lib/iomgr/ev_posix.h +8 -0
  122. data/src/core/lib/iomgr/executor.cc +13 -0
  123. data/src/core/lib/iomgr/executor.h +2 -1
  124. data/src/core/lib/iomgr/internal_errqueue.cc +2 -4
  125. data/src/core/lib/iomgr/iomgr.cc +5 -0
  126. data/src/core/lib/iomgr/iomgr.h +7 -0
  127. data/src/core/lib/iomgr/iomgr_custom.cc +9 -2
  128. data/src/core/lib/iomgr/iomgr_internal.cc +6 -0
  129. data/src/core/lib/iomgr/iomgr_internal.h +9 -1
  130. data/src/core/lib/iomgr/iomgr_posix.cc +10 -2
  131. data/src/core/lib/iomgr/iomgr_windows.cc +10 -2
  132. data/src/core/lib/iomgr/port.h +19 -0
  133. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -4
  134. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  135. data/src/core/lib/iomgr/tcp_posix.cc +158 -54
  136. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  137. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
  138. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
  139. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  140. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -6
  141. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
  142. data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
  143. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -2
  144. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +28 -17
  145. data/src/core/lib/security/security_connector/ssl_utils.cc +134 -0
  146. data/src/core/lib/security/security_connector/ssl_utils.h +32 -0
  147. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
  148. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
  149. data/src/core/lib/security/transport/auth_filters.h +2 -2
  150. data/src/core/lib/security/transport/client_auth_filter.cc +35 -39
  151. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  152. data/src/core/lib/security/transport/security_handshaker.cc +4 -3
  153. data/src/core/lib/slice/percent_encoding.cc +3 -3
  154. data/src/core/lib/slice/percent_encoding.h +3 -3
  155. data/src/core/lib/slice/slice.cc +27 -30
  156. data/src/core/lib/slice/slice_hash_table.h +2 -2
  157. data/src/core/lib/slice/slice_intern.cc +1 -1
  158. data/src/core/lib/slice/slice_internal.h +14 -3
  159. data/src/core/lib/slice/slice_weak_hash_table.h +4 -4
  160. data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
  161. data/src/core/lib/surface/call.cc +8 -3
  162. data/src/core/lib/surface/completion_queue.cc +134 -148
  163. data/src/core/lib/surface/init.cc +78 -30
  164. data/src/core/lib/surface/init.h +1 -0
  165. data/src/core/lib/surface/lame_client.cc +4 -6
  166. data/src/core/lib/surface/version.cc +1 -1
  167. data/src/core/lib/transport/metadata.cc +66 -33
  168. data/src/core/lib/transport/metadata_batch.cc +1 -1
  169. data/src/core/lib/transport/metadata_batch.h +1 -1
  170. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  171. data/src/core/lib/transport/timeout_encoding.h +1 -1
  172. data/src/core/lib/transport/transport.h +4 -3
  173. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
  174. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
  175. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
  176. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
  177. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
  178. data/src/core/tsi/ssl_transport_security.cc +1 -5
  179. data/src/core/tsi/ssl_transport_security.h +24 -4
  180. data/src/ruby/bin/math_pb.rb +18 -16
  181. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  182. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  183. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  184. data/src/ruby/lib/grpc/version.rb +1 -1
  185. data/src/ruby/pb/README.md +1 -1
  186. data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
  187. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
  188. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
  189. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
  190. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
  191. data/third_party/cares/cares/ares.h +12 -0
  192. data/third_party/cares/cares/ares_create_query.c +5 -1
  193. data/third_party/cares/cares/ares_data.c +74 -73
  194. data/third_party/cares/cares/ares_destroy.c +6 -1
  195. data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
  196. data/third_party/cares/cares/ares_gethostbyname.c +15 -4
  197. data/third_party/cares/cares/ares_getnameinfo.c +11 -0
  198. data/third_party/cares/cares/ares_init.c +274 -173
  199. data/third_party/cares/cares/ares_library_init.c +21 -3
  200. data/third_party/cares/cares/ares_options.c +6 -2
  201. data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
  202. data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
  203. data/third_party/cares/cares/ares_platform.c +7 -0
  204. data/third_party/cares/cares/ares_private.h +19 -11
  205. data/third_party/cares/cares/ares_process.c +27 -2
  206. data/third_party/cares/cares/ares_rules.h +1 -1
  207. data/third_party/cares/cares/ares_search.c +7 -0
  208. data/third_party/cares/cares/ares_send.c +6 -0
  209. data/third_party/cares/cares/ares_strsplit.c +174 -0
  210. data/third_party/cares/cares/ares_strsplit.h +43 -0
  211. data/third_party/cares/cares/ares_version.h +4 -4
  212. data/third_party/cares/cares/config-win32.h +1 -1
  213. data/third_party/cares/cares/inet_ntop.c +2 -3
  214. data/third_party/cares/config_darwin/ares_config.h +3 -0
  215. data/third_party/cares/config_freebsd/ares_config.h +3 -0
  216. data/third_party/cares/config_linux/ares_config.h +3 -0
  217. data/third_party/cares/config_openbsd/ares_config.h +3 -0
  218. metadata +39 -37
  219. data/src/core/ext/filters/client_channel/request_routing.cc +0 -946
  220. data/src/core/ext/filters/client_channel/request_routing.h +0 -181
  221. data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
  222. data/src/core/lib/gprpp/atomic_with_std.h +0 -35
  223. data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
  224. data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
@@ -44,13 +44,14 @@ struct thd_arg {
44
44
  void (*body)(void* arg); /* body of a thread */
45
45
  void* arg; /* argument to a thread */
46
46
  const char* name; /* name of thread. Can be nullptr. */
47
+ bool joinable;
48
+ bool tracked;
47
49
  };
48
50
 
49
- class ThreadInternalsPosix
50
- : public grpc_core::internal::ThreadInternalsInterface {
51
+ class ThreadInternalsPosix : public internal::ThreadInternalsInterface {
51
52
  public:
52
53
  ThreadInternalsPosix(const char* thd_name, void (*thd_body)(void* arg),
53
- void* arg, bool* success)
54
+ void* arg, bool* success, const Thread::Options& options)
54
55
  : started_(false) {
55
56
  gpr_mu_init(&mu_);
56
57
  gpr_cv_init(&ready_);
@@ -63,11 +64,20 @@ class ThreadInternalsPosix
63
64
  info->body = thd_body;
64
65
  info->arg = arg;
65
66
  info->name = thd_name;
66
- grpc_core::Fork::IncThreadCount();
67
+ info->joinable = options.joinable();
68
+ info->tracked = options.tracked();
69
+ if (options.tracked()) {
70
+ Fork::IncThreadCount();
71
+ }
67
72
 
68
73
  GPR_ASSERT(pthread_attr_init(&attr) == 0);
69
- GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) ==
70
- 0);
74
+ if (options.joinable()) {
75
+ GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) ==
76
+ 0);
77
+ } else {
78
+ GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) ==
79
+ 0);
80
+ }
71
81
 
72
82
  *success =
73
83
  (pthread_create(&pthread_id_, &attr,
@@ -97,8 +107,14 @@ class ThreadInternalsPosix
97
107
  }
98
108
  gpr_mu_unlock(&arg.thread->mu_);
99
109
 
110
+ if (!arg.joinable) {
111
+ Delete(arg.thread);
112
+ }
113
+
100
114
  (*arg.body)(arg.arg);
101
- grpc_core::Fork::DecThreadCount();
115
+ if (arg.tracked) {
116
+ Fork::DecThreadCount();
117
+ }
102
118
  return nullptr;
103
119
  },
104
120
  info) == 0);
@@ -108,9 +124,11 @@ class ThreadInternalsPosix
108
124
  if (!(*success)) {
109
125
  /* don't use gpr_free, as this was allocated using malloc (see above) */
110
126
  free(info);
111
- grpc_core::Fork::DecThreadCount();
127
+ if (options.tracked()) {
128
+ Fork::DecThreadCount();
129
+ }
112
130
  }
113
- };
131
+ }
114
132
 
115
133
  ~ThreadInternalsPosix() override {
116
134
  gpr_mu_destroy(&mu_);
@@ -136,15 +154,15 @@ class ThreadInternalsPosix
136
154
  } // namespace
137
155
 
138
156
  Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
139
- bool* success) {
157
+ bool* success, const Options& options)
158
+ : options_(options) {
140
159
  bool outcome = false;
141
- impl_ =
142
- grpc_core::New<ThreadInternalsPosix>(thd_name, thd_body, arg, &outcome);
160
+ impl_ = New<ThreadInternalsPosix>(thd_name, thd_body, arg, &outcome, options);
143
161
  if (outcome) {
144
162
  state_ = ALIVE;
145
163
  } else {
146
164
  state_ = FAILED;
147
- grpc_core::Delete(impl_);
165
+ Delete(impl_);
148
166
  impl_ = nullptr;
149
167
  }
150
168
 
@@ -33,10 +33,8 @@
33
33
 
34
34
  #if defined(_MSC_VER)
35
35
  #define thread_local __declspec(thread)
36
- #define WIN_LAMBDA
37
36
  #elif defined(__GNUC__)
38
37
  #define thread_local __thread
39
- #define WIN_LAMBDA WINAPI
40
38
  #else
41
39
  #error "Unknown compiler - please file a bug report"
42
40
  #endif
@@ -48,6 +46,7 @@ struct thd_info {
48
46
  void (*body)(void* arg); /* body of a thread */
49
47
  void* arg; /* argument to a thread */
50
48
  HANDLE join_event; /* the join event */
49
+ bool joinable; /* whether it is joinable */
51
50
  };
52
51
 
53
52
  thread_local struct thd_info* g_thd_info;
@@ -55,7 +54,8 @@ thread_local struct thd_info* g_thd_info;
55
54
  class ThreadInternalsWindows
56
55
  : public grpc_core::internal::ThreadInternalsInterface {
57
56
  public:
58
- ThreadInternalsWindows(void (*thd_body)(void* arg), void* arg, bool* success)
57
+ ThreadInternalsWindows(void (*thd_body)(void* arg), void* arg, bool* success,
58
+ const grpc_core::Thread::Options& options)
59
59
  : started_(false) {
60
60
  gpr_mu_init(&mu_);
61
61
  gpr_cv_init(&ready_);
@@ -65,36 +65,24 @@ class ThreadInternalsWindows
65
65
  info_->thread = this;
66
66
  info_->body = thd_body;
67
67
  info_->arg = arg;
68
-
69
- info_->join_event = CreateEvent(nullptr, FALSE, FALSE, nullptr);
70
- if (info_->join_event == nullptr) {
71
- gpr_free(info_);
72
- *success = false;
73
- } else {
74
- handle = CreateThread(
75
- nullptr, 64 * 1024,
76
- [](void* v) WIN_LAMBDA -> DWORD {
77
- g_thd_info = static_cast<thd_info*>(v);
78
- gpr_mu_lock(&g_thd_info->thread->mu_);
79
- while (!g_thd_info->thread->started_) {
80
- gpr_cv_wait(&g_thd_info->thread->ready_, &g_thd_info->thread->mu_,
81
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
82
- }
83
- gpr_mu_unlock(&g_thd_info->thread->mu_);
84
- g_thd_info->body(g_thd_info->arg);
85
- BOOL ret = SetEvent(g_thd_info->join_event);
86
- GPR_ASSERT(ret);
87
- return 0;
88
- },
89
- info_, 0, nullptr);
90
- if (handle == nullptr) {
91
- destroy_thread();
68
+ info_->join_event = nullptr;
69
+ info_->joinable = options.joinable();
70
+ if (info_->joinable) {
71
+ info_->join_event = CreateEvent(nullptr, FALSE, FALSE, nullptr);
72
+ if (info_->join_event == nullptr) {
73
+ gpr_free(info_);
92
74
  *success = false;
93
- } else {
94
- CloseHandle(handle);
95
- *success = true;
75
+ return;
96
76
  }
97
77
  }
78
+ handle = CreateThread(nullptr, 64 * 1024, thread_body, info_, 0, nullptr);
79
+ if (handle == nullptr) {
80
+ destroy_thread();
81
+ *success = false;
82
+ } else {
83
+ CloseHandle(handle);
84
+ *success = true;
85
+ }
98
86
  }
99
87
 
100
88
  ~ThreadInternalsWindows() override {
@@ -116,8 +104,32 @@ class ThreadInternalsWindows
116
104
  }
117
105
 
118
106
  private:
107
+ static DWORD WINAPI thread_body(void* v) {
108
+ g_thd_info = static_cast<thd_info*>(v);
109
+ gpr_mu_lock(&g_thd_info->thread->mu_);
110
+ while (!g_thd_info->thread->started_) {
111
+ gpr_cv_wait(&g_thd_info->thread->ready_, &g_thd_info->thread->mu_,
112
+ gpr_inf_future(GPR_CLOCK_MONOTONIC));
113
+ }
114
+ gpr_mu_unlock(&g_thd_info->thread->mu_);
115
+ if (!g_thd_info->joinable) {
116
+ grpc_core::Delete(g_thd_info->thread);
117
+ g_thd_info->thread = nullptr;
118
+ }
119
+ g_thd_info->body(g_thd_info->arg);
120
+ if (g_thd_info->joinable) {
121
+ BOOL ret = SetEvent(g_thd_info->join_event);
122
+ GPR_ASSERT(ret);
123
+ } else {
124
+ gpr_free(g_thd_info);
125
+ }
126
+ return 0;
127
+ }
128
+
119
129
  void destroy_thread() {
120
- CloseHandle(info_->join_event);
130
+ if (info_ != nullptr && info_->joinable) {
131
+ CloseHandle(info_->join_event);
132
+ }
121
133
  gpr_free(info_);
122
134
  }
123
135
 
@@ -132,14 +144,15 @@ class ThreadInternalsWindows
132
144
  namespace grpc_core {
133
145
 
134
146
  Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
135
- bool* success) {
147
+ bool* success, const Options& options)
148
+ : options_(options) {
136
149
  bool outcome = false;
137
- impl_ = grpc_core::New<ThreadInternalsWindows>(thd_body, arg, &outcome);
150
+ impl_ = New<ThreadInternalsWindows>(thd_body, arg, &outcome, options);
138
151
  if (outcome) {
139
152
  state_ = ALIVE;
140
153
  } else {
141
154
  state_ = FAILED;
142
- grpc_core::Delete(impl_);
155
+ Delete(impl_);
143
156
  impl_ = nullptr;
144
157
  }
145
158
 
@@ -121,7 +121,7 @@ static void append_error(internal_request* req, grpc_error* error) {
121
121
  }
122
122
 
123
123
  static void do_read(internal_request* req) {
124
- grpc_endpoint_read(req->ep, &req->incoming, &req->on_read);
124
+ grpc_endpoint_read(req->ep, &req->incoming, &req->on_read, /*urgent=*/true);
125
125
  }
126
126
 
127
127
  static void on_read(void* user_data, grpc_error* error) {
@@ -229,7 +229,8 @@ static void internal_request_begin(grpc_httpcli_context* context,
229
229
  const grpc_httpcli_request* request,
230
230
  grpc_millis deadline, grpc_closure* on_done,
231
231
  grpc_httpcli_response* response,
232
- const char* name, grpc_slice request_text) {
232
+ const char* name,
233
+ const grpc_slice& request_text) {
233
234
  internal_request* req =
234
235
  static_cast<internal_request*>(gpr_malloc(sizeof(internal_request)));
235
236
  memset(req, 0, sizeof(*req));
@@ -59,7 +59,6 @@ class grpc_httpcli_ssl_channel_security_connector final
59
59
  tsi_result InitHandshakerFactory(const char* pem_root_certs,
60
60
  const tsi_ssl_root_certs_store* root_store) {
61
61
  tsi_ssl_client_handshaker_options options;
62
- memset(&options, 0, sizeof(options));
63
62
  options.pem_root_certs = pem_root_certs;
64
63
  options.root_store = root_store;
65
64
  return tsi_create_ssl_client_handshaker_factory_with_options(
@@ -351,7 +351,8 @@ void grpc_http_response_destroy(grpc_http_response* response) {
351
351
  gpr_free(response->hdrs);
352
352
  }
353
353
 
354
- grpc_error* grpc_http_parser_parse(grpc_http_parser* parser, grpc_slice slice,
354
+ grpc_error* grpc_http_parser_parse(grpc_http_parser* parser,
355
+ const grpc_slice& slice,
355
356
  size_t* start_of_body) {
356
357
  for (size_t i = 0; i < GRPC_SLICE_LENGTH(slice); i++) {
357
358
  bool found_body_start = false;
@@ -101,7 +101,8 @@ void grpc_http_parser_init(grpc_http_parser* parser, grpc_http_type type,
101
101
  void grpc_http_parser_destroy(grpc_http_parser* parser);
102
102
 
103
103
  /* Sets \a start_of_body to the offset in \a slice of the start of the body. */
104
- grpc_error* grpc_http_parser_parse(grpc_http_parser* parser, grpc_slice slice,
104
+ grpc_error* grpc_http_parser_parse(grpc_http_parser* parser,
105
+ const grpc_slice& slice,
105
106
  size_t* start_of_body);
106
107
  grpc_error* grpc_http_parser_eof(grpc_http_parser* parser);
107
108
 
@@ -160,6 +160,6 @@ void grpc_tcp_set_write_timestamps_callback(void (*fn)(void*,
160
160
  grpc_core::Timestamps*,
161
161
  grpc_error* error));
162
162
 
163
- }; /* namespace grpc_core */
163
+ } /* namespace grpc_core */
164
164
 
165
165
  #endif /* GRPC_CORE_LIB_IOMGR_BUFFER_LIST_H */
@@ -23,8 +23,8 @@
23
23
  grpc_core::TraceFlag grpc_tcp_trace(false, "tcp");
24
24
 
25
25
  void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices,
26
- grpc_closure* cb) {
27
- ep->vtable->read(ep, slices, cb);
26
+ grpc_closure* cb, bool urgent) {
27
+ ep->vtable->read(ep, slices, cb, urgent);
28
28
  }
29
29
 
30
30
  void grpc_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
@@ -36,7 +36,8 @@ typedef struct grpc_endpoint_vtable grpc_endpoint_vtable;
36
36
  class Timestamps;
37
37
 
38
38
  struct grpc_endpoint_vtable {
39
- void (*read)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb);
39
+ void (*read)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb,
40
+ bool urgent);
40
41
  void (*write)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb,
41
42
  void* arg);
42
43
  void (*add_to_pollset)(grpc_endpoint* ep, grpc_pollset* pollset);
@@ -56,7 +57,7 @@ struct grpc_endpoint_vtable {
56
57
  Valid slices may be placed into \a slices even when the callback is
57
58
  invoked with error != GRPC_ERROR_NONE. */
58
59
  void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices,
59
- grpc_closure* cb);
60
+ grpc_closure* cb, bool urgent);
60
61
 
61
62
  char* grpc_endpoint_get_peer(grpc_endpoint* ep);
62
63
 
@@ -150,13 +150,12 @@ static void unref_errs(grpc_error* err) {
150
150
  }
151
151
  }
152
152
 
153
- static void unref_slice(grpc_slice slice) { grpc_slice_unref_internal(slice); }
154
-
155
153
  static void unref_strs(grpc_error* err) {
156
154
  for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) {
157
155
  uint8_t slot = err->strs[which];
158
156
  if (slot != UINT8_MAX) {
159
- unref_slice(*reinterpret_cast<grpc_slice*>(err->arena + slot));
157
+ grpc_slice_unref_internal(
158
+ *reinterpret_cast<grpc_slice*>(err->arena + slot));
160
159
  }
161
160
  }
162
161
  }
@@ -231,7 +230,7 @@ static void internal_set_int(grpc_error** err, grpc_error_ints which,
231
230
  }
232
231
 
233
232
  static void internal_set_str(grpc_error** err, grpc_error_strs which,
234
- grpc_slice value) {
233
+ const grpc_slice& value) {
235
234
  uint8_t slot = (*err)->strs[which];
236
235
  if (slot == UINT8_MAX) {
237
236
  slot = get_placement(err, sizeof(value));
@@ -243,7 +242,8 @@ static void internal_set_str(grpc_error** err, grpc_error_strs which,
243
242
  return;
244
243
  }
245
244
  } else {
246
- unref_slice(*reinterpret_cast<grpc_slice*>((*err)->arena + slot));
245
+ grpc_slice_unref_internal(
246
+ *reinterpret_cast<grpc_slice*>((*err)->arena + slot));
247
247
  }
248
248
  (*err)->strs[which] = slot;
249
249
  memcpy((*err)->arena + slot, &value, sizeof(value));
@@ -313,8 +313,8 @@ void grpc_enable_error_creation() {
313
313
  gpr_atm_no_barrier_store(&g_error_creation_allowed, true);
314
314
  }
315
315
 
316
- grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
317
- grpc_error** referencing,
316
+ grpc_error* grpc_error_create(const char* file, int line,
317
+ const grpc_slice& desc, grpc_error** referencing,
318
318
  size_t num_referencing) {
319
319
  GPR_TIMER_SCOPE("grpc_error_create", 0);
320
320
  uint8_t initial_arena_capacity = static_cast<uint8_t>(
@@ -472,7 +472,7 @@ bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) {
472
472
  }
473
473
 
474
474
  grpc_error* grpc_error_set_str(grpc_error* src, grpc_error_strs which,
475
- grpc_slice str) {
475
+ const grpc_slice& str) {
476
476
  GPR_TIMER_SCOPE("grpc_error_set_str", 0);
477
477
  grpc_error* new_err = copy_error_and_unref(src);
478
478
  internal_set_str(&new_err, which, str);
@@ -620,7 +620,7 @@ static char* key_str(grpc_error_strs which) {
620
620
  return gpr_strdup(error_str_name(which));
621
621
  }
622
622
 
623
- static char* fmt_str(grpc_slice slice) {
623
+ static char* fmt_str(const grpc_slice& slice) {
624
624
  char* s = nullptr;
625
625
  size_t sz = 0;
626
626
  size_t cap = 0;
@@ -138,8 +138,9 @@ void grpc_enable_error_creation();
138
138
  const char* grpc_error_string(grpc_error* error);
139
139
 
140
140
  /// Create an error - but use GRPC_ERROR_CREATE instead
141
- grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
142
- grpc_error** referencing, size_t num_referencing);
141
+ grpc_error* grpc_error_create(const char* file, int line,
142
+ const grpc_slice& desc, grpc_error** referencing,
143
+ size_t num_referencing);
143
144
  /// Create an error (this is the preferred way of generating an error that is
144
145
  /// not due to a system call - for system calls, use GRPC_OS_ERROR or
145
146
  /// GRPC_WSA_ERROR as appropriate)
@@ -200,7 +201,7 @@ bool grpc_error_get_int(grpc_error* error, grpc_error_ints which, intptr_t* p);
200
201
  /// This call takes ownership of the slice; the error is responsible for
201
202
  /// eventually unref-ing it.
202
203
  grpc_error* grpc_error_set_str(grpc_error* src, grpc_error_strs which,
203
- grpc_slice str) GRPC_MUST_USE_RESULT;
204
+ const grpc_slice& str) GRPC_MUST_USE_RESULT;
204
205
  /// Returns false if the specified string is not set.
205
206
  /// Caller does NOT own the slice.
206
207
  bool grpc_error_get_str(grpc_error* error, grpc_error_strs which,
@@ -1246,6 +1246,11 @@ static bool is_any_background_poller_thread(void) { return false; }
1246
1246
 
1247
1247
  static void shutdown_background_closure(void) {}
1248
1248
 
1249
+ static bool add_closure_to_background_poller(grpc_closure* closure,
1250
+ grpc_error* error) {
1251
+ return false;
1252
+ }
1253
+
1249
1254
  static void shutdown_engine(void) {
1250
1255
  fd_global_shutdown();
1251
1256
  pollset_global_shutdown();
@@ -1292,6 +1297,7 @@ static const grpc_event_engine_vtable vtable = {
1292
1297
  is_any_background_poller_thread,
1293
1298
  shutdown_background_closure,
1294
1299
  shutdown_engine,
1300
+ add_closure_to_background_poller,
1295
1301
  };
1296
1302
 
1297
1303
  /* Called by the child process's post-fork handler to close open fds, including
@@ -447,14 +447,12 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
447
447
  // Otherwise, we will receive epoll events after we release the FD.
448
448
  epoll_event ev_fd;
449
449
  memset(&ev_fd, 0, sizeof(ev_fd));
450
- if (release_fd != nullptr) {
451
- if (pollable_obj != nullptr) { // For PO_FD.
452
- epoll_ctl(pollable_obj->epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
453
- }
454
- for (size_t i = 0; i < fd->pollset_fds.size(); ++i) { // For PO_MULTI.
455
- const int epfd = fd->pollset_fds[i];
456
- epoll_ctl(epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
457
- }
450
+ if (pollable_obj != nullptr) { // For PO_FD.
451
+ epoll_ctl(pollable_obj->epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
452
+ }
453
+ for (size_t i = 0; i < fd->pollset_fds.size(); ++i) { // For PO_MULTI.
454
+ const int epfd = fd->pollset_fds[i];
455
+ epoll_ctl(epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
458
456
  }
459
457
  *release_fd = fd->fd;
460
458
  } else {
@@ -614,6 +612,7 @@ static void pollable_unref(pollable* p, int line, const char* reason) {
614
612
  close(p->epfd);
615
613
  grpc_wakeup_fd_destroy(&p->wakeup);
616
614
  gpr_mu_destroy(&p->owner_orphan_mu);
615
+ gpr_mu_destroy(&p->mu);
617
616
  gpr_free(p);
618
617
  }
619
618
  }
@@ -1295,7 +1294,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
1295
1294
  static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
1296
1295
  GPR_TIMER_SCOPE("pollset_add_fd", 0);
1297
1296
 
1298
- // We never transition from PO_MULTI to other modes (i.e., PO_FD or PO_EMOPTY)
1297
+ // We never transition from PO_MULTI to other modes (i.e., PO_FD or PO_EMPTY)
1299
1298
  // and, thus, it is safe to simply store and check whether the FD has already
1300
1299
  // been added to the active pollable previously.
1301
1300
  if (gpr_atm_acq_load(&pollset->active_pollable_type) == PO_MULTI &&
@@ -1579,6 +1578,11 @@ static bool is_any_background_poller_thread(void) { return false; }
1579
1578
 
1580
1579
  static void shutdown_background_closure(void) {}
1581
1580
 
1581
+ static bool add_closure_to_background_poller(grpc_closure* closure,
1582
+ grpc_error* error) {
1583
+ return false;
1584
+ }
1585
+
1582
1586
  static void shutdown_engine(void) {
1583
1587
  fd_global_shutdown();
1584
1588
  pollset_global_shutdown();
@@ -1620,6 +1624,7 @@ static const grpc_event_engine_vtable vtable = {
1620
1624
  is_any_background_poller_thread,
1621
1625
  shutdown_background_closure,
1622
1626
  shutdown_engine,
1627
+ add_closure_to_background_poller,
1623
1628
  };
1624
1629
 
1625
1630
  const grpc_event_engine_vtable* grpc_init_epollex_linux(