mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-06 02:52:22 +00:00
Previously, processing a large batch of timeouts was O(n^2) in the number of
outstanding queries, and processing a DNS response packet was O(n) in the number of outstanding queries. To speed things up in Google, we added a few circular, doubly-linked lists of queries that are hash-bucketed based on the attributes we care about, so most important operations are now O(1). It might be that the number of buckets are higher than most people would need, but on a quick calculation it should only be 100kB or so even on a 64-bit system, so I've let it stay as-is.
This commit is contained in:
14
ares_query.c
14
ares_query.c
@ -68,15 +68,19 @@ void ares__rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len)
|
||||
static struct query* find_query_by_id(ares_channel channel, int id)
|
||||
{
|
||||
unsigned short qid;
|
||||
struct query* q;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
DNS_HEADER_SET_QID(((unsigned char*)&qid), id);
|
||||
|
||||
/* Find the query corresponding to this packet. */
|
||||
for (q = channel->queries; q; q = q->next)
|
||||
{
|
||||
if (q->qid == qid)
|
||||
list_head = &(channel->queries_by_qid[qid % ARES_QID_TABLE_SIZE]);
|
||||
for (list_node = list_head->next; list_node != list_head;
|
||||
list_node = list_node->next)
|
||||
{
|
||||
struct query *q = list_node->data;
|
||||
if (q->qid == qid)
|
||||
return q;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user