Lines Matching refs:query

90 static void skip_server(ares_channel channel, struct query *query,
92 static void next_server(ares_channel channel, struct query *query,
99 static void end_query(ares_channel channel, struct query *query, int status,
506 struct query *query;
521 query = list_node->data;
522 list_node = list_node->next; /* in case the query gets deleted */
523 if (query->timeout.tv_sec && ares__timedout(now, &query->timeout))
525 query->error_status = ARES_ETIMEOUT;
526 ++query->timeouts;
527 next_server(channel, query, now);
541 struct query *query;
550 /* Grab the query ID, truncate bit, and response code from the packet. */
555 /* Find the query corresponding to this packet. The queries are
556 * hashed/bucketed by query id, so this lookup should be quick.
557 * Note that both the query id and the questions must be the same;
558 * when the query id wraps around we can have multiple outstanding
559 * queries with the same query id, so we need to check both the id and
562 query = NULL;
567 struct query *q = list_node->data;
570 query = q;
574 if (!query)
578 * don't accept the packet, and switch the query to TCP if we hadn't
583 if (!query->using_tcp)
585 query->using_tcp = 1;
586 ares__send_query(channel, query, now);
604 skip_server(channel, query, whichserver);
605 if (query->server == whichserver)
606 next_server(channel, query, now);
611 end_query(channel, query, ARES_SUCCESS, abuf, alen);
633 struct query *query;
653 query = list_node->data;
654 list_node = list_node->next; /* in case the query gets deleted */
655 assert(query->server == whichserver);
656 skip_server(channel, query, whichserver);
657 next_server(channel, query, now);
659 /* Each query should have removed itself from our temporary list as
665 static void skip_server(ares_channel channel, struct query *query,
667 /* The given server gave us problems with this query, so if we have
677 query->server_info[whichserver].skip_server = 1;
681 static void next_server(ares_channel channel, struct query *query,
686 * attempts. Use query->try to remember how many times we already attempted
687 * this query. Use modular arithmetic to find the next server to try. */
688 while (++(query->try_count) < (channel->nservers * channel->tries))
693 query->server = (query->server + 1) % channel->nservers;
694 server = &channel->servers[query->server];
699 * errors we encountered, or (3) we already sent this query
703 !query->server_info[query->server].skip_server &&
704 !(query->using_tcp &&
705 (query->server_info[query->server].tcp_connection_generation ==
708 ares__send_query(channel, query, now);
720 /* If we are here, all attempts to perform query failed. */
721 end_query(channel, query, query->error_status, NULL, 0);
724 void ares__send_query(ares_channel channel, struct query *query,
731 server = &channel->servers[query->server];
732 if (query->using_tcp)
741 skip_server(channel, query, query->server);
742 next_server(channel, query, now);
749 end_query(channel, query, ARES_ENOMEM, NULL, 0);
753 * query's tcpbuf for as long as the query is alive. In the rare
754 * case where the query ends while it's queued for transmission,
759 sendreq->data = query->tcpbuf;
760 sendreq->len = query->tcplen;
761 sendreq->owner_query = query;
771 query->server_info[query->server].tcp_connection_generation =
780 skip_server(channel, query, query->server);
781 next_server(channel, query, now);
785 if (swrite(server->udp_socket, query->qbuf, query->qlen) == -1)
788 skip_server(channel, query, query->server);
789 next_server(channel, query, now);
793 timeplus = channel->timeout << (query->try_count / channel->nservers);
795 query->timeout = *now;
796 ares__timeadd(&query->timeout,
801 ares__remove_from_list(&(query->queries_by_timeout));
803 &(query->queries_by_timeout),
804 &(channel->queries_by_timeout[query->timeout.tv_sec %
810 ares__remove_from_list(&(query->queries_to_server));
811 ares__insert_in_list(&(query->queries_to_server),
1126 /* Decode the question in the query. */
1207 static void end_query (ares_channel channel, struct query *query, int status,
1212 /* First we check to see if this query ended while one of our send
1220 if (sendreq->owner_query == query)
1226 /* We got a reply for this query, but this queued
1227 * sendreq points into this soon-to-be-gone query's
1229 * the query for retransmission, then received a
1233 * we may have sent only some prefix of the query,
1234 * with some suffix of the query left to send. Also,
1236 * prevent dangling pointers to the query's tcpbuf and
1238 * their own copy of the query packet.
1267 query->callback(query->arg, status, query->timeouts, abuf, alen);
1268 ares__free_query(query);
1281 void ares__free_query(struct query *query)
1283 /* Remove the query from all the lists in which it is linked */
1284 ares__remove_from_list(&(query->queries_by_qid));
1285 ares__remove_from_list(&(query->queries_by_timeout));
1286 ares__remove_from_list(&(query->queries_to_server));
1287 ares__remove_from_list(&(query->all_queries));
1289 query->callback = NULL;
1290 query->arg = NULL;
1291 /* Deallocate the memory associated with the query */
1292 free(query->tcpbuf);
1293 free(query->server_info);
1294 free(query);