grpc 1.21.0 → 1.22.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +422 -62
  3. data/include/grpc/grpc_security.h +61 -5
  4. data/include/grpc/grpc_security_constants.h +1 -1
  5. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  6. data/include/grpc/slice.h +2 -2
  7. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
  8. data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
  10. data/src/core/ext/filters/client_channel/client_channel.h +0 -8
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
  16. data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  27. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
  31. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
  34. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
  35. data/src/core/ext/filters/client_channel/server_address.cc +4 -6
  36. data/src/core/ext/filters/client_channel/server_address.h +1 -3
  37. data/src/core/ext/filters/client_channel/service_config.cc +20 -22
  38. data/src/core/ext/filters/client_channel/service_config.h +26 -28
  39. data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
  40. data/src/core/ext/filters/client_channel/subchannel.h +97 -23
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
  43. data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
  45. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  46. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
  47. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
  48. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
  49. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
  50. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
  51. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  52. data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
  53. data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
  54. data/src/core/lib/channel/channelz.cc +136 -19
  55. data/src/core/lib/channel/channelz.h +36 -40
  56. data/src/core/lib/channel/channelz_registry.cc +74 -106
  57. data/src/core/lib/channel/channelz_registry.h +10 -28
  58. data/src/core/lib/channel/context.h +1 -1
  59. data/src/core/lib/channel/handshaker.cc +6 -0
  60. data/src/core/lib/compression/compression.cc +13 -8
  61. data/src/core/lib/compression/compression_internal.cc +14 -10
  62. data/src/core/lib/compression/compression_internal.h +1 -1
  63. data/src/core/lib/compression/stream_compression.cc +3 -2
  64. data/src/core/lib/compression/stream_compression.h +2 -2
  65. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  66. data/src/core/lib/gpr/env.h +1 -1
  67. data/src/core/lib/gpr/string.cc +8 -1
  68. data/src/core/lib/gpr/string.h +6 -1
  69. data/src/core/lib/gprpp/fork.cc +1 -1
  70. data/src/core/lib/gprpp/fork.h +5 -1
  71. data/src/core/lib/gprpp/global_config.h +9 -0
  72. data/src/core/lib/gprpp/global_config_custom.h +1 -1
  73. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  74. data/src/core/lib/gprpp/map.h +38 -21
  75. data/src/core/lib/gprpp/memory.h +2 -2
  76. data/src/core/lib/gprpp/orphanable.h +1 -1
  77. data/src/core/lib/gprpp/ref_counted.h +9 -4
  78. data/src/core/lib/http/httpcli.cc +3 -3
  79. data/src/core/lib/iomgr/buffer_list.h +1 -1
  80. data/src/core/lib/iomgr/call_combiner.cc +1 -1
  81. data/src/core/lib/iomgr/call_combiner.h +1 -1
  82. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  83. data/src/core/lib/iomgr/cfstream_handle.h +4 -0
  84. data/src/core/lib/iomgr/error.cc +3 -3
  85. data/src/core/lib/iomgr/error.h +9 -3
  86. data/src/core/lib/iomgr/error_internal.h +1 -1
  87. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
  88. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  89. data/src/core/lib/iomgr/ev_posix.h +3 -2
  90. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  91. data/src/core/lib/iomgr/iomgr.cc +4 -4
  92. data/src/core/lib/iomgr/lockfree_event.cc +1 -1
  93. data/src/core/lib/iomgr/port.h +5 -1
  94. data/src/core/lib/iomgr/tcp_posix.cc +1 -3
  95. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  96. data/src/core/lib/iomgr/tcp_server.h +24 -0
  97. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
  98. data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
  99. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  100. data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
  101. data/src/core/lib/iomgr/tcp_uv.cc +5 -6
  102. data/src/core/lib/iomgr/timer.h +2 -1
  103. data/src/core/lib/iomgr/udp_server.cc +2 -2
  104. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  105. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  106. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  107. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  108. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
  109. data/src/core/lib/security/transport/auth_filters.h +3 -0
  110. data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
  111. data/src/core/lib/security/transport/security_handshaker.cc +7 -7
  112. data/src/core/lib/slice/b64.h +2 -2
  113. data/src/core/lib/slice/slice.cc +82 -10
  114. data/src/core/lib/slice/slice_buffer.cc +49 -21
  115. data/src/core/lib/slice/slice_hash_table.h +2 -2
  116. data/src/core/lib/slice/slice_intern.cc +15 -16
  117. data/src/core/lib/slice/slice_internal.h +52 -0
  118. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  119. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  120. data/src/core/lib/slice/slice_utils.h +50 -0
  121. data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
  122. data/src/core/lib/surface/call.cc +14 -8
  123. data/src/core/lib/surface/channel.cc +89 -97
  124. data/src/core/lib/surface/channel.h +60 -6
  125. data/src/core/lib/surface/completion_queue.cc +49 -36
  126. data/src/core/lib/surface/completion_queue.h +2 -1
  127. data/src/core/lib/surface/server.cc +8 -8
  128. data/src/core/lib/surface/validate_metadata.cc +14 -8
  129. data/src/core/lib/surface/validate_metadata.h +13 -2
  130. data/src/core/lib/surface/version.cc +1 -1
  131. data/src/core/lib/transport/metadata.cc +56 -26
  132. data/src/core/lib/transport/metadata.h +91 -75
  133. data/src/core/lib/transport/static_metadata.cc +262 -176
  134. data/src/core/lib/transport/static_metadata.h +272 -180
  135. data/src/core/lib/transport/transport.cc +1 -1
  136. data/src/core/lib/transport/transport.h +8 -2
  137. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  138. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
  140. data/src/ruby/lib/grpc/version.rb +1 -1
  141. metadata +37 -35
@@ -29,12 +29,12 @@
29
29
 
30
30
  // Add this to a class that want to use Delete(), but has a private or
31
31
  // protected destructor.
32
- #define GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \
32
+ #define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \
33
33
  template <typename T> \
34
34
  friend void grpc_core::Delete(T*);
35
35
  // Add this to a class that want to use New(), but has a private or
36
36
  // protected constructor.
37
- #define GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW \
37
+ #define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW \
38
38
  template <typename T, typename... Args> \
39
39
  friend T* grpc_core::New(Args&&...);
40
40
 
@@ -84,7 +84,7 @@ class InternallyRefCounted : public Orphanable {
84
84
  GRPC_ABSTRACT_BASE_CLASS
85
85
 
86
86
  protected:
87
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
87
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
88
88
 
89
89
  // Allow RefCountedPtr<> to access Unref() and IncrementRefCount().
90
90
  template <typename T>
@@ -44,7 +44,7 @@ class PolymorphicRefCount {
44
44
  GRPC_ABSTRACT_BASE_CLASS
45
45
 
46
46
  protected:
47
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
47
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
48
48
 
49
49
  virtual ~PolymorphicRefCount() = default;
50
50
  };
@@ -57,7 +57,7 @@ class NonPolymorphicRefCount {
57
57
  GRPC_ABSTRACT_BASE_CLASS
58
58
 
59
59
  protected:
60
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
60
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
61
61
 
62
62
  ~NonPolymorphicRefCount() = default;
63
63
  };
@@ -180,7 +180,7 @@ class RefCount {
180
180
  // So, use NonPolymorphicRefCount only when both of the following conditions
181
181
  // are guaranteed to hold:
182
182
  // (a) Child is a concrete leaf class in RefCounted<Child>, and
183
- // (b) you are gauranteed to call Unref only on concrete leaf classes and not
183
+ // (b) you are guaranteed to call Unref only on concrete leaf classes and not
184
184
  // their parents.
185
185
  //
186
186
  // The following example is illegal, because calling Unref() will not call
@@ -221,6 +221,11 @@ class RefCounted : public Impl {
221
221
  }
222
222
  }
223
223
 
224
+ bool RefIfNonZero() { return refs_.RefIfNonZero(); }
225
+ bool RefIfNonZero(const DebugLocation& location, const char* reason) {
226
+ return refs_.RefIfNonZero(location, reason);
227
+ }
228
+
224
229
  // Not copyable nor movable.
225
230
  RefCounted(const RefCounted&) = delete;
226
231
  RefCounted& operator=(const RefCounted&) = delete;
@@ -228,7 +233,7 @@ class RefCounted : public Impl {
228
233
  GRPC_ABSTRACT_BASE_CLASS
229
234
 
230
235
  protected:
231
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
236
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
232
237
 
233
238
  // TraceFlagT is defined to accept both DebugOnlyTraceFlag and TraceFlag.
234
239
  // Note: RefCount tracing is only enabled on debug builds, even when a
@@ -28,6 +28,7 @@
28
28
 
29
29
  #include "src/core/lib/channel/channel_args.h"
30
30
  #include "src/core/lib/gpr/string.h"
31
+ #include "src/core/lib/gprpp/memory.h"
31
32
  #include "src/core/lib/http/format_request.h"
32
33
  #include "src/core/lib/http/parser.h"
33
34
  #include "src/core/lib/iomgr/endpoint.h"
@@ -112,12 +113,11 @@ static void append_error(internal_request* req, grpc_error* error) {
112
113
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed HTTP/1 client request");
113
114
  }
114
115
  grpc_resolved_address* addr = &req->addresses->addrs[req->next_address - 1];
115
- char* addr_text = grpc_sockaddr_to_uri(addr);
116
+ grpc_core::UniquePtr<char> addr_text(grpc_sockaddr_to_uri(addr));
116
117
  req->overall_error = grpc_error_add_child(
117
118
  req->overall_error,
118
119
  grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS,
119
- grpc_slice_from_copied_string(addr_text)));
120
- gpr_free(addr_text);
120
+ grpc_slice_from_moved_string(std::move(addr_text))));
121
121
  }
122
122
 
123
123
  static void do_read(internal_request* req) {
@@ -133,7 +133,7 @@ class TracedBuffer {
133
133
  grpc_error* shutdown_err);
134
134
 
135
135
  private:
136
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
136
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
137
137
 
138
138
  TracedBuffer(uint32_t seq_no, void* arg)
139
139
  : seq_no_(seq_no), arg_(arg), next_(nullptr) {}
@@ -28,7 +28,7 @@
28
28
 
29
29
  namespace grpc_core {
30
30
 
31
- TraceFlag grpc_call_combiner_trace(false, "call_combiner");
31
+ DebugOnlyTraceFlag grpc_call_combiner_trace(false, "call_combiner");
32
32
 
33
33
  namespace {
34
34
 
@@ -43,7 +43,7 @@
43
43
 
44
44
  namespace grpc_core {
45
45
 
46
- extern TraceFlag grpc_call_combiner_trace;
46
+ extern DebugOnlyTraceFlag grpc_call_combiner_trace;
47
47
 
48
48
  class CallCombiner {
49
49
  public:
@@ -18,6 +18,7 @@
18
18
 
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
+ #include "src/core/lib/gprpp/memory.h"
21
22
  #include "src/core/lib/iomgr/port.h"
22
23
 
23
24
  #ifdef GRPC_CFSTREAM
@@ -47,7 +48,7 @@ void CFStreamHandle::Release(void* info) {
47
48
 
48
49
  CFStreamHandle* CFStreamHandle::CreateStreamHandle(
49
50
  CFReadStreamRef read_stream, CFWriteStreamRef write_stream) {
50
- return new CFStreamHandle(read_stream, write_stream);
51
+ return grpc_core::New<CFStreamHandle>(read_stream, write_stream);
51
52
  }
52
53
 
53
54
  void CFStreamHandle::ReadCallback(CFReadStreamRef stream,
@@ -188,7 +189,7 @@ void CFStreamHandle::Unref(const char* file, int line, const char* reason) {
188
189
  reason, val, val - 1);
189
190
  }
190
191
  if (gpr_unref(&refcount_)) {
191
- delete this;
192
+ grpc_core::Delete<CFStreamHandle>(this);
192
193
  }
193
194
  }
194
195
 
@@ -29,6 +29,7 @@
29
29
  #ifdef GRPC_CFSTREAM
30
30
  #import <CoreFoundation/CoreFoundation.h>
31
31
 
32
+ #include "src/core/lib/gprpp/memory.h"
32
33
  #include "src/core/lib/iomgr/closure.h"
33
34
  #include "src/core/lib/iomgr/lockfree_event.h"
34
35
 
@@ -65,6 +66,9 @@ class CFStreamHandle final {
65
66
  dispatch_queue_t dispatch_queue_;
66
67
 
67
68
  gpr_refcount refcount_;
69
+
70
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
71
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
68
72
  };
69
73
 
70
74
  #ifdef DEBUG
@@ -795,9 +795,9 @@ grpc_error* grpc_wsa_error(const char* file, int line, int err,
795
795
  }
796
796
  #endif
797
797
 
798
- bool grpc_log_if_error(const char* what, grpc_error* error, const char* file,
799
- int line) {
800
- if (error == GRPC_ERROR_NONE) return true;
798
+ bool grpc_log_error(const char* what, grpc_error* error, const char* file,
799
+ int line) {
800
+ GPR_DEBUG_ASSERT(error != GRPC_ERROR_NONE);
801
801
  const char* msg = grpc_error_string(error);
802
802
  gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "%s: %s", what, msg);
803
803
  GRPC_ERROR_UNREF(error);
@@ -261,9 +261,15 @@ grpc_error* grpc_wsa_error(const char* file, int line, int err,
261
261
  #define GRPC_WSA_ERROR(err, call_name) \
262
262
  grpc_wsa_error(__FILE__, __LINE__, err, call_name)
263
263
 
264
- bool grpc_log_if_error(const char* what, grpc_error* error, const char* file,
265
- int line);
264
+ bool grpc_log_error(const char* what, grpc_error* error, const char* file,
265
+ int line);
266
+ inline bool grpc_log_if_error(const char* what, grpc_error* error,
267
+ const char* file, int line) {
268
+ return error == GRPC_ERROR_NONE ? true
269
+ : grpc_log_error(what, error, file, line);
270
+ }
271
+
266
272
  #define GRPC_LOG_IF_ERROR(what, error) \
267
- grpc_log_if_error((what), (error), __FILE__, __LINE__)
273
+ (grpc_log_if_error((what), (error), __FILE__, __LINE__))
268
274
 
269
275
  #endif /* GRPC_CORE_LIB_IOMGR_ERROR_H */
@@ -49,7 +49,7 @@ struct grpc_error {
49
49
  uint8_t strs[GRPC_ERROR_STR_MAX];
50
50
  uint8_t times[GRPC_ERROR_TIME_MAX];
51
51
  // The child errors are stored in the arena, but are effectively a linked list
52
- // structure, since they are contained withing grpc_linked_error objects.
52
+ // structure, since they are contained within grpc_linked_error objects.
53
53
  uint8_t first_err;
54
54
  uint8_t last_err;
55
55
  // The arena is dynamically reallocated with a grow factor of 1.5.
@@ -1031,7 +1031,7 @@ static grpc_error* pollset_work(grpc_pollset* ps,
1031
1031
  process the pending epoll events.
1032
1032
 
1033
1033
  The reason for decoupling do_epoll_wait and process_epoll_events is to
1034
- better distrubute the work (i.e handling epoll events) across multiple
1034
+ better distribute the work (i.e handling epoll events) across multiple
1035
1035
  threads
1036
1036
 
1037
1037
  process_epoll_events() returns very quickly: It just queues the work on
@@ -44,11 +44,11 @@ GPR_GLOBAL_CONFIG_DEFINE_STRING(
44
44
  "This is a comma-separated list of engines, which are tried in priority "
45
45
  "order first -> last.")
46
46
 
47
- grpc_core::TraceFlag grpc_polling_trace(false,
48
- "polling"); /* Disabled by default */
47
+ grpc_core::DebugOnlyTraceFlag grpc_polling_trace(
48
+ false, "polling"); /* Disabled by default */
49
49
 
50
50
  /* Traces fd create/close operations */
51
- grpc_core::TraceFlag grpc_fd_trace(false, "fd_trace");
51
+ grpc_core::DebugOnlyTraceFlag grpc_fd_trace(false, "fd_trace");
52
52
  grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount");
53
53
  grpc_core::DebugOnlyTraceFlag grpc_polling_api_trace(false, "polling_api");
54
54
 
@@ -32,8 +32,9 @@
32
32
 
33
33
  GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_poll_strategy);
34
34
 
35
- extern grpc_core::TraceFlag grpc_fd_trace; /* Disabled by default */
36
- extern grpc_core::TraceFlag grpc_polling_trace; /* Disabled by default */
35
+ extern grpc_core::DebugOnlyTraceFlag grpc_fd_trace; /* Disabled by default */
36
+ extern grpc_core::DebugOnlyTraceFlag
37
+ grpc_polling_trace; /* Disabled by default */
37
38
 
38
39
  #define GRPC_FD_TRACE(format, ...) \
39
40
  if (GRPC_TRACE_FLAG_ENABLED(grpc_fd_trace)) { \
@@ -24,7 +24,7 @@
24
24
 
25
25
  #include "src/core/lib/debug/trace.h"
26
26
 
27
- grpc_core::TraceFlag grpc_polling_trace(false,
28
- "polling"); /* Disabled by default */
27
+ grpc_core::DebugOnlyTraceFlag grpc_polling_trace(
28
+ false, "polling"); /* Disabled by default */
29
29
 
30
30
  #endif // GRPC_WINSOCK_SOCKET
@@ -49,6 +49,7 @@ static gpr_mu g_mu;
49
49
  static gpr_cv g_rcv;
50
50
  static int g_shutdown;
51
51
  static grpc_iomgr_object g_root_object;
52
+ static bool g_grpc_abort_on_leaks;
52
53
 
53
54
  void grpc_iomgr_init() {
54
55
  grpc_core::ExecCtx exec_ctx;
@@ -57,11 +58,12 @@ void grpc_iomgr_init() {
57
58
  gpr_mu_init(&g_mu);
58
59
  gpr_cv_init(&g_rcv);
59
60
  grpc_core::Executor::InitAll();
60
- grpc_timer_list_init();
61
61
  g_root_object.next = g_root_object.prev = &g_root_object;
62
62
  g_root_object.name = (char*)"root";
63
63
  grpc_iomgr_platform_init();
64
+ grpc_timer_list_init();
64
65
  grpc_core::grpc_errqueue_init();
66
+ g_grpc_abort_on_leaks = GPR_GLOBAL_CONFIG_GET(grpc_abort_on_leaks);
65
67
  }
66
68
 
67
69
  void grpc_iomgr_start() { grpc_timer_manager_init(); }
@@ -189,6 +191,4 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object* obj) {
189
191
  gpr_free(obj->name);
190
192
  }
191
193
 
192
- bool grpc_iomgr_abort_on_leaks(void) {
193
- return GPR_GLOBAL_CONFIG_GET(grpc_abort_on_leaks);
194
- }
194
+ bool grpc_iomgr_abort_on_leaks(void) { return g_grpc_abort_on_leaks; }
@@ -24,7 +24,7 @@
24
24
 
25
25
  #include "src/core/lib/debug/trace.h"
26
26
 
27
- extern grpc_core::TraceFlag grpc_polling_trace;
27
+ extern grpc_core::DebugOnlyTraceFlag grpc_polling_trace;
28
28
 
29
29
  /* 'state' holds the to call when the fd is readable or writable respectively.
30
30
  It can contain one of the following values:
@@ -26,6 +26,11 @@
26
26
  #define GRPC_CUSTOM_SOCKET
27
27
  #endif
28
28
  #endif
29
+ /* This needs to be separate from the other conditions because it needs to
30
+ * apply to custom sockets too */
31
+ #ifdef GPR_WINDOWS
32
+ #define GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY 1
33
+ #endif
29
34
  #if defined(GRPC_CUSTOM_SOCKET)
30
35
  // Do Nothing
31
36
  #elif defined(GPR_MANYLINUX1)
@@ -45,7 +50,6 @@
45
50
  #define GRPC_WINSOCK_SOCKET 1
46
51
  #define GRPC_WINDOWS_SOCKETUTILS 1
47
52
  #define GRPC_WINDOWS_SOCKET_ARES_EV_DRIVER 1
48
- #define GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY 1
49
53
  #elif defined(GPR_ANDROID)
50
54
  #define GRPC_HAVE_IPV6_RECVPKTINFO 1
51
55
  #define GRPC_HAVE_IP_PKTINFO 1
@@ -685,7 +685,6 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
685
685
  uint32_t opt = grpc_core::kTimestampingSocketOptions;
686
686
  if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING,
687
687
  static_cast<void*>(&opt), sizeof(opt)) != 0) {
688
- grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
689
688
  if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
690
689
  gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket.");
691
690
  }
@@ -980,8 +979,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
980
979
  // unref all and forget about all slices that have been written to this
981
980
  // point
982
981
  for (size_t idx = 0; idx < unwind_slice_idx; ++idx) {
983
- grpc_slice_unref_internal(
984
- grpc_slice_buffer_take_first(tcp->outgoing_buffer));
982
+ grpc_slice_buffer_remove_first(tcp->outgoing_buffer);
985
983
  }
986
984
  return false;
987
985
  } else if (errno == EPIPE) {
@@ -41,6 +41,11 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s,
41
41
  return grpc_tcp_server_impl->add_port(s, addr, out_port);
42
42
  }
43
43
 
44
+ grpc_core::TcpServerFdHandler* grpc_tcp_server_create_fd_handler(
45
+ grpc_tcp_server* s) {
46
+ return grpc_tcp_server_impl->create_fd_handler(s);
47
+ }
48
+
44
49
  unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s,
45
50
  unsigned port_index) {
46
51
  return grpc_tcp_server_impl->port_fd_count(s, port_index);
@@ -22,7 +22,9 @@
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
24
  #include <grpc/grpc.h>
25
+ #include <grpc/impl/codegen/grpc_types.h>
25
26
 
27
+ #include "src/core/lib/gprpp/abstract.h"
26
28
  #include "src/core/lib/iomgr/closure.h"
27
29
  #include "src/core/lib/iomgr/endpoint.h"
28
30
  #include "src/core/lib/iomgr/resolve_address.h"
@@ -37,6 +39,10 @@ typedef struct grpc_tcp_server_acceptor {
37
39
  /* Indices that may be passed to grpc_tcp_server_port_fd(). */
38
40
  unsigned port_index;
39
41
  unsigned fd_index;
42
+ /* Data when the connection is passed to tcp_server from external. */
43
+ bool external_connection;
44
+ int listener_fd;
45
+ grpc_byte_buffer* pending_data;
40
46
  } grpc_tcp_server_acceptor;
41
47
 
42
48
  /* Called for newly connected TCP connections.
@@ -44,6 +50,18 @@ typedef struct grpc_tcp_server_acceptor {
44
50
  typedef void (*grpc_tcp_server_cb)(void* arg, grpc_endpoint* ep,
45
51
  grpc_pollset* accepting_pollset,
46
52
  grpc_tcp_server_acceptor* acceptor);
53
+ namespace grpc_core {
54
+ // An interface for a handler to take a externally connected fd as a internal
55
+ // connection.
56
+ class TcpServerFdHandler {
57
+ public:
58
+ virtual ~TcpServerFdHandler() = default;
59
+ virtual void Handle(int listener_fd, int fd,
60
+ grpc_byte_buffer* pending_read) GRPC_ABSTRACT;
61
+
62
+ GRPC_ABSTRACT_BASE_CLASS;
63
+ };
64
+ } // namespace grpc_core
47
65
 
48
66
  typedef struct grpc_tcp_server_vtable {
49
67
  grpc_error* (*create)(grpc_closure* shutdown_complete,
@@ -54,6 +72,7 @@ typedef struct grpc_tcp_server_vtable {
54
72
  void* cb_arg);
55
73
  grpc_error* (*add_port)(grpc_tcp_server* s, const grpc_resolved_address* addr,
56
74
  int* out_port);
75
+ grpc_core::TcpServerFdHandler* (*create_fd_handler)(grpc_tcp_server* s);
57
76
  unsigned (*port_fd_count)(grpc_tcp_server* s, unsigned port_index);
58
77
  int (*port_fd)(grpc_tcp_server* s, unsigned port_index, unsigned fd_index);
59
78
  grpc_tcp_server* (*ref)(grpc_tcp_server* s);
@@ -88,6 +107,11 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s,
88
107
  const grpc_resolved_address* addr,
89
108
  int* out_port);
90
109
 
110
+ /* Create and return a TcpServerFdHandler so that it can be used by upper layer
111
+ to hand over an externally connected fd to the grpc server. */
112
+ grpc_core::TcpServerFdHandler* grpc_tcp_server_create_fd_handler(
113
+ grpc_tcp_server* s);
114
+
91
115
  /* Number of fds at the given port_index, or 0 if port_index is out of
92
116
  bounds. */
93
117
  unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, unsigned port_index);
@@ -233,6 +233,7 @@ static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) {
233
233
  acceptor->from_server = sp->server;
234
234
  acceptor->port_index = sp->port_index;
235
235
  acceptor->fd_index = 0;
236
+ acceptor->external_connection = false;
236
237
  sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, nullptr, acceptor);
237
238
  gpr_free(peer_name_string);
238
239
  }
@@ -456,16 +457,17 @@ static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {
456
457
  }
457
458
  }
458
459
 
460
+ static grpc_core::TcpServerFdHandler* tcp_server_create_fd_handler(
461
+ grpc_tcp_server* s) {
462
+ return nullptr;
463
+ }
464
+
459
465
  grpc_tcp_server_vtable custom_tcp_server_vtable = {
460
- tcp_server_create,
461
- tcp_server_start,
462
- tcp_server_add_port,
463
- tcp_server_port_fd_count,
464
- tcp_server_port_fd,
465
- tcp_server_ref,
466
- tcp_server_shutdown_starting_add,
467
- tcp_server_unref,
468
- tcp_server_shutdown_listeners};
466
+ tcp_server_create, tcp_server_start,
467
+ tcp_server_add_port, tcp_server_create_fd_handler,
468
+ tcp_server_port_fd_count, tcp_server_port_fd,
469
+ tcp_server_ref, tcp_server_shutdown_starting_add,
470
+ tcp_server_unref, tcp_server_shutdown_listeners};
469
471
 
470
472
  #ifdef GRPC_UV_TEST
471
473
  grpc_tcp_server_vtable* default_tcp_server_vtable = &custom_tcp_server_vtable;
@@ -27,8 +27,6 @@
27
27
 
28
28
  #ifdef GRPC_POSIX_SOCKET_TCP_SERVER
29
29
 
30
- #include "src/core/lib/iomgr/tcp_server.h"
31
-
32
30
  #include <errno.h>
33
31
  #include <fcntl.h>
34
32
  #include <netinet/in.h>
@@ -47,11 +45,14 @@
47
45
 
48
46
  #include "src/core/lib/channel/channel_args.h"
49
47
  #include "src/core/lib/gpr/string.h"
48
+ #include "src/core/lib/gprpp/memory.h"
49
+ #include "src/core/lib/iomgr/exec_ctx.h"
50
50
  #include "src/core/lib/iomgr/resolve_address.h"
51
51
  #include "src/core/lib/iomgr/sockaddr.h"
52
52
  #include "src/core/lib/iomgr/sockaddr_utils.h"
53
53
  #include "src/core/lib/iomgr/socket_utils_posix.h"
54
54
  #include "src/core/lib/iomgr/tcp_posix.h"
55
+ #include "src/core/lib/iomgr/tcp_server.h"
55
56
  #include "src/core/lib/iomgr/tcp_server_utils_posix.h"
56
57
  #include "src/core/lib/iomgr/unix_sockets_posix.h"
57
58
 
@@ -96,6 +97,7 @@ static grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
96
97
  s->tail = nullptr;
97
98
  s->nports = 0;
98
99
  s->channel_args = grpc_channel_args_copy(args);
100
+ s->fd_handler = nullptr;
99
101
  gpr_atm_no_barrier_store(&s->next_pollset_to_assign, 0);
100
102
  *server = s;
101
103
  return GRPC_ERROR_NONE;
@@ -117,6 +119,7 @@ static void finish_shutdown(grpc_tcp_server* s) {
117
119
  gpr_free(sp);
118
120
  }
119
121
  grpc_channel_args_destroy(s->channel_args);
122
+ grpc_core::Delete(s->fd_handler);
120
123
 
121
124
  gpr_free(s);
122
125
  }
@@ -254,6 +257,7 @@ static void on_read(void* arg, grpc_error* err) {
254
257
  acceptor->from_server = sp->server;
255
258
  acceptor->port_index = sp->port_index;
256
259
  acceptor->fd_index = sp->fd_index;
260
+ acceptor->external_connection = false;
257
261
 
258
262
  sp->server->on_accept_cb(
259
263
  sp->server->on_accept_cb_arg,
@@ -562,14 +566,71 @@ static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {
562
566
  gpr_mu_unlock(&s->mu);
563
567
  }
564
568
 
569
+ namespace {
570
+ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler {
571
+ public:
572
+ explicit ExternalConnectionHandler(grpc_tcp_server* s) : s_(s) {}
573
+
574
+ // TODO(yangg) resolve duplicate code with on_read
575
+ void Handle(int listener_fd, int fd, grpc_byte_buffer* buf) override {
576
+ grpc_pollset* read_notifier_pollset;
577
+ grpc_resolved_address addr;
578
+ char* addr_str;
579
+ char* name;
580
+ memset(&addr, 0, sizeof(addr));
581
+ addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
582
+ grpc_core::ExecCtx exec_ctx;
583
+
584
+ if (getpeername(fd, reinterpret_cast<struct sockaddr*>(addr.addr),
585
+ &(addr.len)) < 0) {
586
+ gpr_log(GPR_ERROR, "Failed getpeername: %s", strerror(errno));
587
+ close(fd);
588
+ return;
589
+ }
590
+ grpc_set_socket_no_sigpipe_if_possible(fd);
591
+ addr_str = grpc_sockaddr_to_uri(&addr);
592
+ gpr_asprintf(&name, "tcp-server-connection:%s", addr_str);
593
+ if (grpc_tcp_trace.enabled()) {
594
+ gpr_log(GPR_INFO, "SERVER_CONNECT: incoming external connection: %s",
595
+ addr_str);
596
+ }
597
+ grpc_fd* fdobj = grpc_fd_create(fd, name, true);
598
+ read_notifier_pollset =
599
+ s_->pollsets[static_cast<size_t>(gpr_atm_no_barrier_fetch_add(
600
+ &s_->next_pollset_to_assign, 1)) %
601
+ s_->pollset_count];
602
+ grpc_pollset_add_fd(read_notifier_pollset, fdobj);
603
+ grpc_tcp_server_acceptor* acceptor =
604
+ static_cast<grpc_tcp_server_acceptor*>(gpr_malloc(sizeof(*acceptor)));
605
+ acceptor->from_server = s_;
606
+ acceptor->port_index = -1;
607
+ acceptor->fd_index = -1;
608
+ acceptor->external_connection = true;
609
+ acceptor->listener_fd = listener_fd;
610
+ acceptor->pending_data = buf;
611
+ s_->on_accept_cb(s_->on_accept_cb_arg,
612
+ grpc_tcp_create(fdobj, s_->channel_args, addr_str),
613
+ read_notifier_pollset, acceptor);
614
+ gpr_free(name);
615
+ gpr_free(addr_str);
616
+ }
617
+
618
+ private:
619
+ grpc_tcp_server* s_;
620
+ };
621
+ } // namespace
622
+
623
+ static grpc_core::TcpServerFdHandler* tcp_server_create_fd_handler(
624
+ grpc_tcp_server* s) {
625
+ s->fd_handler = grpc_core::New<ExternalConnectionHandler>(s);
626
+ return s->fd_handler;
627
+ }
628
+
565
629
  grpc_tcp_server_vtable grpc_posix_tcp_server_vtable = {
566
- tcp_server_create,
567
- tcp_server_start,
568
- tcp_server_add_port,
569
- tcp_server_port_fd_count,
570
- tcp_server_port_fd,
571
- tcp_server_ref,
572
- tcp_server_shutdown_starting_add,
573
- tcp_server_unref,
574
- tcp_server_shutdown_listeners};
630
+ tcp_server_create, tcp_server_start,
631
+ tcp_server_add_port, tcp_server_create_fd_handler,
632
+ tcp_server_port_fd_count, tcp_server_port_fd,
633
+ tcp_server_ref, tcp_server_shutdown_starting_add,
634
+ tcp_server_unref, tcp_server_shutdown_listeners};
635
+
575
636
  #endif /* GRPC_POSIX_SOCKET_TCP_SERVER */