grpc 1.22.0 → 1.23.0

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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +487 -649
  3. data/include/grpc/grpc_security.h +25 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +11 -2
  5. data/include/grpc/impl/codegen/port_platform.h +12 -0
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
  10. data/src/core/ext/filters/client_channel/connector.h +10 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
  12. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
  13. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
  14. data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
  19. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
  20. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
  22. data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
  23. data/src/core/ext/filters/client_channel/resolver.h +3 -11
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
  31. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
  32. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
  33. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
  34. data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
  35. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
  36. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
  37. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
  38. data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
  39. data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
  40. data/src/core/ext/filters/client_channel/subchannel.h +65 -45
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
  42. data/src/core/ext/filters/client_idle/client_idle_filter.cc +262 -0
  43. data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
  44. data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
  45. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
  46. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +63 -38
  50. data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
  53. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -0
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +7 -0
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +1 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -81
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
  60. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
  61. data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
  62. data/src/core/ext/transport/chttp2/transport/internal.h +13 -2
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -22
  64. data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
  65. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -0
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  67. data/src/core/lib/channel/channelz.cc +80 -33
  68. data/src/core/lib/channel/channelz.h +28 -13
  69. data/src/core/lib/compression/compression.cc +1 -2
  70. data/src/core/lib/compression/compression_args.cc +13 -6
  71. data/src/core/lib/compression/compression_args.h +3 -2
  72. data/src/core/lib/compression/compression_internal.cc +1 -1
  73. data/src/core/lib/gpr/env_linux.cc +10 -21
  74. data/src/core/lib/gpr/env_posix.cc +0 -5
  75. data/src/core/lib/gpr/string.cc +7 -2
  76. data/src/core/lib/gpr/string.h +1 -0
  77. data/src/core/lib/gpr/sync_posix.cc +0 -129
  78. data/src/core/lib/gprpp/debug_location.h +3 -2
  79. data/src/core/lib/gprpp/fork.cc +14 -21
  80. data/src/core/lib/gprpp/fork.h +15 -4
  81. data/src/core/lib/gprpp/host_port.cc +118 -0
  82. data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
  83. data/src/core/lib/gprpp/map.h +25 -0
  84. data/src/core/lib/gprpp/memory.h +26 -9
  85. data/src/core/lib/gprpp/ref_counted.h +63 -21
  86. data/src/core/lib/gprpp/string_view.h +143 -0
  87. data/src/core/lib/gprpp/thd.h +10 -1
  88. data/src/core/lib/gprpp/thd_posix.cc +25 -0
  89. data/src/core/lib/gprpp/thd_windows.cc +9 -1
  90. data/src/core/lib/http/httpcli_security_connector.cc +3 -1
  91. data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
  92. data/src/core/lib/iomgr/cfstream_handle.h +8 -2
  93. data/src/core/lib/iomgr/combiner.cc +4 -4
  94. data/src/core/lib/iomgr/error.cc +18 -8
  95. data/src/core/lib/iomgr/error.h +2 -0
  96. data/src/core/lib/iomgr/ev_posix.cc +4 -2
  97. data/src/core/lib/iomgr/executor.cc +4 -1
  98. data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
  99. data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
  100. data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
  101. data/src/core/lib/iomgr/executor/threadpool.h +153 -0
  102. data/src/core/lib/iomgr/fork_posix.cc +4 -2
  103. data/src/core/lib/iomgr/iocp_windows.cc +2 -2
  104. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
  105. data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
  106. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  107. data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
  108. data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
  109. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  110. data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
  111. data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
  112. data/src/core/lib/iomgr/socket_windows.h +1 -1
  113. data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
  114. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
  115. data/src/core/lib/iomgr/tcp_custom.cc +4 -0
  116. data/src/core/lib/iomgr/tcp_posix.cc +8 -2
  117. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
  118. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  119. data/src/core/lib/iomgr/tcp_windows.cc +7 -7
  120. data/src/core/lib/iomgr/timer_custom.cc +1 -0
  121. data/src/core/lib/iomgr/timer_manager.cc +0 -29
  122. data/src/core/lib/security/credentials/credentials.cc +84 -0
  123. data/src/core/lib/security/credentials/credentials.h +58 -2
  124. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
  125. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
  127. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
  128. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
  129. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
  130. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
  131. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  132. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  133. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
  134. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
  135. data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
  136. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
  137. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
  138. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  139. data/src/core/lib/security/util/json_util.cc +19 -5
  140. data/src/core/lib/security/util/json_util.h +3 -1
  141. data/src/core/lib/slice/slice.cc +69 -50
  142. data/src/core/lib/slice/slice_buffer.cc +6 -5
  143. data/src/core/lib/slice/slice_hash_table.h +3 -7
  144. data/src/core/lib/slice/slice_intern.cc +130 -39
  145. data/src/core/lib/slice/slice_internal.h +8 -0
  146. data/src/core/lib/slice/slice_utils.h +120 -0
  147. data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
  148. data/src/core/lib/surface/call.cc +8 -3
  149. data/src/core/lib/surface/channel.cc +31 -8
  150. data/src/core/lib/surface/completion_queue.cc +17 -7
  151. data/src/core/lib/surface/init_secure.cc +4 -1
  152. data/src/core/lib/surface/lame_client.cc +2 -2
  153. data/src/core/lib/surface/server.cc +34 -35
  154. data/src/core/lib/surface/server.h +8 -17
  155. data/src/core/lib/surface/version.cc +1 -1
  156. data/src/core/lib/transport/byte_stream.cc +3 -5
  157. data/src/core/lib/transport/byte_stream.h +1 -2
  158. data/src/core/lib/transport/error_utils.cc +10 -1
  159. data/src/core/lib/transport/metadata.cc +202 -35
  160. data/src/core/lib/transport/metadata.h +81 -6
  161. data/src/core/lib/transport/static_metadata.cc +1257 -465
  162. data/src/core/lib/transport/static_metadata.h +190 -347
  163. data/src/core/lib/transport/timeout_encoding.cc +7 -0
  164. data/src/core/lib/transport/timeout_encoding.h +3 -2
  165. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  166. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
  167. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
  168. data/src/core/tsi/ssl_transport_security.cc +35 -43
  169. data/src/core/tsi/ssl_transport_security.h +2 -1
  170. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  172. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  173. data/src/ruby/lib/grpc/grpc.rb +1 -1
  174. data/src/ruby/lib/grpc/version.rb +1 -1
  175. metadata +39 -33
  176. data/src/core/lib/gpr/host_port.cc +0 -98
@@ -0,0 +1,143 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+ #ifndef GRPC_CORE_LIB_GPRPP_STRING_VIEW_H
19
+ #define GRPC_CORE_LIB_GPRPP_STRING_VIEW_H
20
+
21
+ #include <grpc/support/port_platform.h>
22
+
23
+ #include <grpc/impl/codegen/slice.h>
24
+ #include <grpc/support/alloc.h>
25
+ #include <grpc/support/log.h>
26
+
27
+ #include <algorithm>
28
+ #include <cstdint>
29
+ #include <cstring>
30
+ #include <limits>
31
+
32
+ #include "src/core/lib/gpr/string.h"
33
+ #include "src/core/lib/gpr/useful.h"
34
+ #include "src/core/lib/gprpp/memory.h"
35
+
36
+ namespace grpc_core {
37
+
38
+ // Provides a light-weight view over a char array or a slice, similar but not
39
+ // identical to absl::string_view.
40
+ //
41
+ // Any method that has the same name as absl::string_view MUST HAVE identical
42
+ // semantics to what absl::string_view provides.
43
+ //
44
+ // Methods that are not part of absl::string_view API, must be clearly
45
+ // annotated.
46
+ //
47
+ // StringView does not own the buffers that back the view. Callers must ensure
48
+ // the buffer stays around while the StringView is accessible.
49
+ //
50
+ // Pass StringView by value in functions, since it is exactly two pointers in
51
+ // size.
52
+ //
53
+ // The interface used here is not identical to absl::string_view. Notably, we
54
+ // need to support slices while we cannot support std::string, and gpr string
55
+ // style functions such as strdup() and cmp(). Once we switch to
56
+ // absl::string_view this class will inherit from absl::string_view and add the
57
+ // gRPC-specific APIs.
58
+ class StringView final {
59
+ public:
60
+ static constexpr size_t npos = std::numeric_limits<size_t>::max();
61
+
62
+ constexpr StringView(const char* ptr, size_t size) : ptr_(ptr), size_(size) {}
63
+ constexpr StringView(const char* ptr)
64
+ : StringView(ptr, ptr == nullptr ? 0 : strlen(ptr)) {}
65
+ // Not part of absl::string_view API.
66
+ StringView(const grpc_slice& slice)
67
+ : StringView(reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(slice)),
68
+ GRPC_SLICE_LENGTH(slice)) {}
69
+ constexpr StringView() : StringView(nullptr, 0) {}
70
+
71
+ constexpr const char* data() const { return ptr_; }
72
+ constexpr size_t size() const { return size_; }
73
+ constexpr bool empty() const { return size_ == 0; }
74
+
75
+ StringView substr(size_t start, size_t size = npos) {
76
+ GPR_DEBUG_ASSERT(start + size <= size_);
77
+ return StringView(ptr_ + start, std::min(size, size_ - start));
78
+ }
79
+
80
+ constexpr const char& operator[](size_t i) const { return ptr_[i]; }
81
+
82
+ const char& front() const { return ptr_[0]; }
83
+ const char& back() const { return ptr_[size_ - 1]; }
84
+
85
+ void remove_prefix(size_t n) {
86
+ GPR_DEBUG_ASSERT(n <= size_);
87
+ ptr_ += n;
88
+ size_ -= n;
89
+ }
90
+
91
+ void remove_suffix(size_t n) {
92
+ GPR_DEBUG_ASSERT(n <= size_);
93
+ size_ -= n;
94
+ }
95
+
96
+ size_t find(char c, size_t pos = 0) const {
97
+ if (empty() || pos >= size_) return npos;
98
+ const char* result =
99
+ static_cast<const char*>(memchr(ptr_ + pos, c, size_ - pos));
100
+ return result != nullptr ? result - ptr_ : npos;
101
+ }
102
+
103
+ void clear() {
104
+ ptr_ = nullptr;
105
+ size_ = 0;
106
+ }
107
+
108
+ // Creates a dup of the string viewed by this class.
109
+ // Return value is null-terminated and never nullptr.
110
+ //
111
+ // Not part of absl::string_view API.
112
+ grpc_core::UniquePtr<char> dup() const {
113
+ char* str = static_cast<char*>(gpr_malloc(size_ + 1));
114
+ if (size_ > 0) memcpy(str, ptr_, size_);
115
+ str[size_] = '\0';
116
+ return grpc_core::UniquePtr<char>(str);
117
+ }
118
+
119
+ // Not part of absl::string_view API.
120
+ int cmp(StringView other) const {
121
+ const size_t len = GPR_MIN(size(), other.size());
122
+ const int ret = strncmp(data(), other.data(), len);
123
+ if (ret != 0) return ret;
124
+ if (size() == other.size()) return 0;
125
+ if (size() < other.size()) return -1;
126
+ return 1;
127
+ }
128
+
129
+ private:
130
+ const char* ptr_;
131
+ size_t size_;
132
+ };
133
+
134
+ inline bool operator==(StringView lhs, StringView rhs) {
135
+ return lhs.size() == rhs.size() &&
136
+ strncmp(lhs.data(), rhs.data(), lhs.size()) == 0;
137
+ }
138
+
139
+ inline bool operator!=(StringView lhs, StringView rhs) { return !(lhs == rhs); }
140
+
141
+ } // namespace grpc_core
142
+
143
+ #endif /* GRPC_CORE_LIB_GPRPP_STRING_VIEW_H */
@@ -49,7 +49,7 @@ class Thread {
49
49
  public:
50
50
  class Options {
51
51
  public:
52
- Options() : joinable_(true), tracked_(true) {}
52
+ Options() : joinable_(true), tracked_(true), stack_size_(0) {}
53
53
  /// Set whether the thread is joinable or detached.
54
54
  Options& set_joinable(bool joinable) {
55
55
  joinable_ = joinable;
@@ -64,9 +64,18 @@ class Thread {
64
64
  }
65
65
  bool tracked() const { return tracked_; }
66
66
 
67
+ /// Sets thread stack size (in bytes). Sets to 0 will use the default stack
68
+ /// size which is 64KB for Windows threads and 2MB for Posix(x86) threads.
69
+ Options& set_stack_size(size_t bytes) {
70
+ stack_size_ = bytes;
71
+ return *this;
72
+ }
73
+ size_t stack_size() const { return stack_size_; }
74
+
67
75
  private:
68
76
  bool joinable_;
69
77
  bool tracked_;
78
+ size_t stack_size_;
70
79
  };
71
80
  /// Default constructor only to allow use in structs that lack constructors
72
81
  /// Does not produce a validly-constructed thread; must later
@@ -31,6 +31,7 @@
31
31
  #include <pthread.h>
32
32
  #include <stdlib.h>
33
33
  #include <string.h>
34
+ #include <unistd.h>
34
35
 
35
36
  #include "src/core/lib/gpr/useful.h"
36
37
  #include "src/core/lib/gprpp/fork.h"
@@ -48,6 +49,25 @@ struct thd_arg {
48
49
  bool tracked;
49
50
  };
50
51
 
52
+ size_t RoundUpToPageSize(size_t size) {
53
+ // TODO(yunjiaw): Change this variable (page_size) to a function-level static
54
+ // when possible
55
+ size_t page_size = static_cast<size_t>(sysconf(_SC_PAGESIZE));
56
+ return (size + page_size - 1) & ~(page_size - 1);
57
+ }
58
+
59
+ // Returns the minimum valid stack size that can be passed to
60
+ // pthread_attr_setstacksize.
61
+ size_t MinValidStackSize(size_t request_size) {
62
+ if (request_size < _SC_THREAD_STACK_MIN) {
63
+ request_size = _SC_THREAD_STACK_MIN;
64
+ }
65
+
66
+ // On some systems, pthread_attr_setstacksize() can fail if stacksize is
67
+ // not a multiple of the system page size.
68
+ return RoundUpToPageSize(request_size);
69
+ }
70
+
51
71
  class ThreadInternalsPosix : public internal::ThreadInternalsInterface {
52
72
  public:
53
73
  ThreadInternalsPosix(const char* thd_name, void (*thd_body)(void* arg),
@@ -79,6 +99,11 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface {
79
99
  0);
80
100
  }
81
101
 
102
+ if (options.stack_size() != 0) {
103
+ size_t stack_size = MinValidStackSize(options.stack_size());
104
+ GPR_ASSERT(pthread_attr_setstacksize(&attr, stack_size) == 0);
105
+ }
106
+
82
107
  *success =
83
108
  (pthread_create(&pthread_id_, &attr,
84
109
  [](void* v) -> void* {
@@ -75,7 +75,15 @@ class ThreadInternalsWindows
75
75
  return;
76
76
  }
77
77
  }
78
- handle = CreateThread(nullptr, 64 * 1024, thread_body, info_, 0, nullptr);
78
+
79
+ if (options.stack_size() != 0) {
80
+ // Windows will round up the given stack_size value to nearest page.
81
+ handle = CreateThread(nullptr, options.stack_size(), thread_body, info_,
82
+ 0, nullptr);
83
+ } else {
84
+ handle = CreateThread(nullptr, 64 * 1024, thread_body, info_, 0, nullptr);
85
+ }
86
+
79
87
  if (handle == nullptr) {
80
88
  destroy_thread();
81
89
  *success = false;
@@ -30,6 +30,7 @@
30
30
  #include "src/core/lib/channel/handshaker_registry.h"
31
31
  #include "src/core/lib/gpr/string.h"
32
32
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
33
+ #include "src/core/lib/gprpp/string_view.h"
33
34
  #include "src/core/lib/iomgr/pollset.h"
34
35
  #include "src/core/lib/security/credentials/credentials.h"
35
36
  #include "src/core/lib/security/security_connector/ssl_utils.h"
@@ -108,7 +109,8 @@ class grpc_httpcli_ssl_channel_security_connector final
108
109
  return strcmp(secure_peer_name_, other->secure_peer_name_);
109
110
  }
110
111
 
111
- bool check_call_host(const char* host, grpc_auth_context* auth_context,
112
+ bool check_call_host(grpc_core::StringView host,
113
+ grpc_auth_context* auth_context,
112
114
  grpc_closure* on_call_host_checked,
113
115
  grpc_error** error) override {
114
116
  *error = GRPC_ERROR_NONE;
@@ -25,6 +25,7 @@
25
25
  #import <CoreFoundation/CoreFoundation.h>
26
26
  #import "src/core/lib/iomgr/cfstream_handle.h"
27
27
 
28
+ #include <grpc/grpc.h>
28
29
  #include <grpc/support/atm.h>
29
30
  #include <grpc/support/sync.h>
30
31
 
@@ -35,6 +36,10 @@
35
36
 
36
37
  extern grpc_core::TraceFlag grpc_tcp_trace;
37
38
 
39
+ GrpcLibraryInitHolder::GrpcLibraryInitHolder() { grpc_init(); }
40
+
41
+ GrpcLibraryInitHolder::~GrpcLibraryInitHolder() { grpc_shutdown(); }
42
+
38
43
  void* CFStreamHandle::Retain(void* info) {
39
44
  CFStreamHandle* handle = static_cast<CFStreamHandle*>(info);
40
45
  CFSTREAM_HANDLE_REF(handle, "retain");
@@ -184,7 +189,7 @@ void CFStreamHandle::Ref(const char* file, int line, const char* reason) {
184
189
  void CFStreamHandle::Unref(const char* file, int line, const char* reason) {
185
190
  if (grpc_tcp_trace.enabled()) {
186
191
  gpr_atm val = gpr_atm_no_barrier_load(&refcount_.count);
187
- gpr_log(GPR_ERROR,
192
+ gpr_log(GPR_DEBUG,
188
193
  "CFStream Handle unref %p : %s %" PRIdPTR " -> %" PRIdPTR, this,
189
194
  reason, val, val - 1);
190
195
  }
@@ -33,11 +33,17 @@
33
33
  #include "src/core/lib/iomgr/closure.h"
34
34
  #include "src/core/lib/iomgr/lockfree_event.h"
35
35
 
36
- class CFStreamHandle final {
36
+ class GrpcLibraryInitHolder {
37
+ public:
38
+ GrpcLibraryInitHolder();
39
+ virtual ~GrpcLibraryInitHolder();
40
+ };
41
+
42
+ class CFStreamHandle : public GrpcLibraryInitHolder {
37
43
  public:
38
44
  static CFStreamHandle* CreateStreamHandle(CFReadStreamRef read_stream,
39
45
  CFWriteStreamRef write_stream);
40
- ~CFStreamHandle();
46
+ ~CFStreamHandle() override;
41
47
  CFStreamHandle(const CFStreamHandle& ref) = delete;
42
48
  CFStreamHandle(CFStreamHandle&& ref) = delete;
43
49
  CFStreamHandle& operator=(const CFStreamHandle& rhs) = delete;
@@ -233,11 +233,11 @@ bool grpc_combiner_continue_exec_ctx() {
233
233
  // offload only if all the following conditions are true:
234
234
  // 1. the combiner is contended and has more than one closure to execute
235
235
  // 2. the current execution context needs to finish as soon as possible
236
- // 3. the DEFAULT executor is threaded
237
- // 4. the current thread is not a worker for any background poller
236
+ // 3. the current thread is not a worker for any background poller
237
+ // 4. the DEFAULT executor is threaded
238
238
  if (contended && grpc_core::ExecCtx::Get()->IsReadyToFinish() &&
239
- grpc_core::Executor::IsThreadedDefault() &&
240
- !grpc_iomgr_is_any_background_poller_thread()) {
239
+ !grpc_iomgr_is_any_background_poller_thread() &&
240
+ grpc_core::Executor::IsThreadedDefault()) {
241
241
  GPR_TIMER_MARK("offload_from_finished_exec_ctx", 0);
242
242
  // this execution context wants to move on: schedule remaining work to be
243
243
  // picked up on the executor
@@ -73,6 +73,8 @@ static const char* error_int_name(grpc_error_ints key) {
73
73
  return "limit";
74
74
  case GRPC_ERROR_INT_OCCURRED_DURING_WRITE:
75
75
  return "occurred_during_write";
76
+ case GRPC_ERROR_INT_CHANNEL_CONNECTIVITY_STATE:
77
+ return "channel_connectivity_state";
76
78
  case GRPC_ERROR_INT_MAX:
77
79
  GPR_UNREACHABLE_CODE(return "unknown");
78
80
  }
@@ -447,13 +449,17 @@ grpc_error* grpc_error_set_int(grpc_error* src, grpc_error_ints which,
447
449
  typedef struct {
448
450
  grpc_status_code code;
449
451
  const char* msg;
452
+ size_t len;
450
453
  } special_error_status_map;
451
- static const special_error_status_map error_status_map[] = {
452
- {GRPC_STATUS_OK, ""}, // GRPC_ERROR_NONE
453
- {GRPC_STATUS_INVALID_ARGUMENT, ""}, // GRPC_ERROR_RESERVED_1
454
- {GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory"}, // GRPC_ERROR_OOM
455
- {GRPC_STATUS_INVALID_ARGUMENT, ""}, // GRPC_ERROR_RESERVED_2
456
- {GRPC_STATUS_CANCELLED, "Cancelled"}, // GRPC_ERROR_CANCELLED
454
+
455
+ const special_error_status_map error_status_map[] = {
456
+ {GRPC_STATUS_OK, "", 0}, // GRPC_ERROR_NONE
457
+ {GRPC_STATUS_INVALID_ARGUMENT, "", 0}, // GRPC_ERROR_RESERVED_1
458
+ {GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory",
459
+ strlen("Out of memory")}, // GRPC_ERROR_OOM
460
+ {GRPC_STATUS_INVALID_ARGUMENT, "", 0}, // GRPC_ERROR_RESERVED_2
461
+ {GRPC_STATUS_CANCELLED, "Cancelled",
462
+ strlen("Cancelled")}, // GRPC_ERROR_CANCELLED
457
463
  };
458
464
 
459
465
  bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) {
@@ -483,8 +489,12 @@ bool grpc_error_get_str(grpc_error* err, grpc_error_strs which,
483
489
  grpc_slice* str) {
484
490
  if (grpc_error_is_special(err)) {
485
491
  if (which != GRPC_ERROR_STR_GRPC_MESSAGE) return false;
486
- *str = grpc_slice_from_static_string(
487
- error_status_map[reinterpret_cast<size_t>(err)].msg);
492
+ const special_error_status_map& msg =
493
+ error_status_map[reinterpret_cast<size_t>(err)];
494
+ str->refcount = &grpc_core::kNoopRefcount;
495
+ str->data.refcounted.bytes =
496
+ reinterpret_cast<uint8_t*>(const_cast<char*>(msg.msg));
497
+ str->data.refcounted.length = msg.len;
488
498
  return true;
489
499
  }
490
500
  uint8_t slot = err->strs[which];
@@ -73,6 +73,8 @@ typedef enum {
73
73
  GRPC_ERROR_INT_LIMIT,
74
74
  /// chttp2: did the error occur while a write was in progress
75
75
  GRPC_ERROR_INT_OCCURRED_DURING_WRITE,
76
+ /// channel connectivity state associated with the error
77
+ GRPC_ERROR_INT_CHANNEL_CONNECTIVITY_STATE,
76
78
 
77
79
  /// Must always be last
78
80
  GRPC_ERROR_INT_MAX,
@@ -206,7 +206,8 @@ void grpc_register_event_engine_factory(const char* name,
206
206
  GPR_ASSERT(false);
207
207
  }
208
208
 
209
- /* Call this only after calling grpc_event_engine_init() */
209
+ /*If grpc_event_engine_init() has been called, returns the poll_strategy_name.
210
+ * Otherwise, returns nullptr. */
210
211
  const char* grpc_get_poll_strategy_name() { return g_poll_strategy_name; }
211
212
 
212
213
  void grpc_event_engine_init(void) {
@@ -246,7 +247,8 @@ bool grpc_event_engine_can_track_errors(void) {
246
247
  }
247
248
 
248
249
  bool grpc_event_engine_run_in_background(void) {
249
- return g_event_engine->run_in_background;
250
+ // g_event_engine is nullptr when using a custom iomgr.
251
+ return g_event_engine != nullptr && g_event_engine->run_in_background;
250
252
  }
251
253
 
252
254
  grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) {
@@ -120,7 +120,10 @@ size_t Executor::RunClosures(const char* executor_name,
120
120
  // thread itself, but this is the point where we could start seeing
121
121
  // application-level callbacks. No need to create a new ExecCtx, though,
122
122
  // since there already is one and it is flushed (but not destructed) in this
123
- // function itself.
123
+ // function itself. The ApplicationCallbackExecCtx will have its callbacks
124
+ // invoked on its destruction, which will be after completing any closures in
125
+ // the executor's closure list (which were explicitly scheduled onto the
126
+ // executor).
124
127
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx(
125
128
  GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD);
126
129
 
@@ -0,0 +1,183 @@
1
+ /*
2
+ *
3
+ * Copyright 2019 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/lib/iomgr/executor/mpmcqueue.h"
22
+
23
+ namespace grpc_core {
24
+
25
+ DebugOnlyTraceFlag grpc_thread_pool_trace(false, "thread_pool");
26
+
27
+ inline void* InfLenFIFOQueue::PopFront() {
28
+ // Caller should already check queue is not empty and has already held the
29
+ // mutex. This function will assume that there is at least one element in the
30
+ // queue (i.e. queue_head_->content is valid).
31
+ void* result = queue_head_->content;
32
+ count_.Store(count_.Load(MemoryOrder::RELAXED) - 1, MemoryOrder::RELAXED);
33
+
34
+ // Updates Stats when trace flag turned on.
35
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_thread_pool_trace)) {
36
+ gpr_timespec wait_time =
37
+ gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), queue_head_->insert_time);
38
+ stats_.num_completed++;
39
+ stats_.total_queue_time = gpr_time_add(stats_.total_queue_time, wait_time);
40
+ stats_.max_queue_time = gpr_time_max(
41
+ gpr_convert_clock_type(stats_.max_queue_time, GPR_TIMESPAN), wait_time);
42
+
43
+ if (count_.Load(MemoryOrder::RELAXED) == 0) {
44
+ stats_.busy_queue_time =
45
+ gpr_time_add(stats_.busy_queue_time,
46
+ gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), busy_time));
47
+ }
48
+
49
+ gpr_log(GPR_INFO,
50
+ "[InfLenFIFOQueue PopFront] num_completed: %" PRIu64
51
+ " total_queue_time: %f max_queue_time: %f busy_queue_time: %f",
52
+ stats_.num_completed,
53
+ gpr_timespec_to_micros(stats_.total_queue_time),
54
+ gpr_timespec_to_micros(stats_.max_queue_time),
55
+ gpr_timespec_to_micros(stats_.busy_queue_time));
56
+ }
57
+
58
+ queue_head_ = queue_head_->next;
59
+ // Signal waiting thread
60
+ if (count_.Load(MemoryOrder::RELAXED) > 0) {
61
+ TopWaiter()->cv.Signal();
62
+ }
63
+
64
+ return result;
65
+ }
66
+
67
+ InfLenFIFOQueue::Node* InfLenFIFOQueue::AllocateNodes(int num) {
68
+ num_nodes_ = num_nodes_ + num;
69
+ Node* new_chunk = static_cast<Node*>(gpr_zalloc(sizeof(Node) * num));
70
+ new_chunk[0].next = &new_chunk[1];
71
+ new_chunk[num - 1].prev = &new_chunk[num - 2];
72
+ for (int i = 1; i < num - 1; ++i) {
73
+ new_chunk[i].prev = &new_chunk[i - 1];
74
+ new_chunk[i].next = &new_chunk[i + 1];
75
+ }
76
+ return new_chunk;
77
+ }
78
+
79
+ InfLenFIFOQueue::InfLenFIFOQueue() {
80
+ delete_list_size_ = kDeleteListInitSize;
81
+ delete_list_ =
82
+ static_cast<Node**>(gpr_zalloc(sizeof(Node*) * delete_list_size_));
83
+
84
+ Node* new_chunk = AllocateNodes(kQueueInitNumNodes);
85
+ delete_list_[delete_list_count_++] = new_chunk;
86
+ queue_head_ = queue_tail_ = new_chunk;
87
+ new_chunk[0].prev = &new_chunk[kQueueInitNumNodes - 1];
88
+ new_chunk[kQueueInitNumNodes - 1].next = &new_chunk[0];
89
+
90
+ waiters_.next = &waiters_;
91
+ waiters_.prev = &waiters_;
92
+ }
93
+
94
+ InfLenFIFOQueue::~InfLenFIFOQueue() {
95
+ GPR_ASSERT(count_.Load(MemoryOrder::RELAXED) == 0);
96
+ for (size_t i = 0; i < delete_list_count_; ++i) {
97
+ gpr_free(delete_list_[i]);
98
+ }
99
+ gpr_free(delete_list_);
100
+ }
101
+
102
+ void InfLenFIFOQueue::Put(void* elem) {
103
+ MutexLock l(&mu_);
104
+
105
+ int curr_count = count_.Load(MemoryOrder::RELAXED);
106
+
107
+ if (queue_tail_ == queue_head_ && curr_count != 0) {
108
+ // List is full. Expands list to double size by inserting new chunk of nodes
109
+ Node* new_chunk = AllocateNodes(curr_count);
110
+ delete_list_[delete_list_count_++] = new_chunk;
111
+ // Expands delete list on full.
112
+ if (delete_list_count_ == delete_list_size_) {
113
+ delete_list_size_ = delete_list_size_ * 2;
114
+ delete_list_ = static_cast<Node**>(
115
+ gpr_realloc(delete_list_, sizeof(Node*) * delete_list_size_));
116
+ }
117
+ new_chunk[0].prev = queue_tail_->prev;
118
+ new_chunk[curr_count - 1].next = queue_head_;
119
+ queue_tail_->prev->next = new_chunk;
120
+ queue_head_->prev = &new_chunk[curr_count - 1];
121
+ queue_tail_ = new_chunk;
122
+ }
123
+ queue_tail_->content = static_cast<void*>(elem);
124
+
125
+ // Updates Stats info
126
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_thread_pool_trace)) {
127
+ stats_.num_started++;
128
+ gpr_log(GPR_INFO, "[InfLenFIFOQueue Put] num_started: %" PRIu64,
129
+ stats_.num_started);
130
+ auto current_time = gpr_now(GPR_CLOCK_MONOTONIC);
131
+ if (curr_count == 0) {
132
+ busy_time = current_time;
133
+ }
134
+ queue_tail_->insert_time = current_time;
135
+ }
136
+
137
+ count_.Store(curr_count + 1, MemoryOrder::RELAXED);
138
+ queue_tail_ = queue_tail_->next;
139
+
140
+ TopWaiter()->cv.Signal();
141
+ }
142
+
143
+ void* InfLenFIFOQueue::Get(gpr_timespec* wait_time) {
144
+ MutexLock l(&mu_);
145
+
146
+ if (count_.Load(MemoryOrder::RELAXED) == 0) {
147
+ gpr_timespec start_time;
148
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_thread_pool_trace) &&
149
+ wait_time != nullptr) {
150
+ start_time = gpr_now(GPR_CLOCK_MONOTONIC);
151
+ }
152
+
153
+ Waiter self;
154
+ PushWaiter(&self);
155
+ do {
156
+ self.cv.Wait(&mu_);
157
+ } while (count_.Load(MemoryOrder::RELAXED) == 0);
158
+ RemoveWaiter(&self);
159
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_thread_pool_trace) &&
160
+ wait_time != nullptr) {
161
+ *wait_time = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), start_time);
162
+ }
163
+ }
164
+ GPR_DEBUG_ASSERT(count_.Load(MemoryOrder::RELAXED) > 0);
165
+ return PopFront();
166
+ }
167
+
168
+ void InfLenFIFOQueue::PushWaiter(Waiter* waiter) {
169
+ waiter->next = waiters_.next;
170
+ waiter->prev = &waiters_;
171
+ waiter->next->prev = waiter;
172
+ waiter->prev->next = waiter;
173
+ }
174
+
175
+ void InfLenFIFOQueue::RemoveWaiter(Waiter* waiter) {
176
+ GPR_DEBUG_ASSERT(waiter != &waiters_);
177
+ waiter->next->prev = waiter->prev;
178
+ waiter->prev->next = waiter->next;
179
+ }
180
+
181
+ InfLenFIFOQueue::Waiter* InfLenFIFOQueue::TopWaiter() { return waiters_.next; }
182
+
183
+ } // namespace grpc_core