Skip to content

Commit

Permalink
Use uv_check_t to roll the connection establishment instead of using …
Browse files Browse the repository at this point in the history
…uv_prepare_t
  • Loading branch information
stiartsly authored and kuit committed Oct 8, 2023
1 parent b5d0cb0 commit eee3b68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/addons/activeproxy/activeproxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void ActiveProxy::onStop() noexcept
log->info("Addon ActiveProxy is on-stopping...");
running = false;

uv_prepare_stop(&prepareHandle);
uv_check_stop(&checkHandle);
uv_timer_stop(&timerHandle);
uv_close((uv_handle_t*)&prepareHandle, nullptr);
uv_close((uv_handle_t*)&checkHandle, nullptr);
uv_close((uv_handle_t*)&timerHandle, nullptr);
uv_close((uv_handle_t*)&stopHandle, nullptr);

Expand Down Expand Up @@ -282,15 +282,15 @@ void ActiveProxy::start()
stopHandle.data = this;

// init the idle/iteration handle
uv_prepare_init(&loop, &prepareHandle); // always success
prepareHandle.data = this;
rc = uv_prepare_start(&prepareHandle, [](uv_prepare_t* handle) {
uv_check_init(&loop, &checkHandle); // always success
checkHandle.data = this;
rc = uv_check_start(&checkHandle, [](uv_check_t* handle) {
ActiveProxy* ap = (ActiveProxy*)handle->data;
ap->onIteration();
});
if (rc < 0) {
log->error("Addon ActiveProxy failed to start the iteration handle({}): {}", rc, uv_strerror(rc));
uv_close((uv_handle_t*)&prepareHandle, nullptr);
uv_close((uv_handle_t*)&checkHandle, nullptr);
uv_close((uv_handle_t*)&stopHandle, nullptr);
uv_loop_close(&loop);
throw networking_error(uv_strerror(rc));
Expand All @@ -308,8 +308,8 @@ void ActiveProxy::start()
}, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_INTERVAL);
if (rc < 0) {
log->error("Addon ActiveProxy failed to start timer ({}): {}", rc, uv_strerror(rc));
uv_prepare_stop(&prepareHandle);
uv_close((uv_handle_t*)&prepareHandle, nullptr);
uv_check_stop(&checkHandle);
uv_close((uv_handle_t*)&checkHandle, nullptr);
uv_close((uv_handle_t*)&stopHandle, nullptr);
uv_loop_close(&loop);
throw networking_error(uv_strerror(rc));
Expand All @@ -324,9 +324,9 @@ void ActiveProxy::start()
if (rc < 0) {
log->error("Addon ActiveProxy failed to start the event loop({}): {}", rc, uv_strerror(rc));
running = false;
uv_prepare_stop(&prepareHandle);
uv_check_stop(&checkHandle);
uv_timer_stop(&timerHandle);
uv_close((uv_handle_t*)&prepareHandle, nullptr);
uv_close((uv_handle_t*)&checkHandle, nullptr);
uv_close((uv_handle_t*)&timerHandle, nullptr);
uv_close((uv_handle_t*)&stopHandle, nullptr);
uv_loop_close(&loop);
Expand Down
2 changes: 1 addition & 1 deletion src/addons/activeproxy/activeproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class ActiveProxy : public Addon {

uv_loop_t loop { 0 };
uv_async_t stopHandle { 0 };
uv_prepare_t prepareHandle { 0 };
uv_check_t checkHandle { 0 };
uv_timer_t timerHandle { 0 };

uint64_t lastConnectTimestamp { 0 };
Expand Down

0 comments on commit eee3b68

Please sign in to comment.