Lines Matching refs:query
70 static void end_query(ares_channel_t *channel, struct query *query,
551 struct query *query = ares__slist_node_val(node);
555 /* Since this is sorted, as soon as we hit a query that isn't timed out,
557 if (!ares__timedout(now, &query->timeout)) {
561 query->error_status = ARES_ETIMEOUT;
562 query->timeouts++;
564 conn = query->conn;
566 ares__requeue_query(query, now);
574 struct query *query)
605 ares_free(query->qbuf);
606 query->qbuf = msg;
607 query->qlen = msglen;
621 struct query *query;
637 /* Find the query corresponding to this packet. The queries are
638 * hashed/bucketed by query id, so this lookup should be quick.
640 query = ares__htable_szvp_get_direct(channel->queries_by_qid,
642 if (!query) {
643 /* We may have stopped listening for this query, that's ok */
649 status = ares_dns_parse(query->qbuf, query->qlen, 0, &qdnsrec);
651 end_query(channel, query, status, NULL, 0);
655 /* Both the query id and the questions must be the same. We will drop any
656 * replies that aren't for the same query as this is considered invalid. */
663 /* At this point we know we've received an answer for this query, so we should
667 ares__llist_node_destroy(query->node_queries_to_conn);
668 query->node_queries_to_conn = NULL;
672 * query without EDNS enabled. */
675 status = rewrite_without_edns(qdnsrec, query);
677 end_query(channel, query, status, NULL, 0);
681 ares__send_query(query, now);
687 * don't accept the packet, and switch the query to TCP if we hadn't
692 query->using_tcp = ARES_TRUE;
693 ares__send_query(query, now);
707 query->error_status = ARES_ESERVFAIL;
710 query->error_status = ARES_ENOTIMP;
713 query->error_status = ARES_EREFUSED;
720 ares__requeue_query(query, now);
731 if (ares_qcache_insert(channel, now, query, rdnsrec) == ARES_SUCCESS) {
736 end_query(channel, query, ARES_SUCCESS, abuf, alen);
761 ares_status_t ares__requeue_query(struct query *query, struct timeval *now)
763 ares_channel_t *channel = query->channel;
766 query->try_count++;
768 if (query->try_count < max_tries && !query->no_retries) {
769 return ares__send_query(query, now);
772 /* If we are here, all attempts to perform query failed. */
773 if (query->error_status == ARES_SUCCESS) {
774 query->error_status = ARES_ETIMEOUT;
777 end_query(channel, query, query->error_status, NULL, 0);
816 const struct query *query)
820 status = ares__buf_append_be16(server->tcp_send, (unsigned short)query->qlen);
824 return ares__buf_append(server->tcp_send, query->qbuf, query->qlen);
827 static size_t ares__calc_query_timeout(const struct query *query)
829 const ares_channel_t *channel = query->channel;
840 rounds = (query->try_count / num_servers);
876 ares_status_t ares__send_query(struct query *query, struct timeval *now)
878 ares_channel_t *channel = query->channel;
885 query->conn = NULL;
887 /* Choose the server to send the query to */
896 end_query(channel, query, ARES_ENOSERVER /* ? */, NULL, 0);
900 if (query->using_tcp) {
918 query->error_status = status;
919 return ares__requeue_query(query, now);
923 end_query(channel, query, status, NULL, 0);
932 status = ares__append_tcpbuf(server, query);
934 end_query(channel, query, status, NULL, 0);
977 query->error_status = status;
978 return ares__requeue_query(query, now);
982 end_query(channel, query, status, NULL, 0);
989 if (ares__socket_write(channel, conn->fd, query->qbuf, query->qlen) == -1) {
992 status = ares__requeue_query(query, now);
1004 timeplus = ares__calc_query_timeout(query);
1008 ares__slist_node_destroy(query->node_queries_by_timeout);
1009 query->timeout = *now;
1010 timeadd(&query->timeout, timeplus);
1011 query->node_queries_by_timeout =
1012 ares__slist_insert(channel->queries_by_timeout, query);
1013 if (!query->node_queries_by_timeout) {
1014 end_query(channel, query, ARES_ENOMEM, NULL, 0);
1025 ares__llist_node_destroy(query->node_queries_to_conn);
1026 query->node_queries_to_conn =
1027 ares__llist_insert_last(conn->queries_to_conn, query);
1029 if (query->node_queries_to_conn == NULL) {
1030 end_query(channel, query, ARES_ENOMEM, NULL, 0);
1039 query->conn = conn;
1114 static void ares_detach_query(struct query *query)
1116 /* Remove the query from all the lists in which it is linked */
1117 ares__htable_szvp_remove(query->channel->queries_by_qid, query->qid);
1118 ares__slist_node_destroy(query->node_queries_by_timeout);
1119 ares__llist_node_destroy(query->node_queries_to_conn);
1120 ares__llist_node_destroy(query->node_all_queries);
1121 query->node_queries_by_timeout = NULL;
1122 query->node_queries_to_conn = NULL;
1123 query->node_all_queries = NULL;
1126 static void end_query(ares_channel_t *channel, struct query *query,
1131 query->callback(query->arg, (int)status, (int)query->timeouts,
1135 ares__free_query(query);
1138 * must come after the callback and freeing the query for 2 reasons.
1139 * 1) The callback itself may enqueue a new query
1140 * 2) Technically the current query isn't detached until it is free()'d.
1145 void ares__free_query(struct query *query)
1147 ares_detach_query(query);
1149 query->callback = NULL;
1150 query->arg = NULL;
1151 /* Deallocate the memory associated with the query */
1152 ares_free(query->qbuf);
1154 ares_free(query);