Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 4de6721

Browse files
committed
quic: remove CleanupHook from Timer
This means that we always need to use `DeleteFnPtr` to make sure that the timer is actually cleaned up, but I guess that’s an acceptable restriction for now.
1 parent 134855f commit 4de6721

File tree

3 files changed

+97
-13
lines changed

3 files changed

+97
-13
lines changed

src/js_udp_wrap.cc

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "udp_wrap.h"
2+
3+
namespace node {
4+
5+
class JSUDPWrap final : public UDPWrapBase, public AsyncWrap {
6+
public:
7+
JSUDPWrap(Environment* env, Local<Object> obj);
8+
9+
static void New(const FunctionCallbackInfo<Value>& args);
10+
static void Receive(const FunctionCallbackInfo<Value>& args);
11+
static void CreateSendWrap(const FunctionCallbackInfo<Value>& args);
12+
static void SendDone(const FunctionCallbackInfo<Value>& args);
13+
static void AfterBind(const FunctionCallbackInfo<Value>& args);
14+
15+
int RecvStart() override;
16+
int RecvStop() override;
17+
ssize_t Send(uv_buf_t* bufs,
18+
size_t nbufs,
19+
const sockaddr* addr) override;
20+
int GetPeerName(sockaddr* name, int* namelen) override;
21+
int GetSockName(sockaddr* name, int* namelen) override;
22+
AsyncWrap* GetAsyncWrap() override;
23+
24+
static void Initialize(Local<Object> target,
25+
Local<Value> unused,
26+
Local<Context> context,
27+
void* priv);
28+
};
29+
30+
JSUDPWrap::JSUDPWrap(Environment* env, Local<Object> obj) {
31+
}
32+
33+
void JSUDPWrap::New(const FunctionCallbackInfo<Value>& args) {
34+
}
35+
36+
void JSUDPWrap::Receive(const FunctionCallbackInfo<Value>& args) {
37+
}
38+
39+
void JSUDPWrap::CreateSendWrap(const FunctionCallbackInfo<Value>& args) {
40+
}
41+
42+
void JSUDPWrap::SendDone(const FunctionCallbackInfo<Value>& args) {
43+
}
44+
45+
void JSUDPWrap::AfterBind(const FunctionCallbackInfo<Value>& args) {
46+
}
47+
48+
int JSUDPWrap::RecvStart() override {
49+
}
50+
51+
int JSUDPWrap::RecvStop() override {
52+
}
53+
54+
ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
55+
size_t nbufs,
56+
const sockaddr* addr) override {
57+
}
58+
59+
int JSUDPWrap::GetPeerName(sockaddr* name, int* namelen) override {
60+
}
61+
62+
int JSUDPWrap::GetSockName(sockaddr* name, int* namelen) override {
63+
}
64+
65+
AsyncWrap* JSUDPWrap::GetAsyncWrap() override {
66+
return this;
67+
}
68+
69+
void JSUDPWrap::Initialize(Local<Object> target,
70+
Local<Value> unused,
71+
Local<Context> context,
72+
void* priv) {
73+
Environment* env = Environment::GetCurrent(context);
74+
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
75+
t->InstanceTemplate()->SetInternalFieldCount(kUDPWrapBaseField + 1);
76+
Local<String> js_udp_string =
77+
FIXED_ONE_BYTE_STRING(env->isolate(), "JSUDPWrap");
78+
t->SetClassName(js_udp_string);
79+
80+
env->SetProtoMethod(t, "receive", Receive);
81+
env->SetProtoMethod(t, "createSendWrap", CreateSendWrap);
82+
env->SetProtoMethod(t, "sendDone", SendDone);
83+
env->SetProtoMethod(t, "afterBind", AfterBind);
84+
85+
t->Inherit(HandleWrap::GetConstructorTemplate(env));
86+
87+
target->Set(env->context(),
88+
js_udp_string,
89+
t->GetFunction(env->context()).ToLocalChecked()).Check();
90+
}
91+
92+
} // namespace node
93+
94+
NODE_MODULE_CONTEXT_AWARE_INTERNAL(js_udp_wrap, node::JSUDPWrap::Initialize)
95+

src/node_quic_util.cc

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ void Timer::OnTimeout(uv_timer_t* timer) {
2222
t->fn_();
2323
}
2424

25-
void Timer::CleanupHook(void* data) {
26-
Free(static_cast<Timer*>(data));
27-
}
28-
2925
ngtcp2_crypto_level from_ossl_level(OSSL_ENCRYPTION_LEVEL ossl_level) {
3026
switch (ossl_level) {
3127
case ssl_encryption_initial:

src/node_quic_util.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,10 @@ void IncrementStat(
379379
class Timer final : public MemoryRetainer {
380380
public:
381381
explicit Timer(Environment* env, std::function<void()> fn)
382-
: stopped_(false),
383-
env_(env),
382+
: env_(env),
384383
fn_(fn) {
385384
uv_timer_init(env_->event_loop(), &timer_);
386385
timer_.data = this;
387-
env->AddCleanupHook(CleanupHook, this);
388-
}
389-
390-
~Timer() override {
391-
env_->RemoveCleanupHook(CleanupHook, this);
392386
}
393387

394388
// Stops the timer with the side effect of the timer no longer being usable.
@@ -421,9 +415,8 @@ class Timer final : public MemoryRetainer {
421415

422416
private:
423417
static void OnTimeout(uv_timer_t* timer);
424-
static void CleanupHook(void* data);
425418

426-
bool stopped_;
419+
bool stopped_ = false;
427420
Environment* env_;
428421
std::function<void()> fn_;
429422
uv_timer_t timer_;

0 commit comments

Comments
 (0)