xref: /titanic_52/usr/src/cmd/cmd-inet/usr.lib/wpad/eloop.h (revision b02e9a2d4d2071d770e5aa9ae8f83f2bbe1f2ced)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
8  * Sun elects to license this software under the BSD license.
9  * See README for more details.
10  */
11 #ifndef __ELOOP_H
12 #define	__ELOOP_H
13 
14 #pragma ident	"%Z%%M%	%I%	%E% SMI"
15 
16 #ifdef	__cplusplus
17 extern "C" {
18 #endif
19 
20 #ifndef timersub
21 #define	timersub(tvp, uvp, vvp)						\
22 	do								\
23 	{								\
24 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
25 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
26 		if ((vvp)->tv_usec < 0)					\
27 		{							\
28 			(vvp)->tv_sec--;				\
29 			(vvp)->tv_usec += 1000000;			\
30 		}							\
31 	} while (0)
32 #endif /* !timersub */
33 
34 #ifndef timeradd
35 #define	timeradd(tvp, uvp, vvp)						\
36 	do								\
37 	{								\
38 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
39 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
40 		if ((vvp)->tv_usec >= 1000000)				\
41 		{							\
42 			(vvp)->tv_sec++;				\
43 			(vvp)->tv_usec -= 1000000;			\
44 		}							\
45 	} while (0)
46 #endif /* !timeradd */
47 
48 /* Magic number for eloop_cancel_timeout() */
49 #define	ELOOP_ALL_CTX		(void *) -1
50 #define	MAX_POLLFDS		32
51 
52 struct eloop_sock {
53 	int sock;
54 	void *eloop_data;
55 	void *user_data;
56 	void (*handler)(int, void *, void *);
57 };
58 
59 struct eloop_timeout {
60 	struct timeval time;
61 	void *eloop_data;
62 	void *user_data;
63 	void (*handler)(void *, void *);
64 	struct eloop_timeout *next;
65 };
66 
67 struct eloop_signal {
68 	int sig;
69 	void *user_data;
70 	void (*handler)(int, void *, void *);
71 	int signaled;
72 };
73 
74 struct eloop_data {
75 	void *user_data;
76 
77 	int max_sock, reader_count;
78 	struct eloop_sock *readers;
79 
80 	struct eloop_timeout *timeout;
81 
82 	int signal_count;
83 	struct eloop_signal *signals;
84 	int signaled;
85 
86 	int terminate;
87 };
88 
89 void eloop_init(void *);
90 
91 int eloop_register_read_sock(int,
92 	void (*handler)(int, void *, void *), void *, void *);
93 
94 void eloop_unregister_read_sock(int);
95 
96 int eloop_register_timeout(unsigned int, unsigned int,
97 	void (*handler)(void *, void *), void *, void *);
98 
99 void eloop_cancel_timeout(void (*handler)(void *, void *), void *, void *);
100 int eloop_register_signal(int, void (*handler)(int, void *, void *), void *);
101 
102 void eloop_run(void);
103 void eloop_terminate(void);
104 void eloop_destroy(void);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* __ELOOP_H */
111