4 * Copyright (C) 1999-2001 Internet Software Consortium.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
11 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
17 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Id: app.h,v 1.1 2001/07/06 19:50:03 gson Exp */
30 * ISC Application Support
32 * Dealing with program termination can be difficult, especially in a
33 * multithreaded program. The routines in this module help coordinate
34 * the shutdown process. They are used as follows by the initial (main)
35 * thread of the application:
37 * isc_app_start(); Call very early in main(), before
38 * any other threads have been created.
40 * isc_app_run(); This will post any on-run events,
41 * and then block until application
42 * shutdown is requested. A shutdown
43 * request is made by calling
44 * isc_app_shutdown(), or by sending
45 * SIGINT or SIGTERM to the process.
46 * After isc_app_run() returns, the
47 * application should shutdown itself.
49 * isc_app_finish(); Call very late in main().
51 * Applications that want to use SIGHUP/isc_app_reload() to trigger reloading
52 * should check the result of isc_app_run() and call the reload routine if
53 * the result is ISC_R_RELOAD. They should then call isc_app_run() again
54 * to resume waiting for reload or termination.
56 * Use of this module is not required. In particular, isc_app_start() is
57 * NOT an ISC library initialization routine.
60 * Clients must ensure that isc_app_start(), isc_app_run(), and
61 * isc_app_finish() are called at most once. isc_app_shutdown()
62 * is safe to use by any thread (provided isc_app_start() has been
66 * No anticipated impact.
72 * No anticipated impact.
78 #include <isc/eventclass.h>
80 #include <isc/result.h>
82 typedef isc_event_t isc_appevent_t
;
84 #define ISC_APPEVENT_FIRSTEVENT (ISC_EVENTCLASS_APP + 0)
85 #define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1)
86 #define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535)
93 * Start an ISC library application.
96 * This call should be made before any other ISC library call, and as
97 * close to the beginning of the application as possible.
101 isc_app_onrun(isc_mem_t
*mctx
, isc_task_t
*task
, isc_taskaction_t action
,
104 * Request delivery of an event when the application is run.
107 * isc_app_start() has been called.
117 * Run an ISC library application.
120 * The caller (typically the initial thread of an application) will
121 * block until shutdown is requested. When the call returns, the
122 * caller should start shutting down the application.
125 * isc_app_start() has been called.
128 * Any events requested via isc_app_onrun() will have been posted (in
129 * FIFO order) before isc_app_run() blocks.
132 * ISC_R_SUCCESS Shutdown has been requested.
133 * ISC_R_RELOAD Reload has been requested.
137 isc_app_shutdown(void);
139 * Request application shutdown.
142 * It is safe to call isc_app_shutdown() multiple times. Shutdown will
143 * only be triggered once.
146 * isc_app_run() has been called.
154 isc_app_reload(void);
156 * Request application reload.
159 * isc_app_run() has been called.
167 isc_app_finish(void);
169 * Finish an ISC library application.
172 * This call should be made at or near the end of main().
175 * isc_app_start() has been called.
178 * Any resources allocated by isc_app_start() have been released.
184 * Indicate that a blocking operation will be performed.
187 * If a blocking operation is in process, a call to isc_app_shutdown()
188 * or an external signal will abort the program, rather than allowing
189 * clean shutdown. This is primarily useful for reading user input.
192 * isc_app_start() has been called.
193 * No other blocking operations are in progress.
197 isc_app_unblock(void);
199 * Indicate that a blocking operation is complete.
202 * When a blocking operation has completed, return the program to a
203 * state where a call to isc_app_shutdown() or an external signal will
207 * isc_app_start() has been called.
208 * isc_app_block() has been called by the same thread.
214 #endif /* ISC_APP_H */