2 * Copyright (C) 1999-2001 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: app.h,v 1.1 2001/07/06 19:50:03 gson Exp $ */
28 * ISC Application Support
30 * Dealing with program termination can be difficult, especially in a
31 * multithreaded program. The routines in this module help coordinate
32 * the shutdown process. They are used as follows by the initial (main)
33 * thread of the application:
35 * isc_app_start(); Call very early in main(), before
36 * any other threads have been created.
38 * isc_app_run(); This will post any on-run events,
39 * and then block until application
40 * shutdown is requested. A shutdown
41 * request is made by calling
42 * isc_app_shutdown(), or by sending
43 * SIGINT or SIGTERM to the process.
44 * After isc_app_run() returns, the
45 * application should shutdown itself.
47 * isc_app_finish(); Call very late in main().
49 * Applications that want to use SIGHUP/isc_app_reload() to trigger reloading
50 * should check the result of isc_app_run() and call the reload routine if
51 * the result is ISC_R_RELOAD. They should then call isc_app_run() again
52 * to resume waiting for reload or termination.
54 * Use of this module is not required. In particular, isc_app_start() is
55 * NOT an ISC library initialization routine.
58 * Clients must ensure that isc_app_start(), isc_app_run(), and
59 * isc_app_finish() are called at most once. isc_app_shutdown()
60 * is safe to use by any thread (provided isc_app_start() has been
64 * No anticipated impact.
70 * No anticipated impact.
76 #include <isc/eventclass.h>
78 #include <isc/result.h>
80 typedef isc_event_t isc_appevent_t;
82 #define ISC_APPEVENT_FIRSTEVENT (ISC_EVENTCLASS_APP + 0)
83 #define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1)
84 #define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535)
91 * Start an ISC library application.
94 * This call should be made before any other ISC library call, and as
95 * close to the beginning of the application as possible.
99 isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action,
102 * Request delivery of an event when the application is run.
105 * isc_app_start() has been called.
115 * Run an ISC library application.
118 * The caller (typically the initial thread of an application) will
119 * block until shutdown is requested. When the call returns, the
120 * caller should start shutting down the application.
123 * isc_app_start() has been called.
126 * Any events requested via isc_app_onrun() will have been posted (in
127 * FIFO order) before isc_app_run() blocks.
130 * ISC_R_SUCCESS Shutdown has been requested.
131 * ISC_R_RELOAD Reload has been requested.
135 isc_app_shutdown(void);
137 * Request application shutdown.
140 * It is safe to call isc_app_shutdown() multiple times. Shutdown will
141 * only be triggered once.
144 * isc_app_run() has been called.
152 isc_app_reload(void);
154 * Request application reload.
157 * isc_app_run() has been called.
165 isc_app_finish(void);
167 * Finish an ISC library application.
170 * This call should be made at or near the end of main().
173 * isc_app_start() has been called.
176 * Any resources allocated by isc_app_start() have been released.
182 * Indicate that a blocking operation will be performed.
185 * If a blocking operation is in process, a call to isc_app_shutdown()
186 * or an external signal will abort the program, rather than allowing
187 * clean shutdown. This is primarily useful for reading user input.
190 * isc_app_start() has been called.
191 * No other blocking operations are in progress.
195 isc_app_unblock(void);
197 * Indicate that a blocking operation is complete.
200 * When a blocking operation has completed, return the program to a
201 * state where a call to isc_app_shutdown() or an external signal will
205 * isc_app_start() has been called.
206 * isc_app_block() has been called by the same thread.
212 #endif /* ISC_APP_H */