2 /* Copyright 1998 by the Massachusetts Institute of Technology.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of M.I.T. not be used in
10 * advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission.
12 * M.I.T. makes no representations about the suitability of
13 * this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
17 #include "ares_setup.h"
20 #include "ares_private.h"
22 void ares__close_sockets(ares_channel channel
, struct server_state
*server
)
24 struct send_request
*sendreq
;
26 /* Free all pending output buffers. */
29 /* Advance server->qhead; pull out query as we go. */
30 sendreq
= server
->qhead
;
31 server
->qhead
= sendreq
->next
;
32 if (sendreq
->data_storage
!= NULL
)
33 ares_free(sendreq
->data_storage
);
38 /* Reset any existing input buffer. */
39 if (server
->tcp_buffer
)
40 ares_free(server
->tcp_buffer
);
41 server
->tcp_buffer
= NULL
;
42 server
->tcp_lenbuf_pos
= 0;
44 /* Reset brokenness */
45 server
->is_broken
= 0;
47 /* Close the TCP and UDP sockets. */
48 if (server
->tcp_socket
!= ARES_SOCKET_BAD
)
50 SOCK_STATE_CALLBACK(channel
, server
->tcp_socket
, 0, 0);
51 ares__socket_close(channel
, server
->tcp_socket
);
52 server
->tcp_socket
= ARES_SOCKET_BAD
;
53 server
->tcp_connection_generation
= ++channel
->tcp_connection_generation
;
55 if (server
->udp_socket
!= ARES_SOCKET_BAD
)
57 SOCK_STATE_CALLBACK(channel
, server
->udp_socket
, 0, 0);
58 ares__socket_close(channel
, server
->udp_socket
);
59 server
->udp_socket
= ARES_SOCKET_BAD
;