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;
163 const struct sockaddr*
address()
const;
164 socklen_t
size()
const;
267 absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Endpoint>>)>;
305 std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory) = 0;
357 absl::AnyInvocable<void(absl::StatusOr<std::vector<ResolvedAddress>>)>;
360 absl::AnyInvocable<void(absl::StatusOr<std::vector<SRVRecord>>)>;
363 absl::AnyInvocable<void(absl::StatusOr<std::vector<std::string>>)>;
378 absl::string_view name,
379 absl::string_view default_port) = 0;
385 absl::string_view name) = 0;
391 absl::string_view name) = 0;
412 virtual absl::StatusOr<std::unique_ptr<DNSResolver>>
GetDNSResolver(
437 virtual void Run(absl::AnyInvocable<
void()> closure) = 0;
465 absl::AnyInvocable<
void()> closure) = 0;
487 absl::AnyInvocable<std::unique_ptr<EventEngine>()> factory);
502 #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:267
virtual ~EventEngine()=default
At time of destruction, the EventEngine must have no active responsibilities.
A handle to a cancellable connection attempt.
Definition: event_engine.h:141
A struct representing optional arguments that may be provided to an EventEngine Endpoint Write API ca...
Definition: event_engine.h:222
static constexpr socklen_t MAX_SIZE_BYTES
Definition: event_engine.h:158
virtual TaskHandle RunAfter(Duration when, Closure *closure)=0
Synonymous with scheduling an alarm to run after duration when.
friend bool operator==(const TaskHandle &lhs, const TaskHandle &rhs)
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:275
The EventEngine Interface.
Definition: event_engine.h:102
int64_t read_hint_bytes
Definition: event_engine.h:194
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.
absl::AnyInvocable< void(absl::StatusOr< std::vector< SRVRecord > >)> LookupSRVCallback
Called with a collection of SRV records.
Definition: event_engine.h:360
int port
Definition: event_engine.h:350
A struct representing optional arguments that may be provided to an EventEngine Endpoint Read API cal...
Definition: event_engine.h:188
virtual absl::StatusOr< int > Bind(const ResolvedAddress &addr)=0
Bind an address/port to this Listener.
std::string host
Definition: event_engine.h:349
intptr_t keys[2]
Definition: event_engine.h:142
friend bool operator==(const ConnectionHandle &lhs, const ConnectionHandle &rhs)
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:357
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.
Optional configuration for DNSResolvers.
Definition: event_engine.h:342
int64_t max_frame_size
Definition: event_engine.h:230
DNS SRV record type.
Definition: event_engine.h:348
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:156
Listens for incoming connection requests from gRPC clients and initiates request processing once conn...
Definition: event_engine.h:271
A Wrapper around grpc_slice_buffer pointer.
Definition: slice_buffer.h:52
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:225
std::string dns_server
If empty, default DNS servers will be used.
Definition: event_engine.h:345
int weight
Definition: event_engine.h:352
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:339
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:351
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:363
static const GRPC_DLL ConnectionHandle kInvalid
Definition: event_engine.h:143
One end of a connection between a gRPC client and server.
Definition: event_engine.h:179
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
friend bool operator!=(const ConnectionHandle &lhs, const ConnectionHandle &rhs)
virtual ~Listener()=default
::absl::Status Status
Definition: config_protobuf.h:106
friend bool operator!=(const TaskHandle &lhs, const TaskHandle &rhs)
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