]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/daemon/worker.h
2 * daemon/worker.h - worker that handles a pending list of requests.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file describes the worker structure that holds a list of
40 * pending requests and handles them.
43 #ifndef DAEMON_WORKER_H
44 #define DAEMON_WORKER_H
46 #include "libunbound/worker.h"
47 #include "util/netevent.h"
48 #include "util/locks.h"
49 #include "util/alloc.h"
50 #include "util/data/msgreply.h"
51 #include "util/data/msgparse.h"
52 #include "daemon/stats.h"
53 #include "util/module.h"
54 #include "dnstap/dnstap.h"
55 struct listen_dnsport
;
56 struct outside_network
;
65 /** worker commands */
66 enum worker_commands
{
67 /** make the worker quit */
69 /** obtain statistics */
71 /** obtain statistics without statsclear */
72 worker_cmd_stats_noreset
,
73 /** execute remote control command */
78 * Structure holding working information for unbound.
79 * Holds globally visible information.
82 /** the thread number (in daemon array). First in struct for debug. */
84 /** global shared daemon structure */
85 struct daemon
* daemon
;
88 /** pipe, for commands for this worker */
90 /** the event base this worker works with */
91 struct comm_base
* base
;
92 /** the frontside listening interface where request events come in */
93 struct listen_dnsport
* front
;
94 /** the backside outside network interface to the auth servers */
95 struct outside_network
* back
;
96 /** ports to be used by this worker. */
98 /** number of ports for this worker */
100 /** the signal handler */
101 struct comm_signal
* comsig
;
102 /** commpoint to listen to commands. */
103 struct comm_point
* cmd_com
;
104 /** timer for statistics */
105 struct comm_timer
* stat_timer
;
107 /** random() table for this worker. */
108 struct ub_randstate
* rndstate
;
109 /** do we need to restart or quit (on signal) */
111 /** allocation cache for this thread */
112 struct alloc_cache alloc
;
113 /** per thread statistics */
114 struct server_stats stats
;
115 /** thread scratch regional */
116 struct regional
* scratchpad
;
118 /** module environment passed to modules, changed for this thread */
119 struct module_env env
;
122 /** dnstap environment, changed for this thread */
128 * Create the worker structure. Bare bones version, zeroed struct,
129 * with backpointers only. Use worker_init on it later.
130 * @param daemon: the daemon that this worker thread is part of.
131 * @param id: the thread number from 0.. numthreads-1.
132 * @param ports: the ports it is allowed to use, array.
133 * @param n: the number of ports.
134 * @return: the new worker or NULL on alloc failure.
136 struct worker
* worker_create(struct daemon
* daemon
, int id
, int* ports
, int n
);
140 * Allocates event base, listens to ports
141 * @param worker: worker to initialize, created with worker_create.
142 * @param cfg: configuration settings.
143 * @param ports: list of shared query ports.
144 * @param do_sigs: if true, worker installs signal handlers.
145 * @return: false on error.
147 int worker_init(struct worker
* worker
, struct config_file
*cfg
,
148 struct listen_port
* ports
, int do_sigs
);
153 void worker_work(struct worker
* worker
);
158 void worker_delete(struct worker
* worker
);
161 * Send a command to a worker. Uses blocking writes.
162 * @param worker: worker to send command to.
163 * @param cmd: command to send.
165 void worker_send_cmd(struct worker
* worker
, enum worker_commands cmd
);
168 * Init worker stats - includes server_stats_init, outside network and mesh.
169 * @param worker: the worker to init
171 void worker_stats_clear(struct worker
* worker
);
173 #endif /* DAEMON_WORKER_H */