|
|
@ -56,9 +56,9 @@ class AsyncConnect { |
|
|
|
public: |
|
|
|
public: |
|
|
|
AsyncConnect(EventEngine::OnConnectCallback on_connect, |
|
|
|
AsyncConnect(EventEngine::OnConnectCallback on_connect, |
|
|
|
std::shared_ptr<EventEngine> engine, ThreadPool* executor, |
|
|
|
std::shared_ptr<EventEngine> engine, ThreadPool* executor, |
|
|
|
grpc_event_engine::posix_engine::EventHandle* fd, |
|
|
|
grpc_event_engine::experimental::EventHandle* fd, |
|
|
|
MemoryAllocator&& allocator, |
|
|
|
MemoryAllocator&& allocator, |
|
|
|
const grpc_event_engine::posix_engine::PosixTcpOptions& options, |
|
|
|
const grpc_event_engine::experimental::PosixTcpOptions& options, |
|
|
|
std::string resolved_addr_str, int64_t connection_handle) |
|
|
|
std::string resolved_addr_str, int64_t connection_handle) |
|
|
|
: on_connect_(std::move(on_connect)), |
|
|
|
: on_connect_(std::move(on_connect)), |
|
|
|
engine_(engine), |
|
|
|
engine_(engine), |
|
|
@ -80,15 +80,15 @@ class AsyncConnect { |
|
|
|
void OnWritable(absl::Status status) ABSL_NO_THREAD_SAFETY_ANALYSIS; |
|
|
|
void OnWritable(absl::Status status) ABSL_NO_THREAD_SAFETY_ANALYSIS; |
|
|
|
|
|
|
|
|
|
|
|
grpc_core::Mutex mu_; |
|
|
|
grpc_core::Mutex mu_; |
|
|
|
grpc_event_engine::posix_engine::PosixEngineClosure* on_writable_ = nullptr; |
|
|
|
grpc_event_engine::experimental::PosixEngineClosure* on_writable_ = nullptr; |
|
|
|
EventEngine::OnConnectCallback on_connect_; |
|
|
|
EventEngine::OnConnectCallback on_connect_; |
|
|
|
std::shared_ptr<EventEngine> engine_; |
|
|
|
std::shared_ptr<EventEngine> engine_; |
|
|
|
ThreadPool* executor_; |
|
|
|
ThreadPool* executor_; |
|
|
|
EventEngine::TaskHandle alarm_handle_; |
|
|
|
EventEngine::TaskHandle alarm_handle_; |
|
|
|
int refs_{2}; |
|
|
|
int refs_{2}; |
|
|
|
grpc_event_engine::posix_engine::EventHandle* fd_; |
|
|
|
grpc_event_engine::experimental::EventHandle* fd_; |
|
|
|
MemoryAllocator allocator_; |
|
|
|
MemoryAllocator allocator_; |
|
|
|
grpc_event_engine::posix_engine::PosixTcpOptions options_; |
|
|
|
grpc_event_engine::experimental::PosixTcpOptions options_; |
|
|
|
std::string resolved_addr_str_; |
|
|
|
std::string resolved_addr_str_; |
|
|
|
int64_t connection_handle_; |
|
|
|
int64_t connection_handle_; |
|
|
|
bool connect_cancelled_; |
|
|
|
bool connect_cancelled_; |
|
|
@ -97,12 +97,12 @@ class AsyncConnect { |
|
|
|
// A helper class to manager lifetime of the poller associated with the
|
|
|
|
// A helper class to manager lifetime of the poller associated with the
|
|
|
|
// posix event engine.
|
|
|
|
// posix event engine.
|
|
|
|
class PosixEnginePollerManager |
|
|
|
class PosixEnginePollerManager |
|
|
|
: public grpc_event_engine::posix_engine::Scheduler { |
|
|
|
: public grpc_event_engine::experimental::Scheduler { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit PosixEnginePollerManager(std::shared_ptr<ThreadPool> executor); |
|
|
|
explicit PosixEnginePollerManager(std::shared_ptr<ThreadPool> executor); |
|
|
|
explicit PosixEnginePollerManager( |
|
|
|
explicit PosixEnginePollerManager( |
|
|
|
grpc_event_engine::posix_engine::PosixEventPoller* poller); |
|
|
|
grpc_event_engine::experimental::PosixEventPoller* poller); |
|
|
|
grpc_event_engine::posix_engine::PosixEventPoller* Poller() { |
|
|
|
grpc_event_engine::experimental::PosixEventPoller* Poller() { |
|
|
|
return poller_; |
|
|
|
return poller_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -121,7 +121,7 @@ class PosixEnginePollerManager |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
enum class PollerState { kExternal, kOk, kShuttingDown }; |
|
|
|
enum class PollerState { kExternal, kOk, kShuttingDown }; |
|
|
|
grpc_event_engine::posix_engine::PosixEventPoller* poller_ = nullptr; |
|
|
|
grpc_event_engine::experimental::PosixEventPoller* poller_ = nullptr; |
|
|
|
std::atomic<PollerState> poller_state_{PollerState::kOk}; |
|
|
|
std::atomic<PollerState> poller_state_{PollerState::kOk}; |
|
|
|
std::shared_ptr<ThreadPool> executor_; |
|
|
|
std::shared_ptr<ThreadPool> executor_; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -155,7 +155,7 @@ class PosixEventEngine final : public EventEngine, |
|
|
|
// constructor directly. Instead use the MakeTestOnlyPosixEventEngine static
|
|
|
|
// constructor directly. Instead use the MakeTestOnlyPosixEventEngine static
|
|
|
|
// method. Its expected to be used only in tests.
|
|
|
|
// method. Its expected to be used only in tests.
|
|
|
|
explicit PosixEventEngine( |
|
|
|
explicit PosixEventEngine( |
|
|
|
grpc_event_engine::posix_engine::PosixEventPoller* poller); |
|
|
|
grpc_event_engine::experimental::PosixEventPoller* poller); |
|
|
|
PosixEventEngine(); |
|
|
|
PosixEventEngine(); |
|
|
|
#else // GRPC_POSIX_SOCKET_TCP
|
|
|
|
#else // GRPC_POSIX_SOCKET_TCP
|
|
|
|
PosixEventEngine(); |
|
|
|
PosixEventEngine(); |
|
|
@ -194,7 +194,7 @@ class PosixEventEngine final : public EventEngine, |
|
|
|
// event engine will also not attempt to shutdown the poller since it does not
|
|
|
|
// event engine will also not attempt to shutdown the poller since it does not
|
|
|
|
// own it.
|
|
|
|
// own it.
|
|
|
|
static std::shared_ptr<PosixEventEngine> MakeTestOnlyPosixEventEngine( |
|
|
|
static std::shared_ptr<PosixEventEngine> MakeTestOnlyPosixEventEngine( |
|
|
|
grpc_event_engine::posix_engine::PosixEventPoller* test_only_poller) { |
|
|
|
grpc_event_engine::experimental::PosixEventPoller* test_only_poller) { |
|
|
|
return std::make_shared<PosixEventEngine>(test_only_poller); |
|
|
|
return std::make_shared<PosixEventEngine>(test_only_poller); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif // GRPC_POSIX_SOCKET_TCP
|
|
|
|
#endif // GRPC_POSIX_SOCKET_TCP
|
|
|
@ -216,10 +216,10 @@ class PosixEventEngine final : public EventEngine, |
|
|
|
std::shared_ptr<PosixEnginePollerManager> poller_manager); |
|
|
|
std::shared_ptr<PosixEnginePollerManager> poller_manager); |
|
|
|
|
|
|
|
|
|
|
|
ConnectionHandle ConnectInternal( |
|
|
|
ConnectionHandle ConnectInternal( |
|
|
|
grpc_event_engine::posix_engine::PosixSocketWrapper sock, |
|
|
|
grpc_event_engine::experimental::PosixSocketWrapper sock, |
|
|
|
OnConnectCallback on_connect, ResolvedAddress addr, |
|
|
|
OnConnectCallback on_connect, ResolvedAddress addr, |
|
|
|
MemoryAllocator&& allocator, |
|
|
|
MemoryAllocator&& allocator, |
|
|
|
const grpc_event_engine::posix_engine::PosixTcpOptions& options, |
|
|
|
const grpc_event_engine::experimental::PosixTcpOptions& options, |
|
|
|
Duration timeout); |
|
|
|
Duration timeout); |
|
|
|
|
|
|
|
|
|
|
|
void OnConnectFinishInternal(int connection_handle); |
|
|
|
void OnConnectFinishInternal(int connection_handle); |
|
|
@ -233,7 +233,7 @@ class PosixEventEngine final : public EventEngine, |
|
|
|
TaskHandleSet known_handles_ ABSL_GUARDED_BY(mu_); |
|
|
|
TaskHandleSet known_handles_ ABSL_GUARDED_BY(mu_); |
|
|
|
std::atomic<intptr_t> aba_token_{0}; |
|
|
|
std::atomic<intptr_t> aba_token_{0}; |
|
|
|
std::shared_ptr<ThreadPool> executor_; |
|
|
|
std::shared_ptr<ThreadPool> executor_; |
|
|
|
posix_engine::TimerManager timer_manager_; |
|
|
|
TimerManager timer_manager_; |
|
|
|
#ifdef GRPC_POSIX_SOCKET_TCP |
|
|
|
#ifdef GRPC_POSIX_SOCKET_TCP |
|
|
|
std::shared_ptr<PosixEnginePollerManager> poller_manager_; |
|
|
|
std::shared_ptr<PosixEnginePollerManager> poller_manager_; |
|
|
|
#endif // GRPC_POSIX_SOCKET_TCP
|
|
|
|
#endif // GRPC_POSIX_SOCKET_TCP
|
|
|
|