chiark / gitweb /
New configuration system for library clients.
[mLib] / bres.h
CommitLineData
a759efa6 1/* -*-c-*-
2 *
c549d9e5 3 * $Id: bres.h,v 1.2 1999/10/30 11:56:21 mdw Exp $
a759efa6 4 *
5 * Background reverse name resolution
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: bres.h,v $
c549d9e5 33 * Revision 1.2 1999/10/30 11:56:21 mdw
34 * Fix include error, pointed out by Chris Rutter.
35 *
a759efa6 36 * Revision 1.1 1999/10/04 21:40:42 mdw
37 * Added background resolver from `fw'.
38 *
39 */
40
41#ifndef RES_H
42#define RES_H
43
44#ifdef __cplusplus
45 extern "C" {
46#endif
47
48/*----- Header files ------------------------------------------------------*/
49
50#include <sys/types.h>
51
52#include <sys/socket.h>
53#include <netinet/in.h>
54#include <arpa/inet.h>
55#include <netdb.h>
56
c549d9e5 57#include "sel.h"
58#include "selbuf.h"
a759efa6 59
60/*----- Data structures ---------------------------------------------------*/
61
62/* --- Client allocated request block --- */
63
64typedef struct bres_client {
65 struct bres_client *next, *prev; /* Queue of waiting resolve jobs */
66 struct bres_server *rs; /* Pointer to attached server */
67 int q; /* Query type (name or address) */
68 union {
69 struct in_addr addr; /* Address to resolve */
70 char *name; /* Name to resolve */
71 } u;
72 void (*func)(struct hostent */*h*/, void */*p*/); /* Handler function */
73 void *p; /* Argument for handler function */
74} bres_client;
75
76/* --- Server maintained resolver blocks --- */
77
78typedef struct bres_server {
79 struct bres_server *next, *prev; /* Doubly-linked list of servers */
80 pid_t kid; /* Process id of server process */
81 int fd; /* File descriptors */
82 struct bres_client *rc; /* Pointer to attached client */
83 sel_timer t; /* Timeout for idle servers */
84 sel_file f; /* Read selector for server */
85} bres_server;
86
87/*----- Functions provided ------------------------------------------------*/
88
89/* --- @bres_abort@ --- *
90 *
91 * Arguments: @bres_client *rc@ = pointer to client block
92 *
93 * Returns: ---
94 *
95 * Use: Removes a queued job.
96 */
97
98extern void bres_abort(bres_client */*rc*/);
99
100/* --- @bres_byaddr@ --- *
101 *
102 * Arguments: @bres_client *rc@ = pointer to client block
103 * @struct in_addr addr@ = address to resolve
104 * @void (*func)(struct hostent *h, void *p)@ = handler function
105 * @void *p@ = argument for handler function
106 *
107 * Returns: ---
108 *
109 * Use: Adds an address lookup job to the queue. The job will be
110 * processed when there's a spare resolver process to deal with
111 * it.
112 */
113
114extern void bres_byaddr(bres_client */*rc*/, struct in_addr /*addr*/,
115 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
116 void */*p*/);
117
118/* --- @bres_byname@ --- *
119 *
120 * Arguments: @bres_client *rc@ = pointer to client block
121 * @const char *name@ = name to resolve
122 * @void (*func)(struct hostent *h, void *p)@ = handler function
123 * @void *p@ = argument for handler function
124 *
125 * Returns: ---
126 *
127 * Use: Adds a name lookup job to the queue. The job will be
128 * processed when there's a spare resolver process to deal with
129 * it.
130 */
131
132extern void bres_byname(bres_client */*rc*/, const char */*name*/,
133 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
134 void */*p*/);
135
136/* --- @bres_exec@ --- *
137 *
138 * Arguments: @const char *file@ = file containing server code or null
139 *
140 * Returns: ---
141 *
142 * Use: Makes `bres' use a standalone server rather than copies of
143 * the current process. This can reduce memory consumption for
144 * large processes, at the expense of startup time (which
145 * shouldn't be too bad anyway, because of the resolver design).
146 * If the filename is null, a default set up at install time is
147 * used. It's probably a good idea to leave it alone.
148 */
149
150extern void bres_exec(const char */*file*/);
151
152/* --- @bres_init@ --- *
153 *
154 * Arguments: @sel_state *s@ = pointer to select multiplexor
155 *
156 * Returns: ---
157 *
158 * Use: Initializes the background resolver for use.
159 */
160
161extern void bres_init(sel_state */*s*/);
162
163/*----- That's all, folks -------------------------------------------------*/
164
165#ifdef __cplusplus
166 }
167#endif
168
169#endif