grpc 0.13.0 → 0.13.1.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Makefile +1114 -937
  4. data/include/grpc/census.h +71 -89
  5. data/include/grpc/compression.h +7 -7
  6. data/include/grpc/grpc.h +65 -68
  7. data/include/grpc/grpc_security.h +38 -38
  8. data/include/grpc/impl/codegen/alloc.h +7 -7
  9. data/include/grpc/impl/codegen/byte_buffer.h +13 -13
  10. data/include/grpc/impl/codegen/grpc_types.h +7 -2
  11. data/include/grpc/impl/codegen/log.h +5 -5
  12. data/include/grpc/impl/codegen/port_platform.h +14 -6
  13. data/include/grpc/impl/codegen/slice.h +15 -15
  14. data/include/grpc/impl/codegen/slice_buffer.h +17 -17
  15. data/include/grpc/impl/codegen/sync.h +26 -22
  16. data/include/grpc/impl/codegen/time.h +22 -24
  17. data/include/grpc/support/avl.h +9 -8
  18. data/include/grpc/support/cmdline.h +12 -12
  19. data/include/grpc/support/cpu.h +2 -2
  20. data/include/grpc/support/histogram.h +22 -22
  21. data/include/grpc/support/host_port.h +2 -2
  22. data/include/grpc/support/log_win32.h +1 -1
  23. data/include/grpc/support/string_util.h +2 -2
  24. data/include/grpc/support/subprocess.h +5 -5
  25. data/include/grpc/support/thd.h +9 -9
  26. data/include/grpc/support/useful.h +3 -1
  27. data/src/core/census/context.c +64 -85
  28. data/src/core/census/grpc_filter.c +2 -2
  29. data/src/core/census/mlog.c +600 -0
  30. data/src/core/census/mlog.h +95 -0
  31. data/src/core/channel/channel_args.c +67 -6
  32. data/src/core/channel/channel_args.h +7 -1
  33. data/src/core/channel/client_channel.c +26 -36
  34. data/src/core/channel/client_uchannel.c +1 -1
  35. data/src/core/channel/http_client_filter.c +2 -2
  36. data/src/core/channel/http_server_filter.c +2 -2
  37. data/src/core/channel/subchannel_call_holder.c +5 -7
  38. data/src/core/client_config/connector.c +3 -2
  39. data/src/core/client_config/connector.h +2 -2
  40. data/src/core/client_config/lb_policies/load_balancer_api.c +163 -0
  41. data/src/core/client_config/lb_policies/load_balancer_api.h +85 -0
  42. data/src/core/client_config/lb_policies/pick_first.c +10 -11
  43. data/src/core/client_config/lb_policies/round_robin.c +7 -8
  44. data/src/core/client_config/lb_policy.c +3 -3
  45. data/src/core/client_config/lb_policy.h +3 -2
  46. data/src/core/client_config/subchannel.c +51 -21
  47. data/src/core/client_config/subchannel.h +15 -6
  48. data/src/core/client_config/subchannel_index.c +261 -0
  49. data/src/core/client_config/subchannel_index.h +77 -0
  50. data/src/core/compression/{algorithm.c → compression_algorithm.c} +0 -0
  51. data/src/core/httpcli/httpcli.c +13 -11
  52. data/src/core/httpcli/httpcli.h +3 -2
  53. data/src/core/httpcli/httpcli_security_connector.c +7 -7
  54. data/src/core/iomgr/fd_posix.c +4 -2
  55. data/src/core/iomgr/iocp_windows.c +10 -6
  56. data/src/core/iomgr/iocp_windows.h +9 -2
  57. data/src/core/iomgr/iomgr.c +18 -2
  58. data/src/core/iomgr/iomgr_internal.h +5 -1
  59. data/src/core/iomgr/pollset.h +9 -10
  60. data/src/core/iomgr/pollset_multipoller_with_epoll.c +1 -0
  61. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +10 -5
  62. data/src/core/iomgr/pollset_posix.c +30 -35
  63. data/src/core/iomgr/pollset_posix.h +10 -6
  64. data/src/core/iomgr/pollset_set.h +3 -9
  65. data/src/core/iomgr/pollset_set_posix.c +23 -3
  66. data/src/core/iomgr/pollset_set_posix.h +2 -18
  67. data/src/core/iomgr/pollset_set_windows.c +3 -3
  68. data/src/core/iomgr/pollset_set_windows.h +2 -2
  69. data/src/core/iomgr/pollset_windows.c +24 -21
  70. data/src/core/iomgr/pollset_windows.h +1 -5
  71. data/src/core/iomgr/tcp_client_posix.c +7 -5
  72. data/src/core/iomgr/tcp_posix.c +4 -2
  73. data/src/core/iomgr/tcp_server_windows.c +1 -2
  74. data/src/core/iomgr/timer.c +2 -3
  75. data/src/core/iomgr/timer.h +21 -1
  76. data/src/core/iomgr/timer_heap.c +10 -12
  77. data/src/core/iomgr/udp_server.c +5 -4
  78. data/src/core/iomgr/udp_server.h +1 -0
  79. data/src/core/iomgr/workqueue_posix.c +1 -0
  80. data/src/core/iomgr/workqueue_posix.h +3 -1
  81. data/src/core/proto/grpc/lb/v0/load_balancer.pb.c +119 -0
  82. data/src/core/proto/grpc/lb/v0/load_balancer.pb.h +182 -0
  83. data/src/core/security/{base64.c → b64.c} +1 -1
  84. data/src/core/security/{base64.h → b64.h} +1 -1
  85. data/src/core/security/client_auth_filter.c +0 -1
  86. data/src/core/security/credentials.c +12 -5
  87. data/src/core/security/credentials.h +3 -3
  88. data/src/core/security/google_default_credentials.c +24 -19
  89. data/src/core/security/handshake.c +15 -7
  90. data/src/core/security/handshake.h +2 -1
  91. data/src/core/security/json_token.c +1 -1
  92. data/src/core/security/jwt_verifier.c +1 -1
  93. data/src/core/security/security_connector.c +84 -64
  94. data/src/core/security/security_connector.h +42 -22
  95. data/src/core/security/security_context.c +8 -3
  96. data/src/core/security/server_auth_filter.c +2 -2
  97. data/src/core/security/server_secure_chttp2.c +7 -7
  98. data/src/core/support/avl.c +2 -2
  99. data/src/core/support/env_linux.c +17 -0
  100. data/src/core/support/{file.c → load_file.c} +2 -2
  101. data/src/core/support/{file.h → load_file.h} +4 -12
  102. data/src/core/support/sync.c +6 -1
  103. data/src/core/support/time_posix.c +1 -1
  104. data/src/core/{iomgr/timer_internal.h → support/tmpfile.h} +17 -23
  105. data/src/core/support/{file_posix.c → tmpfile_posix.c} +2 -2
  106. data/src/core/support/{file_win32.c → tmpfile_win32.c} +2 -2
  107. data/src/core/surface/alarm.c +3 -2
  108. data/src/core/surface/call.c +102 -52
  109. data/src/core/surface/channel_create.c +1 -1
  110. data/src/core/surface/completion_queue.c +73 -41
  111. data/src/core/surface/init.c +4 -0
  112. data/src/core/surface/lame_client.c +1 -2
  113. data/src/core/surface/secure_channel_create.c +6 -7
  114. data/src/core/surface/server.c +13 -5
  115. data/src/core/surface/validate_metadata.c +1 -1
  116. data/src/core/surface/version.c +1 -1
  117. data/src/core/transport/chttp2/internal.h +22 -10
  118. data/src/core/transport/chttp2/parsing.c +3 -3
  119. data/src/core/transport/chttp2/stream_lists.c +39 -21
  120. data/src/core/transport/chttp2/writing.c +19 -28
  121. data/src/core/transport/chttp2_transport.c +80 -37
  122. data/src/core/transport/metadata.c +8 -0
  123. data/src/core/transport/static_metadata.c +17 -17
  124. data/src/core/transport/static_metadata.h +3 -3
  125. data/src/core/transport/transport.c +2 -1
  126. data/src/core/transport/transport.h +12 -5
  127. data/src/ruby/ext/grpc/extconf.rb +1 -0
  128. data/src/ruby/ext/grpc/rb_call.c +6 -0
  129. data/src/ruby/ext/grpc/rb_call_credentials.c +12 -14
  130. data/src/ruby/ext/grpc/rb_channel.c +8 -14
  131. data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -12
  132. data/src/ruby/ext/grpc/rb_grpc.c +19 -18
  133. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  134. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +8 -2
  135. data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
  136. data/src/ruby/lib/grpc/errors.rb +2 -2
  137. data/src/ruby/lib/grpc/generic/rpc_server.rb +58 -39
  138. data/src/ruby/lib/grpc/version.rb +1 -1
  139. data/src/ruby/pb/README.md +2 -2
  140. data/src/ruby/pb/generate_proto_ruby.sh +2 -2
  141. data/src/ruby/pb/grpc/health/checker.rb +11 -11
  142. data/src/ruby/pb/grpc/health/v1/health.rb +28 -0
  143. data/src/ruby/pb/grpc/health/{v1alpha → v1}/health_services.rb +4 -4
  144. data/src/ruby/spec/client_server_spec.rb +2 -1
  145. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -22
  146. data/src/ruby/spec/pb/health/checker_spec.rb +22 -36
  147. data/third_party/nanopb/pb.h +547 -0
  148. data/third_party/nanopb/pb_common.c +97 -0
  149. data/third_party/nanopb/pb_common.h +42 -0
  150. data/third_party/nanopb/pb_decode.c +1319 -0
  151. data/third_party/nanopb/pb_decode.h +149 -0
  152. data/third_party/nanopb/pb_encode.c +690 -0
  153. data/third_party/nanopb/pb_encode.h +154 -0
  154. metadata +32 -16
  155. data/src/ruby/pb/grpc/health/v1alpha/health.rb +0 -29
@@ -0,0 +1,77 @@
1
+ /*
2
+ *
3
+ * Copyright 2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
35
+ #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
36
+
37
+ #include "src/core/client_config/connector.h"
38
+ #include "src/core/client_config/subchannel.h"
39
+
40
+ /** \file Provides an index of active subchannels so that they can be
41
+ shared amongst channels */
42
+
43
+ typedef struct grpc_subchannel_key grpc_subchannel_key;
44
+
45
+ /** Create a key that can be used to uniquely identify a subchannel */
46
+ grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *con,
47
+ grpc_subchannel_args *args);
48
+
49
+ /** Destroy a subchannel key */
50
+ void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx,
51
+ grpc_subchannel_key *key);
52
+
53
+ /** Given a subchannel key, find the subchannel registered for it.
54
+ Returns NULL if no such channel exists.
55
+ Thread-safe. */
56
+ grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx,
57
+ grpc_subchannel_key *key);
58
+
59
+ /** Register a subchannel against a key.
60
+ Takes ownership of \a constructed.
61
+ Returns the registered subchannel. This may be different from
62
+ \a constructed in the case of a registration race. */
63
+ grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx,
64
+ grpc_subchannel_key *key,
65
+ grpc_subchannel *constructed);
66
+
67
+ /** Remove \a constructed as the registered subchannel for \a key. */
68
+ void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx,
69
+ grpc_subchannel_key *key,
70
+ grpc_subchannel *constructed);
71
+
72
+ /** Initialize the subchannel index (global) */
73
+ void grpc_subchannel_index_init(void);
74
+ /** Shutdown the subchannel index (global) */
75
+ void grpc_subchannel_index_shutdown(void);
76
+
77
+ #endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */
@@ -31,20 +31,22 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/iomgr/sockaddr.h"
35
34
  #include "src/core/httpcli/httpcli.h"
35
+ #include "src/core/iomgr/sockaddr.h"
36
36
 
37
37
  #include <string.h>
38
38
 
39
+ #include <grpc/support/alloc.h>
40
+ #include <grpc/support/log.h>
41
+ #include <grpc/support/string_util.h>
42
+
43
+ #include "src/core/httpcli/format_request.h"
44
+ #include "src/core/httpcli/parser.h"
39
45
  #include "src/core/iomgr/endpoint.h"
46
+ #include "src/core/iomgr/iomgr_internal.h"
40
47
  #include "src/core/iomgr/resolve_address.h"
41
48
  #include "src/core/iomgr/tcp_client.h"
42
- #include "src/core/httpcli/format_request.h"
43
- #include "src/core/httpcli/parser.h"
44
49
  #include "src/core/support/string.h"
45
- #include <grpc/support/alloc.h>
46
- #include <grpc/support/log.h>
47
- #include <grpc/support/string_util.h>
48
50
 
49
51
  typedef struct {
50
52
  gpr_slice request_text;
@@ -84,18 +86,18 @@ const grpc_httpcli_handshaker grpc_httpcli_plaintext = {"http",
84
86
  plaintext_handshake};
85
87
 
86
88
  void grpc_httpcli_context_init(grpc_httpcli_context *context) {
87
- grpc_pollset_set_init(&context->pollset_set);
89
+ context->pollset_set = grpc_pollset_set_create();
88
90
  }
89
91
 
90
92
  void grpc_httpcli_context_destroy(grpc_httpcli_context *context) {
91
- grpc_pollset_set_destroy(&context->pollset_set);
93
+ grpc_pollset_set_destroy(context->pollset_set);
92
94
  }
93
95
 
94
96
  static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req);
95
97
 
96
98
  static void finish(grpc_exec_ctx *exec_ctx, internal_request *req,
97
99
  int success) {
98
- grpc_pollset_set_del_pollset(exec_ctx, &req->context->pollset_set,
100
+ grpc_pollset_set_del_pollset(exec_ctx, req->context->pollset_set,
99
101
  req->pollset);
100
102
  req->on_response(exec_ctx, req->user_data, success ? &req->parser.r : NULL);
101
103
  grpc_httpcli_parser_destroy(&req->parser);
@@ -197,7 +199,7 @@ static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req) {
197
199
  addr = &req->addresses->addrs[req->next_address++];
198
200
  grpc_closure_init(&req->connected, on_connected, req);
199
201
  grpc_tcp_client_connect(
200
- exec_ctx, &req->connected, &req->ep, &req->context->pollset_set,
202
+ exec_ctx, &req->connected, &req->ep, req->context->pollset_set,
201
203
  (struct sockaddr *)&addr->addr, addr->len, req->deadline);
202
204
  }
203
205
 
@@ -237,7 +239,7 @@ static void internal_request_begin(
237
239
  req->host = gpr_strdup(request->host);
238
240
  req->ssl_host_override = gpr_strdup(request->ssl_host_override);
239
241
 
240
- grpc_pollset_set_add_pollset(exec_ctx, &req->context->pollset_set,
242
+ grpc_pollset_set_add_pollset(exec_ctx, req->context->pollset_set,
241
243
  req->pollset);
242
244
  grpc_resolve_address(request->host, req->handshaker->default_port,
243
245
  on_resolved, req);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -39,6 +39,7 @@
39
39
  #include <grpc/support/time.h>
40
40
 
41
41
  #include "src/core/iomgr/endpoint.h"
42
+ #include "src/core/iomgr/iomgr_internal.h"
42
43
  #include "src/core/iomgr/pollset_set.h"
43
44
 
44
45
  /* User agent this library reports */
@@ -56,7 +57,7 @@ typedef struct grpc_httpcli_header {
56
57
  TODO(ctiller): allow caching and capturing multiple requests for the
57
58
  same content and combining them */
58
59
  typedef struct grpc_httpcli_context {
59
- grpc_pollset_set pollset_set;
60
+ grpc_pollset_set *pollset_set;
60
61
  } grpc_httpcli_context;
61
62
 
62
63
  typedef struct {
@@ -59,7 +59,7 @@ static void httpcli_ssl_destroy(grpc_security_connector *sc) {
59
59
  }
60
60
 
61
61
  static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
62
- grpc_security_connector *sc,
62
+ grpc_channel_security_connector *sc,
63
63
  grpc_endpoint *nonsecure_endpoint,
64
64
  grpc_security_handshake_done_cb cb,
65
65
  void *user_data) {
@@ -78,8 +78,8 @@ static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
78
78
  tsi_result_to_string(result));
79
79
  cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
80
80
  } else {
81
- grpc_do_security_handshake(exec_ctx, handshaker, sc, nonsecure_endpoint, cb,
82
- user_data);
81
+ grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, true,
82
+ nonsecure_endpoint, cb, user_data);
83
83
  }
84
84
  }
85
85
 
@@ -103,7 +103,7 @@ static void httpcli_ssl_check_peer(grpc_exec_ctx *exec_ctx,
103
103
  }
104
104
 
105
105
  static grpc_security_connector_vtable httpcli_ssl_vtable = {
106
- httpcli_ssl_destroy, httpcli_ssl_do_handshake, httpcli_ssl_check_peer};
106
+ httpcli_ssl_destroy, httpcli_ssl_check_peer};
107
107
 
108
108
  static grpc_security_status httpcli_ssl_channel_security_connector_create(
109
109
  const unsigned char *pem_root_certs, size_t pem_root_certs_size,
@@ -121,7 +121,6 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create(
121
121
  memset(c, 0, sizeof(grpc_httpcli_ssl_channel_security_connector));
122
122
 
123
123
  gpr_ref_init(&c->base.base.refcount, 1);
124
- c->base.base.is_client_side = 1;
125
124
  c->base.base.vtable = &httpcli_ssl_vtable;
126
125
  if (secure_peer_name != NULL) {
127
126
  c->secure_peer_name = gpr_strdup(secure_peer_name);
@@ -136,6 +135,7 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create(
136
135
  *sc = NULL;
137
136
  return GRPC_SECURITY_ERROR;
138
137
  }
138
+ c->base.do_handshake = httpcli_ssl_do_handshake;
139
139
  *sc = &c->base;
140
140
  return GRPC_SECURITY_OK;
141
141
  }
@@ -180,8 +180,8 @@ static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
180
180
  GPR_ASSERT(httpcli_ssl_channel_security_connector_create(
181
181
  pem_root_certs, pem_root_certs_size, host, &sc) ==
182
182
  GRPC_SECURITY_OK);
183
- grpc_security_connector_do_handshake(exec_ctx, &sc->base, tcp,
184
- on_secure_transport_setup_done, c);
183
+ grpc_channel_security_connector_do_handshake(
184
+ exec_ctx, sc, tcp, on_secure_transport_setup_done, c);
185
185
  GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
186
186
  }
187
187
 
@@ -46,6 +46,8 @@
46
46
  #include <grpc/support/string_util.h>
47
47
  #include <grpc/support/useful.h>
48
48
 
49
+ #include "src/core/iomgr/pollset_posix.h"
50
+
49
51
  #define CLOSURE_NOT_READY ((grpc_closure *)0)
50
52
  #define CLOSURE_READY ((grpc_closure *)1)
51
53
 
@@ -175,11 +177,11 @@ int grpc_fd_is_orphaned(grpc_fd *fd) {
175
177
  }
176
178
 
177
179
  static void pollset_kick_locked(grpc_fd_watcher *watcher) {
178
- gpr_mu_lock(GRPC_POLLSET_MU(watcher->pollset));
180
+ gpr_mu_lock(&watcher->pollset->mu);
179
181
  GPR_ASSERT(watcher->worker);
180
182
  grpc_pollset_kick_ext(watcher->pollset, watcher->worker,
181
183
  GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP);
182
- gpr_mu_unlock(GRPC_POLLSET_MU(watcher->pollset));
184
+ gpr_mu_unlock(&watcher->pollset->mu);
183
185
  }
184
186
 
185
187
  static void maybe_wake_one_watcher_locked(grpc_fd *fd) {
@@ -42,7 +42,7 @@
42
42
  #include <grpc/support/alloc.h>
43
43
  #include <grpc/support/thd.h>
44
44
 
45
- #include "src/core/iomgr/timer_internal.h"
45
+ #include "src/core/iomgr/timer.h"
46
46
  #include "src/core/iomgr/iocp_windows.h"
47
47
  #include "src/core/iomgr/iomgr_internal.h"
48
48
  #include "src/core/iomgr/socket_windows.h"
@@ -71,7 +71,8 @@ static DWORD deadline_to_millis_timeout(gpr_timespec deadline,
71
71
  timeout, gpr_time_from_nanos(GPR_NS_PER_MS - 1, GPR_TIMESPAN)));
72
72
  }
73
73
 
74
- void grpc_iocp_work(grpc_exec_ctx *exec_ctx, gpr_timespec deadline) {
74
+ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx,
75
+ gpr_timespec deadline) {
75
76
  BOOL success;
76
77
  DWORD bytes = 0;
77
78
  DWORD flags = 0;
@@ -84,14 +85,14 @@ void grpc_iocp_work(grpc_exec_ctx *exec_ctx, gpr_timespec deadline) {
84
85
  g_iocp, &bytes, &completion_key, &overlapped,
85
86
  deadline_to_millis_timeout(deadline, gpr_now(deadline.clock_type)));
86
87
  if (success == 0 && overlapped == NULL) {
87
- return;
88
+ return GRPC_IOCP_WORK_TIMEOUT;
88
89
  }
89
90
  GPR_ASSERT(completion_key && overlapped);
90
91
  if (overlapped == &g_iocp_custom_overlap) {
91
92
  gpr_atm_full_fetch_add(&g_custom_events, -1);
92
93
  if (completion_key == (ULONG_PTR)&g_iocp_kick_token) {
93
94
  /* We were awoken from a kick. */
94
- return;
95
+ return GRPC_IOCP_WORK_KICK;
95
96
  }
96
97
  gpr_log(GPR_ERROR, "Unknown custom completion key.");
97
98
  abort();
@@ -121,6 +122,7 @@ void grpc_iocp_work(grpc_exec_ctx *exec_ctx, gpr_timespec deadline) {
121
122
  }
122
123
  gpr_mu_unlock(&socket->state_mu);
123
124
  grpc_exec_ctx_enqueue(exec_ctx, closure, true, NULL);
125
+ return GRPC_IOCP_WORK_WORK;
124
126
  }
125
127
 
126
128
  void grpc_iocp_init(void) {
@@ -140,10 +142,12 @@ void grpc_iocp_kick(void) {
140
142
 
141
143
  void grpc_iocp_flush(void) {
142
144
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
145
+ grpc_iocp_work_status work_status;
143
146
 
144
147
  do {
145
- grpc_iocp_work(&exec_ctx, gpr_inf_past(GPR_CLOCK_MONOTONIC));
146
- } while (grpc_exec_ctx_flush(&exec_ctx));
148
+ work_status = grpc_iocp_work(&exec_ctx, gpr_inf_past(GPR_CLOCK_MONOTONIC));
149
+ } while (work_status == GRPC_IOCP_WORK_KICK ||
150
+ grpc_exec_ctx_flush(&exec_ctx));
147
151
  }
148
152
 
149
153
  void grpc_iocp_shutdown(void) {
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,14 @@
38
38
 
39
39
  #include "src/core/iomgr/socket_windows.h"
40
40
 
41
- void grpc_iocp_work(grpc_exec_ctx *exec_ctx, gpr_timespec deadline);
41
+ typedef enum {
42
+ GRPC_IOCP_WORK_WORK,
43
+ GRPC_IOCP_WORK_TIMEOUT,
44
+ GRPC_IOCP_WORK_KICK
45
+ } grpc_iocp_work_status;
46
+
47
+ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx,
48
+ gpr_timespec deadline);
42
49
  void grpc_iocp_init(void);
43
50
  void grpc_iocp_kick(void);
44
51
  void grpc_iocp_flush(void);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -41,9 +41,11 @@
41
41
  #include <grpc/support/string_util.h>
42
42
  #include <grpc/support/sync.h>
43
43
  #include <grpc/support/thd.h>
44
+ #include <grpc/support/useful.h>
44
45
 
45
46
  #include "src/core/iomgr/iomgr_internal.h"
46
- #include "src/core/iomgr/timer_internal.h"
47
+ #include "src/core/iomgr/timer.h"
48
+ #include "src/core/support/env.h"
47
49
  #include "src/core/support/string.h"
48
50
 
49
51
  static gpr_mu g_mu;
@@ -116,6 +118,9 @@ void grpc_iomgr_shutdown(void) {
116
118
  "memory leaks are likely",
117
119
  count_objects());
118
120
  dump_objects("LEAKED");
121
+ if (grpc_iomgr_abort_on_leaks()) {
122
+ abort();
123
+ }
119
124
  }
120
125
  break;
121
126
  }
@@ -154,3 +159,14 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object *obj) {
154
159
  gpr_mu_unlock(&g_mu);
155
160
  gpr_free(obj->name);
156
161
  }
162
+
163
+ bool grpc_iomgr_abort_on_leaks(void) {
164
+ char *env = gpr_getenv("GRPC_ABORT_ON_LEAKS");
165
+ if (env == NULL) return false;
166
+ static const char *truthy[] = {"yes", "Yes", "YES", "true",
167
+ "True", "TRUE", "1"};
168
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
169
+ if (0 == strcmp(env, truthy[i])) return true;
170
+ }
171
+ return false;
172
+ }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,8 @@
34
34
  #ifndef GRPC_INTERNAL_CORE_IOMGR_IOMGR_INTERNAL_H
35
35
  #define GRPC_INTERNAL_CORE_IOMGR_IOMGR_INTERNAL_H
36
36
 
37
+ #include <stdbool.h>
38
+
37
39
  #include "src/core/iomgr/iomgr.h"
38
40
  #include <grpc/support/sync.h>
39
41
 
@@ -55,4 +57,6 @@ void grpc_iomgr_platform_flush(void);
55
57
  /** tear down all platform specific global iomgr structures */
56
58
  void grpc_iomgr_platform_shutdown(void);
57
59
 
60
+ bool grpc_iomgr_abort_on_leaks(void);
61
+
58
62
  #endif /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_INTERNAL_H */
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -35,8 +35,11 @@
35
35
  #define GRPC_INTERNAL_CORE_IOMGR_POLLSET_H
36
36
 
37
37
  #include <grpc/support/port_platform.h>
38
+ #include <grpc/support/sync.h>
38
39
  #include <grpc/support/time.h>
39
40
 
41
+ #include "src/core/iomgr/exec_ctx.h"
42
+
40
43
  #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
41
44
 
42
45
  /* A grpc_pollset is a set of file descriptors that a higher level item is
@@ -46,15 +49,11 @@
46
49
  - a completion queue might keep a pollset with an entry for each transport
47
50
  that is servicing a call that it's tracking */
48
51
 
49
- #ifdef GPR_POSIX_SOCKET
50
- #include "src/core/iomgr/pollset_posix.h"
51
- #endif
52
-
53
- #ifdef GPR_WIN32
54
- #include "src/core/iomgr/pollset_windows.h"
55
- #endif
52
+ typedef struct grpc_pollset grpc_pollset;
53
+ typedef struct grpc_pollset_worker grpc_pollset_worker;
56
54
 
57
- void grpc_pollset_init(grpc_pollset *pollset);
55
+ size_t grpc_pollset_size(void);
56
+ void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu);
58
57
  /* Begin shutting down the pollset, and call closure when done.
59
58
  * GRPC_POLLSET_MU(pollset) must be held */
60
59
  void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
@@ -83,7 +82,7 @@ void grpc_pollset_destroy(grpc_pollset *pollset);
83
82
  pollset
84
83
  lock */
85
84
  void grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
86
- grpc_pollset_worker *worker, gpr_timespec now,
85
+ grpc_pollset_worker **worker, gpr_timespec now,
87
86
  gpr_timespec deadline);
88
87
 
89
88
  /* Break one polling thread out of polling work for this pollset.