From 4899f78701054febc0a9fab2af754f2040373401 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 5 Feb 2022 12:28:30 +0000 Subject: [Fix] Rework unshedule DNS request function --- contrib/librdns/util.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'contrib/librdns') diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c index 900791b14..e09eb2007 100644 --- a/contrib/librdns/util.c +++ b/contrib/librdns/util.c @@ -635,8 +635,12 @@ rdns_request_retain (struct rdns_request *req) void rdns_request_unschedule (struct rdns_request *req, bool remove_from_hash) { - if (req->async_event) { - if (req->state == RDNS_REQUEST_WAIT_REPLY) { + struct rdns_resolver *resolver = req->resolver; + + switch (req->state) { + case RDNS_REQUEST_WAIT_REPLY: + /* We have a timer pending */ + if (req->async_event) { req->async->del_timer (req->async->data, req->async_event); if (remove_from_hash) { @@ -644,7 +648,10 @@ rdns_request_unschedule (struct rdns_request *req, bool remove_from_hash) } req->async_event = NULL; } - else if (req->state == RDNS_REQUEST_WAIT_SEND) { + break; + case RDNS_REQUEST_WAIT_SEND: + /* We have write request pending */ + if (req->async_event) { req->async->del_write (req->async->data, req->async_event); /* Remove from id hashes */ @@ -653,16 +660,26 @@ rdns_request_unschedule (struct rdns_request *req, bool remove_from_hash) } req->async_event = NULL; } - } - else if (req->state == RDNS_REQUEST_TCP) { - if (remove_from_hash) { - rdns_request_remove_from_hash(req); - } + break; + case RDNS_REQUEST_TCP: + /* We also have a timer */ + if (req->async_event) { + if (remove_from_hash) { + rdns_request_remove_from_hash(req); + } - req->async->del_timer(req->async->data, - req->async_event); + req->async->del_timer(req->async->data, + req->async_event); - req->async_event = NULL; + req->async_event = NULL; + } + default: + /* Nothing to unschedule, so blame if we have any event pending */ + if (req->async_event) { + rdns_err("internal error: have unexpected pending async state on stage %d", + req->state); + } + break; } } -- cgit v1.2.3