]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/unbound/util/ub_event.h
Fix multiple vulnerabilities in unbound.
[FreeBSD/FreeBSD.git] / contrib / unbound / util / ub_event.h
1 /*
2  * util/ub_event.h - indirection layer for pluggable events
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * 
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  * 
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /**
37  * \file
38  *
39  * This file contains prototypes for event loop functions.
40  *
41  */
42
43 #ifndef UB_EVENT_H
44 #define UB_EVENT_H
45
46 struct ub_event_base;
47 struct ub_event;
48 struct comm_base;
49 struct event_base;
50
51 /** event timeout */
52 #define UB_EV_TIMEOUT      0x01
53 /** event fd readable */
54 #define UB_EV_READ         0x02
55 /** event fd writable */
56 #define UB_EV_WRITE        0x04
57 /** event signal */
58 #define UB_EV_SIGNAL       0x08
59 /** event must persist */
60 #define UB_EV_PERSIST      0x10
61
62 /** Returns event-base type. Could be "mini-event", "winsock-event" for the
63  * daemon compile, and will be "pluggable-event<PACKAGE_VERSION>" for 
64  * libunbound.
65  */
66 const char* ub_event_get_version(void);
67 /** Return the name, system and method for the pluggable event base */
68 void ub_get_event_sys(struct ub_event_base*, const char** n, const char** s,
69         const char** m);
70 /** Return a default event base. In the daemon this will be the only event 
71  * bases used.
72  */
73 struct ub_event_base* ub_default_event_base(int, time_t*, struct timeval*);
74 /** Return an ub_event_base constructed for the given libevent event base */
75 struct ub_event_base* ub_libevent_event_base(struct event_base*);
76 /** Return the libevent base underlying the given ub_event_base.  Will return
77  * NULL when the ub_event_base does not have an underlying libevent event base
78  */
79 struct event_base* ub_libevent_get_event_base(struct ub_event_base*);
80 /** Free event base. Free events yourself */
81 void ub_event_base_free(struct ub_event_base*);
82 /** Run the event base */
83 int ub_event_base_dispatch(struct ub_event_base*);
84 /** exit that loop */
85 int ub_event_base_loopexit(struct ub_event_base*);
86
87 /** Create a new ub_event for the event base */
88 struct ub_event* ub_event_new(struct ub_event_base*,
89         int fd, short bits, void (*cb)(int, short, void*), void* arg);
90 /** Create a new ub_event signal for the event base */
91 struct ub_event* ub_signal_new(struct ub_event_base*, int fd,
92         void (*cb)(int, short, void*), void* arg);
93 /** Create a new ub_event associated with the wsaevent for the event base */
94 struct ub_event* ub_winsock_register_wsaevent(struct ub_event_base*,
95         void* wsaevent, void (*cb)(int, short, void*), void* arg);
96
97 /** Add event bits for this event to fire on */
98 void ub_event_add_bits(struct ub_event*, short bits);
99  /** Configure the event so it will not longer fire on given bits */
100 void ub_event_del_bits(struct ub_event*, short bits);
101 /** Change or set the file descriptor on the event */
102 void ub_event_set_fd(struct ub_event*, int fd);
103 /** free the event */
104 void ub_event_free(struct ub_event*);
105 /** Activate the event.  The given timeval is an timeout value. */
106 int ub_event_add(struct ub_event*, struct timeval*);
107 /** Deactivate the event */
108 int ub_event_del(struct ub_event*);
109 /** Reconfigure and activate a timeout event */
110 int ub_timer_add(struct ub_event*, struct ub_event_base*,
111         void (*cb)(int, short, void*), void* arg, struct timeval*);
112 /** Deactivate the timeout event */
113 int ub_timer_del(struct ub_event*);
114 /** Activate a signal event */
115 int ub_signal_add(struct ub_event*, struct timeval*);
116 /** Deactivate a signal event */
117 int ub_signal_del(struct ub_event*);
118 /** Free a with a wsaevent associated event */
119 void ub_winsock_unregister_wsaevent(struct ub_event* ev);
120 /** Signal the eventloop when a TCP windows socket will block on next read
121  * or write (given by the eventbits)
122  */
123 void ub_winsock_tcp_wouldblock(struct ub_event*, int bits);
124 /** Equip the comm_base with the current time */
125 void ub_comm_base_now(struct comm_base* cb);
126
127 #endif /* UB_EVENT_H */