xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.lib/wpad/eloop.h (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * Copyright 2008 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 #ifdef	__cplusplus
15 extern "C" {
16 #endif
17 
18 /* Magic number for eloop_cancel_timeout() */
19 #define	ELOOP_ALL_CTX		(void *) -1
20 #define	MAX_POLLFDS		32
21 
22 struct eloop_sock {
23 	int sock;
24 	void *eloop_data;
25 	void *user_data;
26 	void (*handler)(int, void *, void *);
27 };
28 
29 struct eloop_timeout {
30 	struct timeval time;
31 	void *eloop_data;
32 	void *user_data;
33 	void (*handler)(void *, void *);
34 	struct eloop_timeout *next;
35 };
36 
37 struct eloop_signal {
38 	int sig;
39 	void *user_data;
40 	void (*handler)(int, void *, void *);
41 	int signaled;
42 };
43 
44 struct eloop_data {
45 	void *user_data;
46 
47 	int max_sock, reader_count;
48 	struct eloop_sock *readers;
49 
50 	struct eloop_timeout *timeout;
51 
52 	int signal_count;
53 	struct eloop_signal *signals;
54 	int signaled;
55 
56 	int terminate;
57 };
58 
59 void eloop_init(void *);
60 
61 int eloop_register_read_sock(int,
62 	void (*handler)(int, void *, void *), void *, void *);
63 
64 void eloop_unregister_read_sock(int);
65 
66 int eloop_register_timeout(unsigned int, unsigned int,
67 	void (*handler)(void *, void *), void *, void *);
68 
69 void eloop_cancel_timeout(void (*handler)(void *, void *), void *, void *);
70 int eloop_register_signal(int, void (*handler)(int, void *, void *), void *);
71 
72 void eloop_run(void);
73 void eloop_terminate(void);
74 void eloop_destroy(void);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* __ELOOP_H */
81