]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - libares/ares__close_sockets.c
need automake as a build-dep, even though we don't use most of it
[1ts-debian.git] / libares / ares__close_sockets.c
1 /* Copyright 1998 by the Massachusetts Institute of Technology.
2  *
3  * Permission to use, copy, modify, and distribute this
4  * software and its documentation for any purpose and without
5  * fee is hereby granted, provided that the above copyright
6  * notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in
9  * advertising or publicity pertaining to distribution of the
10  * software without specific, written prior permission.
11  * M.I.T. makes no representations about the suitability of
12  * this software for any purpose.  It is provided "as is"
13  * without express or implied warranty.
14  */
15
16 static const char rcsid[] = "$Id: ares__close_sockets.c,v 1.1 1998/08/13 18:06:22 ghudson Exp $";
17
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include "ares.h"
21 #include "ares_private.h"
22
23 void ares__close_sockets(struct server_state *server)
24 {
25   struct send_request *sendreq;
26
27   /* Free all pending output buffers. */
28   while (server->qhead)
29     {
30       /* Advance server->qhead; pull out query as we go. */
31       sendreq = server->qhead;
32       server->qhead = sendreq->next;
33       free(sendreq);
34     }
35   server->qtail = NULL;
36
37   /* Reset any existing input buffer. */
38   if (server->tcp_buffer)
39     free(server->tcp_buffer);
40   server->tcp_buffer = NULL;
41   server->tcp_lenbuf_pos = 0;
42
43   /* Close the TCP and UDP sockets. */
44   if (server->tcp_socket != -1)
45     {
46       close(server->tcp_socket);
47       server->tcp_socket = -1;
48     }
49   if (server->udp_socket != -1)
50     {
51       close(server->udp_socket);
52       server->udp_socket = -1;
53     }
54 }