Go to the documentation of this file.
14 #ifndef GRPC_EVENT_ENGINE_EVENT_ENGINE_H
15 #define GRPC_EVENT_ENGINE_EVENT_ENGINE_H
19 #include "absl/functional/any_invocable.h"
20 #include "absl/status/status.h"
21 #include "absl/status/statusor.h"
32 namespace experimental {
102 class EventEngine :
public std::enable_shared_from_this<EventEngine>,
109 using Duration = std::chrono::duration<int64_t, std::nano>;
126 virtual void Run() = 0;
157 const struct sockaddr*
address()
const;
158 socklen_t
size()
const;
210 virtual bool Read(absl::AnyInvocable<
void(absl::Status)> on_read,
246 virtual bool Write(absl::AnyInvocable<
void(absl::Status)> on_writable,
261 absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Endpoint>>)>;
277 virtual absl::Status
Start() = 0;
297 absl::AnyInvocable<
void(absl::Status)> on_shutdown,
299 std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory) = 0;
351 absl::AnyInvocable<void(absl::StatusOr<std::vector<ResolvedAddress>>)>;
354 absl::AnyInvocable<void(absl::StatusOr<std::vector<SRVRecord>>)>;
357 absl::AnyInvocable<void(absl::StatusOr<std::vector<std::string>>)>;
372 absl::string_view name,
373 absl::string_view default_port) = 0;
379 absl::string_view name) = 0;
385 absl::string_view name) = 0;
406 virtual absl::StatusOr<std::unique_ptr<DNSResolver>>
GetDNSResolver(
431 virtual void Run(absl::AnyInvocable<
void()> closure) = 0;
459 absl::AnyInvocable<
void()> closure) = 0;
481 absl::AnyInvocable<std::unique_ptr<EventEngine>()> factory);
510 template <
typename Sink>
515 template <
typename Sink>
523 #endif // GRPC_EVENT_ENGINE_EVENT_ENGINE_H
absl::AnyInvocable< void(absl::StatusOr< std::unique_ptr< Endpoint > >)> OnConnectCallback
Called when a new connection is established.
Definition: event_engine.h:261
virtual ~EventEngine()=default
At time of destruction, the EventEngine must have no active responsibilities.
std::ostream & operator<<(std::ostream &out, const EventEngine::TaskHandle &handle)
A handle to a cancellable connection attempt.
Definition: event_engine.h:139
A struct representing optional arguments that may be provided to an EventEngine Endpoint Write API ca...
Definition: event_engine.h:216
static constexpr socklen_t MAX_SIZE_BYTES
Definition: event_engine.h:152
virtual TaskHandle RunAfter(Duration when, Closure *closure)=0
Synonymous with scheduling an alarm to run after duration when.
absl::AnyInvocable< void(std::unique_ptr< Endpoint >, MemoryAllocator memory_allocator)> AcceptCallback
Called when the listener has accepted a new client connection.
Definition: event_engine.h:269
The EventEngine Interface.
Definition: event_engine.h:102
int64_t read_hint_bytes
Definition: event_engine.h:188
virtual ~Endpoint()=default
Shuts down all connections and invokes all pending read or write callbacks with an error status.
virtual bool IsWorkerThread()=0
virtual ~DNSResolver()=default
virtual bool Read(absl::AnyInvocable< void(absl::Status)> on_read, SliceBuffer *buffer, const ReadArgs *args)=0
Reads data from the Endpoint.
virtual void LookupHostname(LookupHostnameCallback on_resolve, absl::string_view name, absl::string_view default_port)=0
Asynchronously resolve an address.
void AbslStringify(Sink &out, const EventEngine::ConnectionHandle &handle)
Definition: event_engine.h:511
absl::AnyInvocable< void(absl::StatusOr< std::vector< SRVRecord > >)> LookupSRVCallback
Called with a collection of SRV records.
Definition: event_engine.h:354
int port
Definition: event_engine.h:344
A struct representing optional arguments that may be provided to an EventEngine Endpoint Read API cal...
Definition: event_engine.h:182
virtual absl::StatusOr< int > Bind(const ResolvedAddress &addr)=0
Bind an address/port to this Listener.
std::string host
Definition: event_engine.h:343
intptr_t keys[2]
Definition: event_engine.h:140
void EventEngineFactoryReset()
Reset gRPC's EventEngine factory to the built-in default.
absl::AnyInvocable< void(absl::StatusOr< std::vector< ResolvedAddress > >)> LookupHostnameCallback
Called with the collection of sockaddrs that were resolved from a given target address.
Definition: event_engine.h:351
virtual bool Write(absl::AnyInvocable< void(absl::Status)> on_writable, SliceBuffer *data, const WriteArgs *args)=0
Writes data out on the connection.
virtual bool CancelConnect(ConnectionHandle handle)=0
Request cancellation of a connection attempt.
bool operator!=(const EventEngine::TaskHandle &lhs, const EventEngine::TaskHandle &rhs)
Optional configuration for DNSResolvers.
Definition: event_engine.h:336
int64_t max_frame_size
Definition: event_engine.h:224
DNS SRV record type.
Definition: event_engine.h:342
virtual void LookupTXT(LookupTXTCallback on_resolve, absl::string_view name)=0
Asynchronously perform a TXT record lookup.
Collection of parameters used to configure client and server endpoints.
Definition: endpoint_config.h:31
Thin wrapper around a platform-specific sockaddr type.
Definition: event_engine.h:150
Listens for incoming connection requests from gRPC clients and initiates request processing once conn...
Definition: event_engine.h:265
A Wrapper around grpc_slice_buffer pointer.
Definition: slice_buffer.h:52
std::string FormatHandleString(uint64_t key1, uint64_t key2)
A custom closure type for EventEngine task execution.
Definition: event_engine.h:117
ResolvedAddress()=default
const struct sockaddr * address() const
virtual absl::Status Start()=0
Closure & operator=(const Closure &)=delete
virtual ~Closure()=default
virtual void Run(Closure *closure)=0
Asynchronously executes a task as soon as possible.
void * google_specific
Definition: event_engine.h:219
std::string dns_server
If empty, default DNS servers will be used.
Definition: event_engine.h:339
int weight
Definition: event_engine.h:346
virtual const ResolvedAddress & GetPeerAddress() const =0
Returns an address in the format described in DNSResolver.
std::unique_ptr< EventEngine > CreateEventEngine()
Create an EventEngine using the default factory.
Provides asynchronous resolution.
Definition: event_engine.h:333
Definition: extensible.h:25
Represents a scheduled task.
Definition: event_engine.h:132
virtual bool Cancel(TaskHandle handle)=0
Request cancellation of a task.
int priority
Definition: event_engine.h:345
virtual absl::StatusOr< std::unique_ptr< DNSResolver > > GetDNSResolver(const DNSResolver::ResolverOptions &options)=0
Creates and returns an instance of a DNSResolver, optionally configured by the options struct.
static const GRPC_DLL TaskHandle kInvalid
Definition: event_engine.h:134
Definition: endpoint_config.h:24
absl::AnyInvocable< void(absl::StatusOr< std::vector< std::string > >)> LookupTXTCallback
Called with the result of a TXT record lookup.
Definition: event_engine.h:357
static const GRPC_DLL ConnectionHandle kInvalid
Definition: event_engine.h:141
One end of a connection between a gRPC client and server.
Definition: event_engine.h:173
Definition: memory_allocator.h:34
virtual ConnectionHandle Connect(OnConnectCallback on_connect, const ResolvedAddress &addr, const EndpointConfig &args, MemoryAllocator memory_allocator, Duration timeout)=0
Creates a client network connection to a remote network listener.
void SetEventEngineFactory(absl::AnyInvocable< std::unique_ptr< EventEngine >()> factory)
Replace gRPC's default EventEngine factory.
intptr_t keys[2]
Definition: event_engine.h:133
virtual ~Listener()=default
virtual void LookupSRV(LookupSRVCallback on_resolve, absl::string_view name)=0
Asynchronously perform an SRV record lookup.
virtual absl::StatusOr< std::unique_ptr< Listener > > CreateListener(Listener::AcceptCallback on_accept, absl::AnyInvocable< void(absl::Status)> on_shutdown, const EndpointConfig &config, std::unique_ptr< MemoryAllocatorFactory > memory_allocator_factory)=0
Factory method to create a network listener / server.
std::chrono::duration< int64_t, std::nano > Duration
A duration between two events.
Definition: event_engine.h:109
virtual const ResolvedAddress & GetLocalAddress() const =0
bool operator==(const EventEngine::TaskHandle &lhs, const EventEngine::TaskHandle &rhs)