From 9b583d2331e00c88017e683c1cd2598135c03a15 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 9 Jul 2020 13:58:44 +0200 Subject: [PATCH] stream reuse, the id for pending stored in waiting_tcp structure, because there can be multiple messages waiting for reply. --- services/outside_network.c | 15 +++++---------- services/outside_network.h | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/services/outside_network.c b/services/outside_network.c index 5082f5f03..07454d324 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -172,11 +172,9 @@ int reuse_id_cmp(const void* key1, const void* key2) { struct waiting_tcp* w1 = (struct waiting_tcp*)key1; struct waiting_tcp* w2 = (struct waiting_tcp*)key2; - struct pending_tcp* p1 = (struct pending_tcp*)w1->next_waiting; - struct pending_tcp* p2 = (struct pending_tcp*)w2->next_waiting; - if(p1->id < p2->id) + if(w1->id < w2->id) return -1; - if(p1->id > p2->id) + if(w1->id > w2->id) return 1; return 0; } @@ -420,12 +418,9 @@ static struct waiting_tcp* reuse_tcp_by_id_find(struct reuse_tcp* reuse, uint16_t id) { struct waiting_tcp key_w; - struct pending_tcp key_p; memset(&key_w, 0, sizeof(key_w)); - memset(&key_p, 0, sizeof(key_p)); - key_w.next_waiting = (void*)&key_p; key_w.id_node.key = &key_w; - key_p.id = id; + key_w.id = id; return (struct waiting_tcp*)rbtree_search(&reuse->tree_by_id, &key_w); } @@ -434,7 +429,7 @@ static uint16_t tree_by_id_get_id(rbnode_type* node) { struct waiting_tcp* w = (struct waiting_tcp*)node->key; - return ((struct pending_tcp*)w->next_waiting)->id; + return w->id; } /** find reuse tcp stream to destination for query, or NULL if none */ @@ -509,7 +504,7 @@ outnet_tcp_take_query_setup(int s, struct pending_tcp* pend, struct waiting_tcp* w) { struct timeval tv; - pend->id = LDNS_ID_WIRE(w->pkt); + w->id = LDNS_ID_WIRE(w->pkt); pend->c->tcp_write_pkt = w->pkt; pend->c->tcp_write_pkt_len = w->pkt_len; pend->c->tcp_write_and_read = 1; diff --git a/services/outside_network.h b/services/outside_network.h index 0dcf1b2e1..9ebbabe9c 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -324,8 +324,6 @@ struct pending { struct pending_tcp { /** next in list of free tcp comm points, or NULL. */ struct pending_tcp* next_free; - /** the ID for the query; checked in reply */ - uint16_t id; /** tcp comm point it was sent on (and reply must come back on). */ struct comm_point* c; /** the query being serviced, NULL if the pending_tcp is unused. */ @@ -355,8 +353,10 @@ struct waiting_tcp { /** true if the waiting_tcp structure is on the write_wait queue */ int write_wait_queued; /** entry in reuse.tree_by_id, if key is NULL, not in tree, otherwise, - * this struct is key and sorted by ID from pending_tcp->id. */ + * this struct is key and sorted by ID (from waiting_tcp.id). */ rbnode_type id_node; + /** the ID for the query; checked in reply */ + uint16_t id; /** timeout event; timer keeps running whether the query is * waiting for a buffer or the tcp reply is pending */ struct comm_timer* timer; -- 2.47.3