3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * User Space Library Functions
32 * ----------------------------
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_if.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_ioctl.h>
56 Harp_timer *harp_timer_head;
61 * Process a HARP timer tick
63 * This function is called via the SIGALRM signal. It increments
64 * harp_timer_exec. The user should check this flag frequently and
65 * call timer_proc when it is set.
87 * This function is called after a SIGALRM signal is posted. It runs
88 * down the list of timer entries, calling the specified functions
89 * for any timers that have expired.
102 void (*f)(Harp_timer *);
105 * Reset marks in all timers on the queue
107 for (htp = harp_timer_head; htp; htp = htp->ht_next) {
112 * Run through timer chain decrementing each timer.
113 * If an expired timer is found, take the timer block
114 * off the chain and call the specified function. A
115 * timer's action can result in other timers being
116 * cancelled (taken off the queue), so every time we
117 * call a user function, we start over from the top of
121 for (htp = harp_timer_head; htp; htp = htp->ht_next) {
123 * Make sure we only process each entry once and
124 * don't process entries that are put on the queue
125 * by user functions we call for this tick
127 if (htp->ht_mark == -1) {
129 * Decrement the timer and mark that we've
130 * processed the entry
132 htp->ht_ticks -= harp_timer_exec;
136 * Check whether the timer is expired
138 if (htp->ht_ticks <= 0) {
140 * Unlink the timer block and call
144 UNLINK(htp, Harp_timer, harp_timer_head,
157 * Reset the timer exec flag
166 * Set up the SIGALRM signal handler and set up the real-time
167 * timer to tick once per second.
174 * errno reason for failure
181 struct itimerval timeval;
184 * Clear the timer flag
189 * Set up signal handler
191 if (signal(SIGALRM, (sig_t)timer_tick) == SIG_ERR) {
198 timeval.it_value.tv_sec = 1;
199 timeval.it_value.tv_usec = 0;
200 timeval.it_interval.tv_sec = 1;
201 timeval.it_interval.tv_usec = 0;
203 if (setitimer(ITIMER_REAL, &timeval,
204 (struct itimerval *)0) == -1) {
206 (void)signal(SIGALRM, SIG_DFL);
214 * Block timers from firing
216 * Block the SIGALRM signal.
222 * mask the previous blocked signal mask
229 * Block the SIGALRM signal
231 return(sigblock(sigmask(SIGALRM)));
238 * Restore the signal mask (presumably one that was returned by
242 * mask the signal mask to be restored
245 * mask the previous blocked signal mask
253 * Set the signal mask