Go to the documentation of this file.
14 #ifndef GRPC_EVENT_ENGINE_EVENT_ENGINE_H
15 #define GRPC_EVENT_ENGINE_EVENT_ENGINE_H
26 #include "absl/functional/any_invocable.h"
27 #include "absl/status/status.h"
28 #include "absl/status/statusor.h"
33 namespace experimental {
103 class EventEngine :
public std::enable_shared_from_this<EventEngine>,
110 using Duration = std::chrono::duration<int64_t, std::nano>;
127 virtual void Run() = 0;
158 const struct sockaddr*
address()
const;
159 socklen_t
size()
const;
265 absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Endpoint>>)>;
303 std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory) = 0;
355 absl::AnyInvocable<void(absl::StatusOr<std::vector<ResolvedAddress>>)>;
358 absl::AnyInvocable<void(absl::StatusOr<std::vector<SRVRecord>>)>;
361 absl::AnyInvocable<void(absl::StatusOr<std::vector<std::string>>)>;
376 absl::string_view name,
377 absl::string_view default_port) = 0;
383 absl::string_view name) = 0;
389 absl::string_view name) = 0;
410 virtual absl::StatusOr<std::unique_ptr<DNSResolver>>
GetDNSResolver(
435 virtual void Run(absl::AnyInvocable<
void()> closure) = 0;
463 absl::AnyInvocable<
void()> closure) = 0;
486 absl::AnyInvocable<std::shared_ptr<EventEngine>()> factory);
552 template <
typename Sink>
557 template <
typename Sink>
565 #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:265
virtual ~EventEngine()=default
At time of destruction, the EventEngine must have no active responsibilities.
std::ostream & operator<<(std::ostream &out, const EventEngine::TaskHandle &handle)
void ShutdownDefaultEventEngine()
Resets gRPC to use one of the default internal EventEngines for all new GetDefaultEventEngine request...
A handle to a cancellable connection attempt.
Definition: event_engine.h:140
A struct representing optional arguments that may be provided to an EventEngine Endpoint Write API ca...
Definition: event_engine.h:220
std::shared_ptr< EventEngine > GetDefaultEventEngine()
Returns the default EventEngine instance.
static constexpr socklen_t MAX_SIZE_BYTES
Definition: event_engine.h:153
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:273
The EventEngine Interface.
Definition: event_engine.h:103
int64_t read_hint_bytes
Definition: event_engine.h:189
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:553
absl::AnyInvocable< void(absl::StatusOr< std::vector< SRVRecord > >)> LookupSRVCallback
Called with a collection of SRV records.
Definition: event_engine.h:358
int port
Definition: event_engine.h:348
A struct representing optional arguments that may be provided to an EventEngine Endpoint Read API cal...
Definition: event_engine.h:183
virtual absl::StatusOr< int > Bind(const ResolvedAddress &addr)=0
Bind an address/port to this Listener.
std::string host
Definition: event_engine.h:347
intptr_t keys[2]
Definition: event_engine.h:141
void EventEngineFactoryReset()
[DEPRECATED] 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:355
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:340
int64_t max_frame_size
Definition: event_engine.h:228
DNS SRV record type.
Definition: event_engine.h:346
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:151
Listens for incoming connection requests from gRPC clients and initiates request processing once conn...
Definition: event_engine.h:269
A Wrapper around grpc_slice_buffer pointer.
Definition: slice_buffer.h:50
std::string FormatHandleString(uint64_t key1, uint64_t key2)
A custom closure type for EventEngine task execution.
Definition: event_engine.h:118
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:223
std::string dns_server
If empty, default DNS servers will be used.
Definition: event_engine.h:343
int weight
Definition: event_engine.h:350
void SetEventEngineFactory(absl::AnyInvocable< std::shared_ptr< EventEngine >()> factory)
[DEPRECATED] Replace gRPC's default EventEngine factory.
virtual const ResolvedAddress & GetPeerAddress() const =0
Returns an address in the format described in DNSResolver.
Provides asynchronous resolution.
Definition: event_engine.h:337
Definition: extensible.h:25
Represents a scheduled task.
Definition: event_engine.h:133
virtual bool Cancel(TaskHandle handle)=0
Request cancellation of a task.
void SetDefaultEventEngine(std::shared_ptr< EventEngine > engine)
Set the default EventEngine instance, which will be used throughout gRPC.
std::shared_ptr< EventEngine > CreateEventEngine()
Create a new EventEngine instance.
int priority
Definition: event_engine.h:349
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:135
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:361
static const GRPC_DLL ConnectionHandle kInvalid
Definition: event_engine.h:142
One end of a connection between a gRPC client and server.
Definition: event_engine.h:174
Definition: memory_allocator.h:33
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.
intptr_t keys[2]
Definition: event_engine.h:134
virtual ~Listener()=default
::absl::Status Status
Definition: config_protobuf.h:107
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:110
virtual const ResolvedAddress & GetLocalAddress() const =0
bool operator==(const EventEngine::TaskHandle &lhs, const EventEngine::TaskHandle &rhs)