@ -22,24 +22,30 @@
# include <algorithm>
# include <algorithm>
# include <functional>
# include <functional>
# include <memory>
# include <string>
# include <string>
# include "absl/status/status.h"
# include "absl/status/status.h"
# include "absl/strings/str_format.h"
# include "absl/strings/str_format.h"
# include "absl/strings/string_view.h"
# include "absl/strings/string_view.h"
# include "absl/types/optional.h"
# include <grpc/event_engine/event_engine.h>
# include <grpc/slice.h>
# include <grpc/slice.h>
# include <grpc/slice_buffer.h>
# include <grpc/slice_buffer.h>
# include <grpc/support/alloc.h>
# include <grpc/support/alloc.h>
# include <grpc/support/log.h>
# include <grpc/support/log.h>
# include "src/core/lib/event_engine/default_event_engine.h"
# include "src/core/lib/gprpp/debug_location.h"
# include "src/core/lib/gprpp/debug_location.h"
# include "src/core/lib/gprpp/time.h"
# include "src/core/lib/gprpp/time.h"
# include "src/core/lib/iomgr/closure.h"
# include "src/core/lib/iomgr/closure.h"
# include "src/core/lib/iomgr/error.h"
# include "src/core/lib/iomgr/error.h"
# include "src/core/lib/iomgr/exec_ctx.h"
# include "src/core/lib/iomgr/exec_ctx.h"
# include "src/core/lib/iomgr/iomgr_fwd.h"
# include "src/core/lib/iomgr/iomgr_fwd.h"
# include "src/core/lib/iomgr/timer.h"
using : : grpc_event_engine : : experimental : : EventEngine ;
using : : grpc_event_engine : : experimental : : GetDefaultEventEngine ;
typedef struct passthru_endpoint passthru_endpoint ;
typedef struct passthru_endpoint passthru_endpoint ;
@ -51,7 +57,7 @@ typedef struct {
} pending_op ;
} pending_op ;
typedef struct {
typedef struct {
grpc_timer timer ;
absl : : optional < EventEngine : : TaskHandle > timer_handle ;
uint64_t allowed_write_bytes ;
uint64_t allowed_write_bytes ;
uint64_t allowed_read_bytes ;
uint64_t allowed_read_bytes ;
std : : vector < grpc_passthru_endpoint_channel_action > actions ;
std : : vector < grpc_passthru_endpoint_channel_action > actions ;
@ -348,6 +354,8 @@ void grpc_passthru_endpoint_destroy(passthru_endpoint* p) {
gpr_free ( p ) ;
gpr_free ( p ) ;
}
}
static void do_next_sched_channel_action ( void * arg , grpc_error_handle error ) ;
static void me_destroy ( grpc_endpoint * ep ) {
static void me_destroy ( grpc_endpoint * ep ) {
passthru_endpoint * p = ( reinterpret_cast < half * > ( ep ) ) - > parent ;
passthru_endpoint * p = ( reinterpret_cast < half * > ( ep ) ) - > parent ;
gpr_mu_lock ( & p - > mu ) ;
gpr_mu_lock ( & p - > mu ) ;
@ -357,7 +365,16 @@ static void me_destroy(grpc_endpoint* ep) {
grpc_passthru_endpoint_destroy ( p ) ;
grpc_passthru_endpoint_destroy ( p ) ;
} else {
} else {
if ( p - > halves = = 0 & & p - > simulate_channel_actions ) {
if ( p - > halves = = 0 & & p - > simulate_channel_actions ) {
grpc_timer_cancel ( & p - > channel_effects - > timer ) ;
if ( p - > channel_effects - > timer_handle . has_value ( ) ) {
if ( GetDefaultEventEngine ( ) - > Cancel (
* p - > channel_effects - > timer_handle ) ) {
gpr_mu_unlock ( & p - > mu ) ;
// This will destroy the passthru endpoint so just return after that.
do_next_sched_channel_action ( ep , absl : : CancelledError ( ) ) ;
return ;
}
p - > channel_effects - > timer_handle . reset ( ) ;
}
}
}
gpr_mu_unlock ( & p - > mu ) ;
gpr_mu_unlock ( & p - > mu ) ;
}
}
@ -483,12 +500,14 @@ static void sched_next_channel_action_locked(half* m) {
shutdown_locked ( m , err ) ;
shutdown_locked ( m , err ) ;
return ;
return ;
}
}
grpc_timer_init ( & m - > parent - > channel_effects - > timer ,
m - > parent - > channel_effects - > timer_handle = GetDefaultEventEngine ( ) - > RunAfter (
grpc_core : : Duration : : Milliseconds (
grpc_core : : Duration : : Milliseconds (
m - > parent - > channel_effects - > actions [ 0 ] . wait_ms ) +
m - > parent - > channel_effects - > actions [ 0 ] . wait_ms ) ,
grpc_core : : Timestamp : : Now ( ) ,
[ m ] {
GRPC_CLOSURE_CREATE ( do_next_sched_channel_action , m ,
grpc_core : : ApplicationCallbackExecCtx callback_exec_ctx ;
grpc_schedule_on_exec_ctx ) ) ;
grpc_core : : ExecCtx exec_ctx ;
do_next_sched_channel_action ( m , absl : : OkStatus ( ) ) ;
} ) ;
}
}
void start_scheduling_grpc_passthru_endpoint_channel_effects (
void start_scheduling_grpc_passthru_endpoint_channel_effects (