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"
25 #include "ares_private.h"
27 void ares__close_sockets(ares_channel channel, struct server_state *server)
29 struct send_request *sendreq;
31 /* Free all pending output buffers. */
34 /* Advance server->qhead; pull out query as we go. */
35 sendreq = server->qhead;
36 server->qhead = sendreq->next;
37 if (sendreq->data_storage != NULL)
38 free(sendreq->data_storage);
43 /* Reset any existing input buffer. */
44 if (server->tcp_buffer)
45 free(server->tcp_buffer);
46 server->tcp_buffer = NULL;
47 server->tcp_lenbuf_pos = 0;
49 /* Reset brokenness */
50 server->is_broken = 0;
52 /* Close the TCP and UDP sockets. */
53 if (server->tcp_socket != ARES_SOCKET_BAD)
55 SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
56 sclose(server->tcp_socket);
57 server->tcp_socket = ARES_SOCKET_BAD;
58 server->tcp_connection_generation = ++channel->tcp_connection_generation;
60 if (server->udp_socket != ARES_SOCKET_BAD)
62 SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
63 sclose(server->udp_socket);
64 server->udp_socket = ARES_SOCKET_BAD;