|
|
@ -19,6 +19,7 @@ |
|
|
|
#include <functional> |
|
|
|
#include <functional> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "absl/functional/any_invocable.h" |
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/status/statusor.h" |
|
|
|
#include "absl/status/statusor.h" |
|
|
|
|
|
|
|
|
|
|
@ -172,7 +173,7 @@ class EventEngine { |
|
|
|
/// For failed read operations, implementations should pass the appropriate
|
|
|
|
/// For failed read operations, implementations should pass the appropriate
|
|
|
|
/// statuses to \a on_read. For example, callbacks might expect to receive
|
|
|
|
/// statuses to \a on_read. For example, callbacks might expect to receive
|
|
|
|
/// CANCELLED on endpoint shutdown.
|
|
|
|
/// CANCELLED on endpoint shutdown.
|
|
|
|
virtual void Read(std::function<void(absl::Status)> on_read, |
|
|
|
virtual void Read(absl::AnyInvocable<void(absl::Status)> on_read, |
|
|
|
SliceBuffer* buffer, const ReadArgs* args) = 0; |
|
|
|
SliceBuffer* buffer, const ReadArgs* args) = 0; |
|
|
|
/// A struct representing optional arguments that may be provided to an
|
|
|
|
/// A struct representing optional arguments that may be provided to an
|
|
|
|
/// EventEngine Endpoint Write API call.
|
|
|
|
/// EventEngine Endpoint Write API call.
|
|
|
@ -206,7 +207,7 @@ class EventEngine { |
|
|
|
/// For failed write operations, implementations should pass the appropriate
|
|
|
|
/// For failed write operations, implementations should pass the appropriate
|
|
|
|
/// statuses to \a on_writable. For example, callbacks might expect to
|
|
|
|
/// statuses to \a on_writable. For example, callbacks might expect to
|
|
|
|
/// receive CANCELLED on endpoint shutdown.
|
|
|
|
/// receive CANCELLED on endpoint shutdown.
|
|
|
|
virtual void Write(std::function<void(absl::Status)> on_writable, |
|
|
|
virtual void Write(absl::AnyInvocable<void(absl::Status)> on_writable, |
|
|
|
SliceBuffer* data, const WriteArgs* args) = 0; |
|
|
|
SliceBuffer* data, const WriteArgs* args) = 0; |
|
|
|
/// Returns an address in the format described in DNSResolver. The returned
|
|
|
|
/// Returns an address in the format described in DNSResolver. The returned
|
|
|
|
/// values are expected to remain valid for the life of the Endpoint.
|
|
|
|
/// values are expected to remain valid for the life of the Endpoint.
|
|
|
@ -221,14 +222,14 @@ class EventEngine { |
|
|
|
/// expect to receive DEADLINE_EXCEEDED statuses when appropriate, or
|
|
|
|
/// expect to receive DEADLINE_EXCEEDED statuses when appropriate, or
|
|
|
|
/// CANCELLED statuses on EventEngine shutdown.
|
|
|
|
/// CANCELLED statuses on EventEngine shutdown.
|
|
|
|
using OnConnectCallback = |
|
|
|
using OnConnectCallback = |
|
|
|
std::function<void(absl::StatusOr<std::unique_ptr<Endpoint>>)>; |
|
|
|
absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Endpoint>>)>; |
|
|
|
|
|
|
|
|
|
|
|
/// Listens for incoming connection requests from gRPC clients and initiates
|
|
|
|
/// Listens for incoming connection requests from gRPC clients and initiates
|
|
|
|
/// request processing once connections are established.
|
|
|
|
/// request processing once connections are established.
|
|
|
|
class Listener { |
|
|
|
class Listener { |
|
|
|
public: |
|
|
|
public: |
|
|
|
/// Called when the listener has accepted a new client connection.
|
|
|
|
/// Called when the listener has accepted a new client connection.
|
|
|
|
using AcceptCallback = std::function<void( |
|
|
|
using AcceptCallback = absl::AnyInvocable<void( |
|
|
|
std::unique_ptr<Endpoint>, MemoryAllocator memory_allocator)>; |
|
|
|
std::unique_ptr<Endpoint>, MemoryAllocator memory_allocator)>; |
|
|
|
virtual ~Listener() = default; |
|
|
|
virtual ~Listener() = default; |
|
|
|
/// Bind an address/port to this Listener.
|
|
|
|
/// Bind an address/port to this Listener.
|
|
|
@ -256,7 +257,7 @@ class EventEngine { |
|
|
|
/// MemoryAllocators for Endpoint construction.
|
|
|
|
/// MemoryAllocators for Endpoint construction.
|
|
|
|
virtual absl::StatusOr<std::unique_ptr<Listener>> CreateListener( |
|
|
|
virtual absl::StatusOr<std::unique_ptr<Listener>> CreateListener( |
|
|
|
Listener::AcceptCallback on_accept, |
|
|
|
Listener::AcceptCallback on_accept, |
|
|
|
std::function<void(absl::Status)> on_shutdown, |
|
|
|
absl::AnyInvocable<void(absl::Status)> on_shutdown, |
|
|
|
const EndpointConfig& config, |
|
|
|
const EndpointConfig& config, |
|
|
|
std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory) = 0; |
|
|
|
std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory) = 0; |
|
|
|
/// Creates a client network connection to a remote network listener.
|
|
|
|
/// Creates a client network connection to a remote network listener.
|
|
|
@ -308,12 +309,13 @@ class EventEngine { |
|
|
|
/// Called with the collection of sockaddrs that were resolved from a given
|
|
|
|
/// Called with the collection of sockaddrs that were resolved from a given
|
|
|
|
/// target address.
|
|
|
|
/// target address.
|
|
|
|
using LookupHostnameCallback = |
|
|
|
using LookupHostnameCallback = |
|
|
|
std::function<void(absl::StatusOr<std::vector<ResolvedAddress>>)>; |
|
|
|
absl::AnyInvocable<void(absl::StatusOr<std::vector<ResolvedAddress>>)>; |
|
|
|
/// Called with a collection of SRV records.
|
|
|
|
/// Called with a collection of SRV records.
|
|
|
|
using LookupSRVCallback = |
|
|
|
using LookupSRVCallback = |
|
|
|
std::function<void(absl::StatusOr<std::vector<SRVRecord>>)>; |
|
|
|
absl::AnyInvocable<void(absl::StatusOr<std::vector<SRVRecord>>)>; |
|
|
|
/// Called with the result of a TXT record lookup
|
|
|
|
/// Called with the result of a TXT record lookup
|
|
|
|
using LookupTXTCallback = std::function<void(absl::StatusOr<std::string>)>; |
|
|
|
using LookupTXTCallback = |
|
|
|
|
|
|
|
absl::AnyInvocable<void(absl::StatusOr<std::string>)>; |
|
|
|
|
|
|
|
|
|
|
|
virtual ~DNSResolver() = default; |
|
|
|
virtual ~DNSResolver() = default; |
|
|
|
|
|
|
|
|
|
|
@ -381,13 +383,13 @@ class EventEngine { |
|
|
|
/// Asynchronously executes a task as soon as possible.
|
|
|
|
/// Asynchronously executes a task as soon as possible.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// \a Closures scheduled with \a Run cannot be cancelled. Unlike the
|
|
|
|
/// \a Closures scheduled with \a Run cannot be cancelled. Unlike the
|
|
|
|
/// overloaded \a Closure alternative, the std::function version's \a closure
|
|
|
|
/// overloaded \a Closure alternative, the absl::AnyInvocable version's \a
|
|
|
|
/// will be deleted by the EventEngine after the closure has been run.
|
|
|
|
/// closure will be deleted by the EventEngine after the closure has been run.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This version of \a Run may be less performant than the \a Closure version
|
|
|
|
/// This version of \a Run may be less performant than the \a Closure version
|
|
|
|
/// in some scenarios. This overload is useful in situations where performance
|
|
|
|
/// in some scenarios. This overload is useful in situations where performance
|
|
|
|
/// is not a critical concern.
|
|
|
|
/// is not a critical concern.
|
|
|
|
virtual void Run(std::function<void()> closure) = 0; |
|
|
|
virtual void Run(absl::AnyInvocable<void()> closure) = 0; |
|
|
|
/// Synonymous with scheduling an alarm to run after duration \a when.
|
|
|
|
/// Synonymous with scheduling an alarm to run after duration \a when.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The \a closure will execute when time \a when arrives unless it has been
|
|
|
|
/// The \a closure will execute when time \a when arrives unless it has been
|
|
|
@ -398,22 +400,23 @@ class EventEngine { |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The \a closure will execute when time \a when arrives unless it has been
|
|
|
|
/// The \a closure will execute when time \a when arrives unless it has been
|
|
|
|
/// cancelled via the \a Cancel method. If cancelled, the closure will not be
|
|
|
|
/// cancelled via the \a Cancel method. If cancelled, the closure will not be
|
|
|
|
/// run. Unilke the overloaded \a Closure alternative, the std::function
|
|
|
|
/// run. Unilke the overloaded \a Closure alternative, the absl::AnyInvocable
|
|
|
|
/// version's \a closure will be deleted by the EventEngine after the closure
|
|
|
|
/// version's \a closure will be deleted by the EventEngine after the closure
|
|
|
|
/// has been run, or upon cancellation.
|
|
|
|
/// has been run, or upon cancellation.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This version of \a RunAfter may be less performant than the \a Closure
|
|
|
|
/// This version of \a RunAfter may be less performant than the \a Closure
|
|
|
|
/// version in some scenarios. This overload is useful in situations where
|
|
|
|
/// version in some scenarios. This overload is useful in situations where
|
|
|
|
/// performance is not a critical concern.
|
|
|
|
/// performance is not a critical concern.
|
|
|
|
virtual TaskHandle RunAfter(Duration when, std::function<void()> closure) = 0; |
|
|
|
virtual TaskHandle RunAfter(Duration when, |
|
|
|
|
|
|
|
absl::AnyInvocable<void()> closure) = 0; |
|
|
|
/// Request cancellation of a task.
|
|
|
|
/// Request cancellation of a task.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// If the associated closure has already been scheduled to run, it will not
|
|
|
|
/// If the associated closure has already been scheduled to run, it will not
|
|
|
|
/// be cancelled, and this function will return false.
|
|
|
|
/// be cancelled, and this function will return false.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// If the associated callback has not been scheduled to run, it will be
|
|
|
|
/// If the associated callback has not been scheduled to run, it will be
|
|
|
|
/// cancelled, and the associated std::function or \a Closure* will not be
|
|
|
|
/// cancelled, and the associated absl::AnyInvocable or \a Closure* will not
|
|
|
|
/// executed. In this case, Cancel will return true.
|
|
|
|
/// be executed. In this case, Cancel will return true.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Implementation note: closures should be destroyed in a timely manner after
|
|
|
|
/// Implementation note: closures should be destroyed in a timely manner after
|
|
|
|
/// execution or cancelliation (milliseconds), since any state bound to the
|
|
|
|
/// execution or cancelliation (milliseconds), since any state bound to the
|
|
|
@ -432,7 +435,7 @@ class EventEngine { |
|
|
|
/// created, applications must set a custom EventEngine factory method *before*
|
|
|
|
/// created, applications must set a custom EventEngine factory method *before*
|
|
|
|
/// grpc is initialized.
|
|
|
|
/// grpc is initialized.
|
|
|
|
void SetDefaultEventEngineFactory( |
|
|
|
void SetDefaultEventEngineFactory( |
|
|
|
std::function<std::unique_ptr<EventEngine>()> factory); |
|
|
|
absl::AnyInvocable<std::unique_ptr<EventEngine>()> factory); |
|
|
|
|
|
|
|
|
|
|
|
/// Create an EventEngine using the default factory.
|
|
|
|
/// Create an EventEngine using the default factory.
|
|
|
|
std::unique_ptr<EventEngine> CreateEventEngine(); |
|
|
|
std::unique_ptr<EventEngine> CreateEventEngine(); |
|
|
|