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