caabbf13b94dfa08d9f50a867ab2c7553cfe7877
[platform/upstream/c-ares.git] / docs / ares_process.3
1 .\"
2 .\" Copyright 1998 by the Massachusetts Institute of Technology.
3 .\"
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.
15 .\"
16 .TH ARES_PROCESS 3 "25 July 1998"
17 .SH NAME
18 ares_process \- Process events for name resolution
19 .SH SYNOPSIS
20 .nf
21 #include <ares.h>
22
23 void ares_process(ares_channel \fIchannel\fP,
24                   fd_set *\fIread_fds\fP,
25                   fd_set *\fIwrite_fds\fP)
26
27 void ares_process_fd(ares_channel \fIchannel\fP,
28                      ares_socket_t \fIread_fd\fP,
29                      ares_socket_t \fIwrite_fd\fP)
30 .fi
31 .SH DESCRIPTION
32 The \fBares_process(3)\fP function handles input/output events and timeouts
33 associated with queries pending on the name service channel identified by
34 .IR channel .
35 The file descriptor sets pointed to by \fIread_fds\fP and \fIwrite_fds\fP
36 should have file descriptors set in them according to whether the file
37 descriptors specified by \fIares_fds(3)\fP are ready for reading and writing.
38 (The easiest way to determine this information is to invoke \fBselect(3)\fP
39 with a timeout no greater than the timeout given by \fIares_timeout(3)\fP).
40
41 The \fBares_process(3)\fP function will invoke callbacks for pending queries
42 if they complete successfully or fail.
43
44 \fBares_process_fd(3)\fP works the same way but acts and operates only on the
45 specific file descriptors (sockets) you pass in to the function. Use
46 ARES_SOCKET_BAD for "no action". This function is provided to allow users of
47 c-ares to void \fIselect(3)\fP in their applications and within c-ares.
48
49 To only process possible timeout conditions without a socket event occurring,
50 one may pass NULL as the values for both \fIread_fds\fP and \fIwrite_fds\fP for
51 \fBares_process(3)\fP, or ARES_SOCKET_BAD for both \fIread_fd\fP and
52 \fIwrite_fd\fP for \fBares_process_fd(3)\fP.
53 .SH EXAMPLE
54 The following code fragment waits for all pending queries on a channel
55 to complete:
56
57 .nf
58 int nfds, count;
59 fd_set readers, writers;
60 struct timeval tv, *tvp;
61
62 while (1) {
63   FD_ZERO(&readers);
64   FD_ZERO(&writers);
65   nfds = ares_fds(channel, &readers, &writers);
66   if (nfds == 0)
67     break;
68   tvp = ares_timeout(channel, NULL, &tv);
69   count = select(nfds, &readers, &writers, NULL, tvp);
70   ares_process(channel, &readers, &writers);
71 }
72 .fi
73 .SH SEE ALSO
74 .BR ares_fds (3),
75 .BR ares_timeout (3)
76 .SH AUTHOR
77 Greg Hudson, MIT Information Systems
78 .br
79 Copyright 1998 by the Massachusetts Institute of Technology.