Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
grpc_event_engine::experimental::IomgrEventEngine Class Referencefinal

#include <iomgr_engine.h>

Inheritance diagram for grpc_event_engine::experimental::IomgrEventEngine:
Inheritance graph
[legend]

Classes

struct  ClosureData
 
class  IomgrDNSResolver
 
class  IomgrEndpoint
 
class  IomgrListener
 

Public Member Functions

bool Cancel (TaskHandle handle) override
 
bool CancelConnect (ConnectionHandle handle) override
 
ConnectionHandle Connect (OnConnectCallback on_connect, const ResolvedAddress &addr, const EndpointConfig &args, MemoryAllocator memory_allocator, Duration timeout) override
 
absl::StatusOr< std::unique_ptr< Listener > > CreateListener (Listener::AcceptCallback on_accept, std::function< void(absl::Status)> on_shutdown, const EndpointConfig &config, std::unique_ptr< MemoryAllocatorFactory > memory_allocator_factory) override
 
std::unique_ptr< DNSResolverGetDNSResolver (const DNSResolver::ResolverOptions &options) override
 
 IomgrEventEngine ()
 
bool IsWorkerThread () override
 
void Run (Closure *closure) override
 
void Run (std::function< void()> closure) override
 
TaskHandle RunAfter (Duration when, Closure *closure) override
 
TaskHandle RunAfter (Duration when, std::function< void()> closure) override
 
 ~IomgrEventEngine () override
 
- Public Member Functions inherited from grpc_event_engine::experimental::EventEngine
virtual std::unique_ptr< DNSResolverGetDNSResolver (const DNSResolver::ResolverOptions &options)=0
 
virtual ~EventEngine ()=default
 

Private Member Functions

TaskHandleSet known_handles_ ABSL_GUARDED_BY (mu_)
 
EventEngine::TaskHandle RunAfterInternal (Duration when, std::function< void()> cb)
 
grpc_core::Timestamp ToTimestamp (EventEngine::Duration when)
 

Private Attributes

std::atomic< intptr_taba_token_ {0}
 
grpc_core::Mutex mu_
 
iomgr_engine::ThreadPool thread_pool_ {2}
 
iomgr_engine::TimerManager timer_manager_
 

Additional Inherited Members

- Public Types inherited from grpc_event_engine::experimental::EventEngine
using Duration = std::chrono::duration< int64_t, std::nano >
 
using OnConnectCallback = std::function< void(absl::StatusOr< std::unique_ptr< Endpoint > >)>
 

Detailed Description

Definition at line 45 of file iomgr_engine.h.

Constructor & Destructor Documentation

◆ IomgrEventEngine()

grpc_event_engine::experimental::IomgrEventEngine::IomgrEventEngine ( )

Definition at line 69 of file iomgr_engine.cc.

◆ ~IomgrEventEngine()

grpc_event_engine::experimental::IomgrEventEngine::~IomgrEventEngine ( )
override

Definition at line 71 of file iomgr_engine.cc.

Member Function Documentation

◆ ABSL_GUARDED_BY()

TaskHandleSet known_handles_ grpc_event_engine::experimental::IomgrEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ Cancel()

bool grpc_event_engine::experimental::IomgrEventEngine::Cancel ( TaskHandle  handle)
overridevirtual

Request cancellation of a task.

If the associated closure has already been scheduled to run, it will not be cancelled, and this function will return false.

If the associated callback has not been scheduled to run, it will be cancelled, and the associated std::function or Closure* will not be executed. In this case, Cancel will return true.

Implementation note: closures should be destroyed in a timely manner after execution or cancelliation (milliseconds), since any state bound to the closure may need to be destroyed for things to progress (e.g., if a closure holds a ref to some ref-counted object).

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 84 of file iomgr_engine.cc.

◆ CancelConnect()

bool grpc_event_engine::experimental::IomgrEventEngine::CancelConnect ( ConnectionHandle  handle)
overridevirtual

Request cancellation of a connection attempt.

If the associated connection has already been completed, it will not be cancelled, and this method will return false.

If the associated connection has not been completed, it will be cancelled, and this method will return true. The OnConnectCallback will not be called.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 138 of file iomgr_engine.cc.

◆ Connect()

EventEngine::ConnectionHandle grpc_event_engine::experimental::IomgrEventEngine::Connect ( OnConnectCallback  on_connect,
const ResolvedAddress addr,
const EndpointConfig args,
MemoryAllocator  memory_allocator,
Duration  timeout 
)
overridevirtual

Creates a client network connection to a remote network listener.

Even in the event of an error, it is expected that the on_connect callback will be asynchronously executed exactly once by the EventEngine. A connection attempt can be cancelled using the CancelConnect method.

Implementation Note: it is important that the memory_allocator be used for all read/write buffer allocations in the EventEngine implementation. This allows gRPC's ResourceQuota system to monitor and control memory usage with graceful degradation mechanisms. Please see the MemoryAllocator API for more information.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 142 of file iomgr_engine.cc.

◆ CreateListener()

absl::StatusOr< std::unique_ptr< EventEngine::Listener > > grpc_event_engine::experimental::IomgrEventEngine::CreateListener ( Listener::AcceptCallback  on_accept,
std::function< void(absl::Status)>  on_shutdown,
const EndpointConfig config,
std::unique_ptr< MemoryAllocatorFactory memory_allocator_factory 
)
overridevirtual

Factory method to create a network listener / server.

Once a Listener is created and started, the on_accept callback will be called once asynchronously for each established connection. This method may return a non-OK status immediately if an error was encountered in any synchronous steps required to create the Listener. In this case, on_shutdown will never be called.

If this method returns a Listener, then on_shutdown will be invoked exactly once, when the Listener is shut down. The status passed to it will indicate if there was a problem during shutdown.

The provided MemoryAllocatorFactory is used to create MemoryAllocators for Endpoint construction.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 150 of file iomgr_engine.cc.

◆ GetDNSResolver()

std::unique_ptr< EventEngine::DNSResolver > grpc_event_engine::experimental::IomgrEventEngine::GetDNSResolver ( const DNSResolver::ResolverOptions &  options)
override

Definition at line 129 of file iomgr_engine.cc.

◆ IsWorkerThread()

bool grpc_event_engine::experimental::IomgrEventEngine::IsWorkerThread ( )
overridevirtual

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 134 of file iomgr_engine.cc.

◆ Run() [1/2]

void grpc_event_engine::experimental::IomgrEventEngine::Run ( Closure closure)
overridevirtual

Asynchronously executes a task as soon as possible.

Closures scheduled with Run cannot be cancelled. The closure will not be deleted after it has been run, ownership remains with the caller.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 108 of file iomgr_engine.cc.

◆ Run() [2/2]

void grpc_event_engine::experimental::IomgrEventEngine::Run ( std::function< void()>  closure)
overridevirtual

Asynchronously executes a task as soon as possible.

Closures scheduled with Run cannot be cancelled. Unlike the overloaded Closure alternative, the std::function version's closure will be deleted by the EventEngine after the closure has been run.

This version of Run may be less performant than the Closure version in some scenarios. This overload is useful in situations where performance is not a critical concern.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 104 of file iomgr_engine.cc.

◆ RunAfter() [1/2]

EventEngine::TaskHandle grpc_event_engine::experimental::IomgrEventEngine::RunAfter ( Duration  when,
Closure closure 
)
overridevirtual

Synonymous with scheduling an alarm to run after duration when.

The closure will execute when time when arrives unless it has been cancelled via the Cancel method. If cancelled, the closure will not be run, nor will it be deleted. Ownership remains with the caller.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 99 of file iomgr_engine.cc.

◆ RunAfter() [2/2]

EventEngine::TaskHandle grpc_event_engine::experimental::IomgrEventEngine::RunAfter ( Duration  when,
std::function< void()>  closure 
)
overridevirtual

Synonymous with scheduling an alarm to run after duration when.

The closure will execute when time when arrives unless it has been cancelled via the Cancel method. If cancelled, the closure will not be run. Unilke the overloaded Closure alternative, the std::function version's closure will be deleted by the EventEngine after the closure has been run, or upon cancellation.

This version of RunAfter may be less performant than the Closure version in some scenarios. This overload is useful in situations where performance is not a critical concern.

Implements grpc_event_engine::experimental::EventEngine.

Definition at line 94 of file iomgr_engine.cc.

◆ RunAfterInternal()

EventEngine::TaskHandle grpc_event_engine::experimental::IomgrEventEngine::RunAfterInternal ( Duration  when,
std::function< void()>  cb 
)
private

Definition at line 112 of file iomgr_engine.cc.

◆ ToTimestamp()

grpc_core::Timestamp grpc_event_engine::experimental::IomgrEventEngine::ToTimestamp ( EventEngine::Duration  when)
private

Definition at line 44 of file iomgr_engine.cc.

Member Data Documentation

◆ aba_token_

std::atomic<intptr_t> grpc_event_engine::experimental::IomgrEventEngine::aba_token_ {0}
private

Definition at line 116 of file iomgr_engine.h.

◆ mu_

grpc_core::Mutex grpc_event_engine::experimental::IomgrEventEngine::mu_
private

Definition at line 114 of file iomgr_engine.h.

◆ thread_pool_

iomgr_engine::ThreadPool grpc_event_engine::experimental::IomgrEventEngine::thread_pool_ {2}
private

Definition at line 112 of file iomgr_engine.h.

◆ timer_manager_

iomgr_engine::TimerManager grpc_event_engine::experimental::IomgrEventEngine::timer_manager_
private

Definition at line 111 of file iomgr_engine.h.


The documentation for this class was generated from the following files:


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:40