28
28
#include "ares_private.h"
29
29
#include <assert.h>
30
30
31
- static void ares__requeue_queries (struct server_connection * conn )
31
+ static void ares__requeue_queries (struct server_connection * conn ,
32
+ ares_status_t requeue_status )
32
33
{
33
34
struct query * query ;
34
35
ares_timeval_t now ;
35
36
36
37
ares__tvnow (& now );
37
38
38
39
while ((query = ares__llist_first_val (conn -> queries_to_conn )) != NULL ) {
39
- ares__requeue_query (query , & now );
40
+ ares__requeue_query (query , & now , requeue_status );
40
41
}
41
42
}
42
43
43
- void ares__close_connection (struct server_connection * conn )
44
+ void ares__close_connection (struct server_connection * conn ,
45
+ ares_status_t requeue_status )
44
46
{
45
47
struct server_state * server = conn -> server ;
46
48
ares_channel_t * channel = server -> channel ;
@@ -58,7 +60,7 @@ void ares__close_connection(struct server_connection *conn)
58
60
}
59
61
60
62
/* Requeue queries to other connections */
61
- ares__requeue_queries (conn );
63
+ ares__requeue_queries (conn , requeue_status );
62
64
63
65
ares__llist_destroy (conn -> queries_to_conn );
64
66
@@ -74,45 +76,63 @@ void ares__close_sockets(struct server_state *server)
74
76
75
77
while ((node = ares__llist_node_first (server -> connections )) != NULL ) {
76
78
struct server_connection * conn = ares__llist_node_val (node );
77
- ares__close_connection (conn );
79
+ ares__close_connection (conn , ARES_SUCCESS );
78
80
}
79
81
}
80
82
81
- void ares__check_cleanup_conn (const ares_channel_t * channel ,
82
- struct server_connection * conn )
83
+ void ares__check_cleanup_conns (const ares_channel_t * channel )
83
84
{
84
- ares_bool_t do_cleanup = ARES_FALSE ;
85
+ ares__slist_node_t * snode ;
85
86
86
- if (channel == NULL || conn == NULL ) {
87
+ if (channel == NULL ) {
87
88
return ; /* LCOV_EXCL_LINE: DefensiveCoding */
88
89
}
89
90
90
- if (ares__llist_len (conn -> queries_to_conn )) {
91
- return ;
91
+ /* Iterate across each server */
92
+ for (snode = ares__slist_node_first (channel -> servers ); snode != NULL ;
93
+ snode = ares__slist_node_next (snode )) {
94
+
95
+ struct server_state * server = ares__slist_node_val (snode );
96
+ ares__llist_node_t * cnode ;
97
+
98
+ /* Iterate across each connection */
99
+ cnode = ares__llist_node_first (server -> connections );
100
+ while (cnode != NULL ) {
101
+ ares__llist_node_t * next = ares__llist_node_next (cnode );
102
+ struct server_connection * conn = ares__llist_node_val (cnode );
103
+ ares_bool_t do_cleanup = ARES_FALSE ;
104
+ cnode = next ;
105
+
106
+ /* Has connections, not eligible */
107
+ if (ares__llist_len (conn -> queries_to_conn )) {
108
+ continue ;
109
+ }
110
+
111
+ /* If we are configured not to stay open, close it out */
112
+ if (!(channel -> flags & ARES_FLAG_STAYOPEN )) {
113
+ do_cleanup = ARES_TRUE ;
114
+ }
115
+
116
+ /* If the associated server has failures, close it out. Resetting the
117
+ * connection (and specifically the source port number) can help resolve
118
+ * situations where packets are being dropped.
119
+ */
120
+ if (conn -> server -> consec_failures > 0 ) {
121
+ do_cleanup = ARES_TRUE ;
122
+ }
123
+
124
+ /* If the udp connection hit its max queries, always close it */
125
+ if (!conn -> is_tcp && channel -> udp_max_queries > 0 &&
126
+ conn -> total_queries >= channel -> udp_max_queries ) {
127
+ do_cleanup = ARES_TRUE ;
128
+ }
129
+
130
+ if (!do_cleanup ) {
131
+ continue ;
132
+ }
133
+
134
+ /* Clean it up */
135
+ ares__close_connection (conn , ARES_SUCCESS );
136
+ }
92
137
}
93
-
94
- /* If we are configured not to stay open, close it out */
95
- if (!(channel -> flags & ARES_FLAG_STAYOPEN )) {
96
- do_cleanup = ARES_TRUE ;
97
- }
98
-
99
- /* If the associated server has failures, close it out. Resetting the
100
- * connection (and specifically the source port number) can help resolve
101
- * situations where packets are being dropped.
102
- */
103
- if (conn -> server -> consec_failures > 0 ) {
104
- do_cleanup = ARES_TRUE ;
105
- }
106
-
107
- /* If the udp connection hit its max queries, always close it */
108
- if (!conn -> is_tcp && channel -> udp_max_queries > 0 &&
109
- conn -> total_queries >= channel -> udp_max_queries ) {
110
- do_cleanup = ARES_TRUE ;
111
- }
112
-
113
- if (!do_cleanup ) {
114
- return ;
115
- }
116
-
117
- ares__close_connection (conn );
118
138
}
0 commit comments