ares_cancel.c
Go to the documentation of this file.
1 
2 /* Copyright (C) 2004 by Daniel Stenberg et al
3  *
4  * Permission to use, copy, modify, and distribute this software and its
5  * documentation for any purpose and without fee is hereby granted, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission. M.I.T. makes no representations about the
11  * suitability of this software for any purpose. It is provided "as is"
12  * without express or implied warranty.
13  */
14 
15 #include "ares_setup.h"
16 #include <assert.h>
17 
18 #include "ares.h"
19 #include "ares_private.h"
20 
21 /*
22  * ares_cancel() cancels all ongoing requests/resolves that might be going on
23  * on the given channel. It does NOT kill the channel, use ares_destroy() for
24  * that.
25  */
27 {
28  struct query *query;
29  struct list_node list_head_copy;
30  struct list_node* list_head;
31  struct list_node* list_node;
32  int i;
33 
34  if (!ares__is_list_empty(&(channel->all_queries)))
35  {
36  /* Swap list heads, so that only those queries which were present on entry
37  * into this function are cancelled. New queries added by callbacks of
38  * queries being cancelled will not be cancelled themselves.
39  */
40  list_head = &(channel->all_queries);
41  list_head_copy.prev = list_head->prev;
42  list_head_copy.next = list_head->next;
43  list_head_copy.prev->next = &list_head_copy;
44  list_head_copy.next->prev = &list_head_copy;
45  list_head->prev = list_head;
46  list_head->next = list_head;
47  for (list_node = list_head_copy.next; list_node != &list_head_copy; )
48  {
49  query = list_node->data;
50  list_node = list_node->next; /* since we're deleting the query */
51  query->callback(query->arg, ARES_ECANCELLED, 0, NULL, 0);
53  }
54  }
55  if (!(channel->flags & ARES_FLAG_STAYOPEN) && ares__is_list_empty(&(channel->all_queries)))
56  {
57  if (channel->servers)
58  {
59  for (i = 0; i < channel->nservers; i++)
60  ares__close_sockets(channel, &channel->servers[i]);
61  }
62  }
63 }
ARES_ECANCELLED
#define ARES_ECANCELLED
Definition: ares.h:136
ares__close_sockets
void ares__close_sockets(ares_channel channel, struct server_state *server)
Definition: ares__close_sockets.c:22
ares.h
list_node::data
void * data
Definition: ares_llist.h:25
ares__is_list_empty
int ares__is_list_empty(struct list_node *head)
Definition: ares_llist.c:41
ares_cancel
void ares_cancel(ares_channel channel)
Definition: ares_cancel.c:26
query
Definition: ares_private.h:198
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
query::arg
void * arg
Definition: ares_private.h:222
ARES_FLAG_STAYOPEN
#define ARES_FLAG_STAYOPEN
Definition: ares.h:146
list_node::prev
struct list_node * prev
Definition: ares_llist.h:23
ares_setup.h
ares_channeldata
Definition: ares_private.h:266
ares__free_query
void ares__free_query(struct query *query)
Definition: ares_process.c:1500
list_node
Definition: ares_llist.h:22
ares_private.h
list_node::next
struct list_node * next
Definition: ares_llist.h:24
query::callback
ares_callback callback
Definition: ares_private.h:221
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43