chiark / gitweb /
New function allowing an atom's length to be specified at intern time.
[mLib] / bres.h
1 /* -*-c-*-
2  *
3  * $Id: bres.h,v 1.3 1999/12/10 23:42:04 mdw Exp $
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 $
33  * Revision 1.3  1999/12/10 23:42:04  mdw
34  * Change header file guard names.
35  *
36  * Revision 1.2  1999/10/30 11:56:21  mdw
37  * Fix include error, pointed out by Chris Rutter.
38  *
39  * Revision 1.1  1999/10/04 21:40:42  mdw
40  * Added background resolver from `fw'.
41  *
42  */
43
44 #ifndef MLIB_RES_H
45 #define MLIB_RES_H
46
47 #ifdef __cplusplus
48   extern "C" {
49 #endif
50
51 /*----- Header files ------------------------------------------------------*/
52
53 #include <sys/types.h>
54
55 #include <sys/socket.h>
56 #include <netinet/in.h>
57 #include <arpa/inet.h>
58 #include <netdb.h>
59
60 #include "sel.h"
61 #include "selbuf.h"
62
63 /*----- Data structures ---------------------------------------------------*/
64
65 /* --- Client allocated request block --- */
66
67 typedef struct bres_client {
68   struct bres_client *next, *prev;      /* Queue of waiting resolve jobs */
69   struct bres_server *rs;               /* Pointer to attached server */
70   int q;                                /* Query type (name or address) */
71   union {
72     struct in_addr addr;                /* Address to resolve */
73     char *name;                         /* Name to resolve */
74   } u;
75   void (*func)(struct hostent */*h*/, void */*p*/); /* Handler function */
76   void *p;                              /* Argument for handler function */
77 } bres_client;
78
79 /* --- Server maintained resolver blocks --- */
80
81 typedef struct bres_server {
82   struct bres_server *next, *prev;      /* Doubly-linked list of servers */
83   pid_t kid;                            /* Process id of server process */
84   int fd;                               /* File descriptors */
85   struct bres_client *rc;               /* Pointer to attached client */
86   sel_timer t;                          /* Timeout for idle servers */
87   sel_file f;                           /* Read selector for server */
88 } bres_server;
89
90 /*----- Functions provided ------------------------------------------------*/
91
92 /* --- @bres_abort@ --- *
93  *
94  * Arguments:   @bres_client *rc@ = pointer to client block
95  *
96  * Returns:     ---
97  *
98  * Use:         Removes a queued job.
99  */
100
101 extern void bres_abort(bres_client */*rc*/);
102
103 /* --- @bres_byaddr@ --- *
104  *
105  * Arguments:   @bres_client *rc@ = pointer to client block
106  *              @struct in_addr addr@ = address to resolve
107  *              @void (*func)(struct hostent *h, void *p)@ = handler function
108  *              @void *p@ = argument for handler function
109  *
110  * Returns:     ---
111  *
112  * Use:         Adds an address lookup job to the queue.  The job will be
113  *              processed when there's a spare resolver process to deal with
114  *              it.
115  */
116
117 extern void bres_byaddr(bres_client */*rc*/, struct in_addr /*addr*/,
118                         void (*/*func*/)(struct hostent */*h*/, void */*p*/),
119                         void */*p*/);
120
121 /* --- @bres_byname@ --- *
122  *
123  * Arguments:   @bres_client *rc@ = pointer to client block
124  *              @const char *name@ = name to resolve
125  *              @void (*func)(struct hostent *h, void *p)@ = handler function
126  *              @void *p@ = argument for handler function
127  *
128  * Returns:     ---
129  *
130  * Use:         Adds a name lookup job to the queue.  The job will be
131  *              processed when there's a spare resolver process to deal with
132  *              it.
133  */
134
135 extern void bres_byname(bres_client */*rc*/, const char */*name*/,
136                         void (*/*func*/)(struct hostent */*h*/, void */*p*/),
137                         void */*p*/);
138
139 /* --- @bres_exec@ --- *
140  *
141  * Arguments:   @const char *file@ = file containing server code or null
142  *
143  * Returns:     ---
144  *
145  * Use:         Makes `bres' use a standalone server rather than copies of
146  *              the current process.  This can reduce memory consumption for
147  *              large processes, at the expense of startup time (which
148  *              shouldn't be too bad anyway, because of the resolver design).
149  *              If the filename is null, a default set up at install time is
150  *              used.  It's probably a good idea to leave it alone.
151  */
152
153 extern void bres_exec(const char */*file*/);
154
155 /* --- @bres_init@ --- *
156  *
157  * Arguments:   @sel_state *s@ = pointer to select multiplexor
158  *
159  * Returns:     ---
160  *
161  * Use:         Initializes the background resolver for use.
162  */
163
164 extern void bres_init(sel_state */*s*/);
165
166 /*----- That's all, folks -------------------------------------------------*/
167
168 #ifdef __cplusplus
169   }
170 #endif
171
172 #endif