GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: do not persist timer handle in cares_wrap · nodejs/node@685b9b2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • cares_wrap.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/cares_wrap.cc‎

Copy file name to clipboardExpand all lines: src/cares_wrap.cc
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ class ChannelWrap : public AsyncWrap {
151151

152152
void Setup();
153153
void EnsureServers();
154-
void CleanupTimer();
154+
void StartTimer();
155+
void CloseTimer();
155156

156157
void ModifyActivityQueryCount(int count);
157158

@@ -313,13 +314,7 @@ void ares_sockstate_cb(void* data,
313314
if (read || write) {
314315
if (!task) {
315316
/* New socket */
316-
317-
/* If this is the first socket then start the timer. */
318-
uv_timer_t* timer_handle = channel->timer_handle();
319-
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(timer_handle))) {
320-
CHECK(channel->task_list()->empty());
321-
uv_timer_start(timer_handle, ChannelWrap::AresTimeout, 1000, 1000);
322-
}
317+
channel->StartTimer();
323318

324319
task = ares_task_create(channel, sock);
325320
if (task == nullptr) {
@@ -349,7 +344,7 @@ void ares_sockstate_cb(void* data,
349344
channel->env()->CloseHandle(&task->poll_watcher, ares_poll_close_cb);
350345

351346
if (channel->task_list()->empty()) {
352-
uv_timer_stop(channel->timer_handle());
347+
channel->CloseTimer();
353348
}
354349
}
355350
}
@@ -490,15 +485,26 @@ void ChannelWrap::Setup() {
490485
}
491486

492487
library_inited_ = true;
488+
}
493489

494-
/* Initialize the timeout timer. The timer won't be started until the */
495-
/* first socket is opened. */
496-
CleanupTimer();
497-
timer_handle_ = new uv_timer_t();
498-
timer_handle_->data = static_cast<void*>(this);
499-
uv_timer_init(env()->event_loop(), timer_handle_);
490+
void ChannelWrap::StartTimer() {
491+
if (timer_handle_ == nullptr) {
492+
timer_handle_ = new uv_timer_t();
493+
timer_handle_->data = static_cast<void*>(this);
494+
uv_timer_init(env()->event_loop(), timer_handle_);
495+
} else if (uv_is_active(reinterpret_cast<uv_handle_t*>(timer_handle_))) {
496+
return;
497+
}
498+
uv_timer_start(timer_handle_, AresTimeout, 1000, 1000);
500499
}
501500

501+
void ChannelWrap::CloseTimer() {
502+
if (timer_handle_ == nullptr)
503+
return;
504+
505+
env()->CloseHandle(timer_handle_, [](uv_timer_t* handle) { delete handle; });
506+
timer_handle_ = nullptr;
507+
}
502508

503509
ChannelWrap::~ChannelWrap() {
504510
if (library_inited_) {
@@ -508,17 +514,10 @@ ChannelWrap::~ChannelWrap() {
508514
}
509515

510516
ares_destroy(channel_);
511-
CleanupTimer();
517+
CloseTimer();
512518
}
513519

514520

515-
void ChannelWrap::CleanupTimer() {
516-
if (timer_handle_ == nullptr) return;
517-
518-
env()->CloseHandle(timer_handle_, [](uv_timer_t* handle) { delete handle; });
519-
timer_handle_ = nullptr;
520-
}
521-
522521
void ChannelWrap::ModifyActivityQueryCount(int count) {
523522
active_query_count_ += count;
524523
if (active_query_count_ < 0) active_query_count_ = 0;
@@ -566,6 +565,7 @@ void ChannelWrap::EnsureServers() {
566565
/* destroy channel and reset channel */
567566
ares_destroy(channel_);
568567

568+
CloseTimer();
569569
Setup();
570570
}
571571

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.