Commit c108fc5c authored by Michał Kępień's avatar Michał Kępień
Browse files

Refactor code sending a query to the next server upon a timeout

When a query times out and another server is available for querying
within the same lookup, the timeout handler - connect_timeout() - is
responsible for sending the query to the next server.  Extract the
relevant part of connect_timeout() to a separate function in order to
improve code readability.
parent ef1da873
......@@ -2880,6 +2880,36 @@ send_udp(dig_query_t *query) {
sendcount++;
}
/*%
* If there are more servers available for querying within 'lookup', initiate a
* TCP or UDP query to the next available server and return true; otherwise,
* return false.
*/
static bool
try_next_server(dig_lookup_t *lookup) {
dig_query_t *current_query, *next_query;
current_query = lookup->current_query;
if (current_query == NULL || !ISC_LINK_LINKED(current_query, link)) {
return (false);
}
next_query = ISC_LIST_NEXT(current_query, link);
if (next_query == NULL) {
return (false);
}
debug("trying next server...");
if (lookup->tcp_mode) {
send_tcp_connect(next_query);
} else {
send_udp(next_query);
}
return (true);
}
/*%
* IO timeout handler, used for both connect and recv timeouts. If
* retries are still allowed, either resend the UDP packet or queue a
......@@ -2888,7 +2918,7 @@ send_udp(dig_query_t *query) {
static void
connect_timeout(isc_task_t *task, isc_event_t *event) {
dig_lookup_t *l = NULL;
dig_query_t *query = NULL, *cq;
dig_query_t *query = NULL;
UNUSED(task);
REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
......@@ -2908,18 +2938,12 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
return;
}
if ((query != NULL) && (query->lookup->current_query != NULL) &&
ISC_LINK_LINKED(query->lookup->current_query, link) &&
(ISC_LIST_NEXT(query->lookup->current_query, link) != NULL)) {
debug("trying next server...");
cq = query->lookup->current_query;
if (!l->tcp_mode)
send_udp(ISC_LIST_NEXT(cq, link));
else {
if (query->sock != NULL)
if (try_next_server(l)) {
if (l->tcp_mode) {
if (query->sock != NULL) {
isc_socket_cancel(query->sock, NULL,
ISC_SOCKCANCEL_ALL);
send_tcp_connect(ISC_LIST_NEXT(cq, link));
}
}
UNLOCK_LOOKUP;
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment