Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.
10 changes: 0 additions & 10 deletions src/node_quic_session-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,6 @@ inline int Empty(const ngtcp2_vec* vec, size_t cnt) {
return i == cnt;
}

inline void QuicSession::OnIdleTimeoutCB(void* data) {
QuicSession* session = static_cast<QuicSession*>(data);
session->OnIdleTimeout();
}

inline void QuicSession::OnRetransmitTimeoutCB(void* data) {
QuicSession* session = static_cast<QuicSession*>(data);
session->MaybeTimeout();
}

} // namespace quic
} // namespace node

Expand Down
4 changes: 2 additions & 2 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ QuicSession::QuicSession(
alpn_(alpn),
options_(options),
initial_connection_close_(initial_connection_close),
idle_(new Timer(socket->env(), OnIdleTimeoutCB, this)),
retransmit_(new Timer(socket->env(), OnRetransmitTimeoutCB, this)),
idle_(new Timer(socket->env(), [this]() { OnIdleTimeout(); })),
retransmit_(new Timer(socket->env(), [this]() { MaybeTimeout(); })),
state_(env()->isolate(), IDX_QUIC_SESSION_STATE_COUNT),
allocator_(this),
crypto_rx_ack_(
Expand Down
3 changes: 0 additions & 3 deletions src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,6 @@ class QuicSession : public AsyncWrap,
const ngtcp2_pkt_stateless_reset* sr,
void* user_data);

static inline void OnIdleTimeoutCB(void* data);
static inline void OnRetransmitTimeoutCB(void* data);

void UpdateIdleTimer();
void UpdateRetransmitTimer(uint64_t timeout);
void StopRetransmitTimer();
Expand Down
2 changes: 1 addition & 1 deletion src/node_quic_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Timer::Free(Timer* timer) {

void Timer::OnTimeout(uv_timer_t* timer) {
Timer* t = ContainerOf(&Timer::timer_, timer);
t->OnTimeout();
t->fn_();
}

void Timer::CleanupHook(void* data) {
Expand Down
20 changes: 6 additions & 14 deletions src/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,10 @@ void IncrementStat(
// reset the timer; Stop to halt the timer.
class Timer {
public:
inline explicit Timer(
Environment* env,
std::function<void(void* data)> fn,
void* data = nullptr) :
stopped_(false),
explicit Timer(Environment* env, std::function<void()> fn)
: stopped_(false),
env_(env),
fn_(fn),
data_(data) {
fn_(fn) {
uv_timer_init(env_->event_loop(), &timer_);
timer_.data = this;
env->AddCleanupHook(CleanupHook, this);
Expand All @@ -412,7 +408,7 @@ class Timer {

// Stops the timer with the side effect of the timer no longer being usable.
// It will be cleaned up and the Timer object will be destroyed.
inline void Stop() {
void Stop() {
if (stopped_)
return;
stopped_ = true;
Expand All @@ -425,7 +421,7 @@ class Timer {

// If the timer is not currently active, interval must be either 0 or greater.
// If the timer is already active, interval is ignored.
inline void Update(uint64_t interval) {
void Update(uint64_t interval) {
if (stopped_)
return;
uv_timer_start(&timer_, OnTimeout, interval, interval);
Expand All @@ -435,16 +431,12 @@ class Timer {
static void Free(Timer* timer);

private:
inline void OnTimeout() {
fn_(data_);
}

static void OnTimeout(uv_timer_t* timer);
static void CleanupHook(void* data);

bool stopped_;
Environment* env_;
std::function<void(void* data)> fn_;
std::function<void()> fn_;
uv_timer_t timer_;
void* data_;
Comment thread
addaleax marked this conversation as resolved.
Outdated
};
Expand Down