Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
grpc_event_engine::experimental::FuzzingEventEngine Class Reference

#include <fuzzing_event_engine.h>

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

Classes

struct  Options
 
struct  Task
 

Public Types

using Time = std::chrono::time_point< FuzzingEventEngine, Duration >
 
- 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 > >)>
 

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
 
void FuzzingDone ()
 
 FuzzingEventEngine (Options options, const fuzzing_event_engine::Actions &actions)
 
std::unique_ptr< DNSResolverGetDNSResolver (const DNSResolver::ResolverOptions &options) override
 
bool IsWorkerThread () override
 
Time Now () ABSL_LOCKS_EXCLUDED(mu_)
 
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
 
void Tick ()
 
 ~FuzzingEventEngine () 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

intptr_t next_task_id_ ABSL_GUARDED_BY (mu_)
 
intptr_t current_tick_ ABSL_GUARDED_BY (mu_)
 
Time now_ ABSL_GUARDED_BY (mu_)
 
std::map< intptr_t, Duration > tick_increments_ ABSL_GUARDED_BY (mu_)
 
std::map< intptr_t, Duration > task_delays_ ABSL_GUARDED_BY (mu_)
 
std::map< intptr_t, std::shared_ptr< Task > > tasks_by_id_ ABSL_GUARDED_BY (mu_)
 
std::multimap< Time, std::shared_ptr< Task > > tasks_by_time_ ABSL_GUARDED_BY (mu_)
 
gpr_timespec NowAsTimespec (gpr_clock_type clock_type) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
 

Static Private Member Functions

static gpr_timespec GlobalNowImpl (gpr_clock_type clock_type) ABSL_LOCKS_EXCLUDED(mu_)
 

Private Attributes

const Duration final_tick_length_
 
grpc_core::Mutex mu_
 

Detailed Description

Definition at line 32 of file fuzzing_event_engine.h.

Member Typedef Documentation

◆ Time

Definition at line 72 of file fuzzing_event_engine.h.

Constructor & Destructor Documentation

◆ FuzzingEventEngine()

grpc_event_engine::experimental::FuzzingEventEngine::FuzzingEventEngine ( Options  options,
const fuzzing_event_engine::Actions &  actions 
)
explicit

Definition at line 36 of file fuzzing_event_engine.cc.

◆ ~FuzzingEventEngine()

grpc_event_engine::experimental::FuzzingEventEngine::~FuzzingEventEngine ( )
override

Definition at line 87 of file fuzzing_event_engine.cc.

Member Function Documentation

◆ ABSL_GUARDED_BY() [1/7]

intptr_t next_task_id_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [2/7]

intptr_t current_tick_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [3/7]

Time now_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [4/7]

std::map<intptr_t, Duration> tick_increments_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [5/7]

std::map<intptr_t, Duration> task_delays_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [6/7]

std::map<intptr_t, std::shared_ptr<Task> > tasks_by_id_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [7/7]

std::multimap<Time, std::shared_ptr<Task> > tasks_by_time_ grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY ( mu_  )
private

◆ Cancel()

bool grpc_event_engine::experimental::FuzzingEventEngine::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 192 of file fuzzing_event_engine.cc.

◆ CancelConnect()

bool grpc_event_engine::experimental::FuzzingEventEngine::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 153 of file fuzzing_event_engine.cc.

◆ Connect()

EventEngine::ConnectionHandle grpc_event_engine::experimental::FuzzingEventEngine::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 147 of file fuzzing_event_engine.cc.

◆ CreateListener()

absl::StatusOr< std::unique_ptr< EventEngine::Listener > > grpc_event_engine::experimental::FuzzingEventEngine::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 140 of file fuzzing_event_engine.cc.

◆ FuzzingDone()

void grpc_event_engine::experimental::FuzzingEventEngine::FuzzingDone ( )

Definition at line 82 of file fuzzing_event_engine.cc.

◆ GetDNSResolver()

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

Definition at line 157 of file fuzzing_event_engine.cc.

◆ GlobalNowImpl()

gpr_timespec grpc_event_engine::experimental::FuzzingEventEngine::GlobalNowImpl ( gpr_clock_type  clock_type)
staticprivate

Definition at line 101 of file fuzzing_event_engine.cc.

◆ IsWorkerThread()

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

◆ Now()

FuzzingEventEngine::Time grpc_event_engine::experimental::FuzzingEventEngine::Now ( )

Definition at line 134 of file fuzzing_event_engine.cc.

◆ NowAsTimespec()

gpr_timespec grpc_event_engine::experimental::FuzzingEventEngine::NowAsTimespec ( gpr_clock_type  clock_type)
private

Definition at line 92 of file fuzzing_event_engine.cc.

◆ Run() [1/2]

void grpc_event_engine::experimental::FuzzingEventEngine::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 162 of file fuzzing_event_engine.cc.

◆ Run() [2/2]

void grpc_event_engine::experimental::FuzzingEventEngine::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 166 of file fuzzing_event_engine.cc.

◆ RunAfter() [1/2]

EventEngine::TaskHandle grpc_event_engine::experimental::FuzzingEventEngine::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 170 of file fuzzing_event_engine.cc.

◆ RunAfter() [2/2]

EventEngine::TaskHandle grpc_event_engine::experimental::FuzzingEventEngine::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 175 of file fuzzing_event_engine.cc.

◆ Tick()

void grpc_event_engine::experimental::FuzzingEventEngine::Tick ( )

Definition at line 107 of file fuzzing_event_engine.cc.

Member Data Documentation

◆ final_tick_length_

const Duration grpc_event_engine::experimental::FuzzingEventEngine::final_tick_length_
private

Definition at line 89 of file fuzzing_event_engine.h.

◆ mu_

grpc_core::Mutex grpc_event_engine::experimental::FuzzingEventEngine::mu_
private

Definition at line 91 of file fuzzing_event_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