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.2 2002-04-04 14:01:52 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 | |
---|
55 | /* Clear readable/writable flags, since we might be in the middle of |
---|
56 | * an ares_process() run. |
---|
57 | */ |
---|
58 | server->udp_readable = 0; |
---|
59 | server->tcp_readable = 0; |
---|
60 | server->tcp_writable = 0; |
---|
61 | } |
---|