xref: /freebsd/contrib/unbound/util/netevent.h (revision b1f92fa22938fe29ab7e53692ffe0ed7a0ecc4d0)
1 /*
2  * util/netevent.h - event notification
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 event notification functions.
40  *
41  * There are three types of communication points
42  *    o UDP socket - perthread buffer.
43  *    o TCP-accept socket - array of TCP-sockets, socketcount.
44  *    o TCP socket - own buffer, parent-TCPaccept, read/write state,
45  *                   number of bytes read/written, timeout.
46  *
47  * There are sockets aimed towards our clients and towards the internet.
48  *    o frontside - aimed towards our clients, queries come in, answers back.
49  *    o behind - aimed towards internet, to the authoritative DNS servers.
50  *
51  * Several event types are available:
52  *    o comm_base - for thread safety of the comm points, one per thread.
53  *    o comm_point - udp and tcp networking, with callbacks.
54  *    o comm_timer - a timeout with callback.
55  *    o comm_signal - callbacks when signal is caught.
56  *    o comm_reply - holds reply info during networking callback.
57  *
58  */
59 
60 #ifndef NET_EVENT_H
61 #define NET_EVENT_H
62 
63 struct sldns_buffer;
64 struct comm_point;
65 struct comm_reply;
66 struct event_base;
67 
68 /* internal event notification data storage structure. */
69 struct internal_event;
70 struct internal_base;
71 struct internal_timer;
72 
73 /** callback from communication point function type */
74 typedef int comm_point_callback_t(struct comm_point*, void*, int,
75 	struct comm_reply*);
76 
77 /** to pass no_error to callback function */
78 #define NETEVENT_NOERROR 0
79 /** to pass closed connection to callback function */
80 #define NETEVENT_CLOSED -1
81 /** to pass timeout happened to callback function */
82 #define NETEVENT_TIMEOUT -2
83 /** to pass fallback from capsforID to callback function; 0x20 failed */
84 #define NETEVENT_CAPSFAIL -3
85 
86 /** timeout to slow accept calls when not possible, in msec. */
87 #define NETEVENT_SLOW_ACCEPT_TIME 2000
88 
89 /**
90  * A communication point dispatcher. Thread specific.
91  */
92 struct comm_base {
93 	/** behind the scenes structure. with say libevent info. alloced */
94 	struct internal_base* eb;
95 	/** callback to stop listening on accept sockets,
96 	 * performed when accept() will not function properly */
97 	void (*stop_accept)(void*);
98 	/** callback to start listening on accept sockets, performed
99 	 * after stop_accept() then a timeout has passed. */
100 	void (*start_accept)(void*);
101 	/** user argument for stop_accept and start_accept functions */
102 	void* cb_arg;
103 };
104 
105 /**
106  * Reply information for a communication point.
107  */
108 struct comm_reply {
109 	/** the comm_point with fd to send reply on to. */
110 	struct comm_point* c;
111 	/** the address (for UDP based communication) */
112 	struct sockaddr_storage addr;
113 	/** length of address */
114 	socklen_t addrlen;
115 	/** return type 0 (none), 4(IP4), 6(IP6) */
116 	int srctype;
117 	/** the return source interface data */
118 	union {
119 #ifdef IPV6_PKTINFO
120 		struct in6_pktinfo v6info;
121 #endif
122 #ifdef IP_PKTINFO
123 		struct in_pktinfo v4info;
124 #elif defined(IP_RECVDSTADDR)
125 		struct in_addr v4addr;
126 #endif
127 	}
128 		/** variable with return source data */
129 		pktinfo;
130 };
131 
132 /**
133  * Communication point to the network
134  * These behaviours can be accomplished by setting the flags
135  * and passing return values from the callback.
136  *    udp frontside: called after readdone. sendafter.
137  *    tcp frontside: called readdone, sendafter. close.
138  *    udp behind: called after readdone. No send after.
139  *    tcp behind: write done, read done, then called. No send after.
140  */
141 struct comm_point {
142 	/** behind the scenes structure, with say libevent info. alloced. */
143 	struct internal_event* ev;
144 
145 	/** file descriptor for communication point */
146 	int fd;
147 
148 	/** timeout (NULL if it does not). Malloced. */
149 	struct timeval* timeout;
150 
151 	/** buffer pointer. Either to perthread, or own buffer or NULL */
152 	struct sldns_buffer* buffer;
153 
154 	/* -------- TCP Handler -------- */
155 	/** Read/Write state for TCP */
156 	int tcp_is_reading;
157 	/** The current read/write count for TCP */
158 	size_t tcp_byte_count;
159 	/** parent communication point (for TCP sockets) */
160 	struct comm_point* tcp_parent;
161 	/** sockaddr from peer, for TCP handlers */
162 	struct comm_reply repinfo;
163 
164 	/* -------- TCP Accept -------- */
165 	/** the number of TCP handlers for this tcp-accept socket */
166 	int max_tcp_count;
167 	/** current number of tcp handler in-use for this accept socket */
168 	int cur_tcp_count;
169 	/** malloced array of tcp handlers for a tcp-accept,
170 	    of size max_tcp_count. */
171 	struct comm_point** tcp_handlers;
172 	/** linked list of free tcp_handlers to use for new queries.
173 	    For tcp_accept the first entry, for tcp_handlers the next one. */
174 	struct comm_point* tcp_free;
175 
176 	/* -------- SSL TCP DNS ------- */
177 	/** the SSL object with rw bio (owned) or for commaccept ctx ref */
178 	void* ssl;
179 	/** handshake state for init and renegotiate */
180 	enum {
181 		/** no handshake, it has been done */
182 		comm_ssl_shake_none = 0,
183 		/** ssl initial handshake wants to read */
184 		comm_ssl_shake_read,
185 		/** ssl initial handshake wants to write */
186 		comm_ssl_shake_write,
187 		/** ssl_write wants to read */
188 		comm_ssl_shake_hs_read,
189 		/** ssl_read wants to write */
190 		comm_ssl_shake_hs_write
191 	} ssl_shake_state;
192 
193 	/* -------- dnstap ------- */
194 	/** the dnstap environment */
195 	struct dt_env* dtenv;
196 
197 	/** is this a UDP, TCP-accept or TCP socket. */
198 	enum comm_point_type {
199 		/** UDP socket - handle datagrams. */
200 		comm_udp,
201 		/** TCP accept socket - only creates handlers if readable. */
202 		comm_tcp_accept,
203 		/** TCP handler socket - handle byteperbyte readwrite. */
204 		comm_tcp,
205 		/** AF_UNIX socket - for internal commands. */
206 		comm_local,
207 		/** raw - not DNS format - for pipe readers and writers */
208 		comm_raw
209 	}
210 		/** variable with type of socket, UDP,TCP-accept,TCP,pipe */
211 		type;
212 
213 	/* ---------- Behaviour ----------- */
214 	/** if set the connection is NOT closed on delete. */
215 	int do_not_close;
216 
217 	/** if set, the connection is closed on error, on timeout,
218 	    and after read/write completes. No callback is done. */
219 	int tcp_do_close;
220 
221 	/** if set, read/write completes:
222 		read/write state of tcp is toggled.
223 		buffer reset/bytecount reset.
224 		this flag cleared.
225 	    So that when that is done the callback is called. */
226 	int tcp_do_toggle_rw;
227 
228 	/** if set, checks for pending error from nonblocking connect() call.*/
229 	int tcp_check_nb_connect;
230 
231 	/** number of queries outstanding on this socket, used by
232 	 * outside network for udp ports */
233 	int inuse;
234 
235 	/** callback when done.
236 	    tcp_accept does not get called back, is NULL then.
237 	    If a timeout happens, callback with timeout=1 is called.
238 	    If an error happens, callback is called with error set
239 	    nonzero. If not NETEVENT_NOERROR, it is an errno value.
240 	    If the connection is closed (by remote end) then the
241 	    callback is called with error set to NETEVENT_CLOSED=-1.
242 	    If a timeout happens on the connection, the error is set to
243 	    NETEVENT_TIMEOUT=-2.
244 	    The reply_info can be copied if the reply needs to happen at a
245 	    later time. It consists of a struct with commpoint and address.
246 	    It can be passed to a msg send routine some time later.
247 	    Note the reply information is temporary and must be copied.
248 	    NULL is passed for_reply info, in cases where error happened.
249 
250 	    declare as:
251 	    int my_callback(struct comm_point* c, void* my_arg, int error,
252 		struct comm_reply *reply_info);
253 
254 	    if the routine returns 0, nothing is done.
255 	    Notzero, the buffer will be sent back to client.
256 	    		For UDP this is done without changing the commpoint.
257 			In TCP it sets write state.
258 	*/
259 	comm_point_callback_t* callback;
260 	/** argument to pass to callback. */
261 	void *cb_arg;
262 };
263 
264 /**
265  * Structure only for making timeout events.
266  */
267 struct comm_timer {
268 	/** the internal event stuff */
269 	struct internal_timer* ev_timer;
270 
271 	/** callback function, takes user arg only */
272 	void (*callback)(void*);
273 
274 	/** callback user argument */
275 	void* cb_arg;
276 };
277 
278 /**
279  * Structure only for signal events.
280  */
281 struct comm_signal {
282 	/** the communication base */
283 	struct comm_base* base;
284 
285 	/** the internal event stuff */
286 	struct internal_signal* ev_signal;
287 
288 	/** callback function, takes signal number and user arg */
289 	void (*callback)(int, void*);
290 
291 	/** callback user argument */
292 	void* cb_arg;
293 };
294 
295 /**
296  * Create a new comm base.
297  * @param sigs: if true it attempts to create a default loop for
298  *   signal handling.
299  * @return: the new comm base. NULL on error.
300  */
301 struct comm_base* comm_base_create(int sigs);
302 
303 /**
304  * Create comm base that uses the given event_base (underlying event
305  * mechanism pointer).
306  * @param base: underlying lib event base.
307  * @return: the new comm base. NULL on error.
308  */
309 struct comm_base* comm_base_create_event(struct event_base* base);
310 
311 /**
312  * Delete comm base structure but not the underlying lib event base.
313  * All comm points must have been deleted.
314  * @param b: the base to delete.
315  */
316 void comm_base_delete_no_base(struct comm_base* b);
317 
318 /**
319  * Destroy a comm base.
320  * All comm points must have been deleted.
321  * @param b: the base to delete.
322  */
323 void comm_base_delete(struct comm_base* b);
324 
325 /**
326  * Obtain two pointers. The pointers never change (until base_delete()).
327  * The pointers point to time values that are updated regularly.
328  * @param b: the communication base that will update the time values.
329  * @param tt: pointer to time in seconds is returned.
330  * @param tv: pointer to time in microseconds is returned.
331  */
332 void comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv);
333 
334 /**
335  * Dispatch the comm base events.
336  * @param b: the communication to perform.
337  */
338 void comm_base_dispatch(struct comm_base* b);
339 
340 /**
341  * Exit from dispatch loop.
342  * @param b: the communication base that is in dispatch().
343  */
344 void comm_base_exit(struct comm_base* b);
345 
346 /**
347  * Set the slow_accept mode handlers.  You can not provide these if you do
348  * not perform accept() calls.
349  * @param b: comm base
350  * @param stop_accept: function that stops listening to accept fds.
351  * @param start_accept: function that resumes listening to accept fds.
352  * @param arg: callback arg to pass to the functions.
353  */
354 void comm_base_set_slow_accept_handlers(struct comm_base* b,
355 	void (*stop_accept)(void*), void (*start_accept)(void*), void* arg);
356 
357 /**
358  * Access internal data structure (for util/tube.c on windows)
359  * @param b: comm base
360  * @return event_base. Could be libevent, or internal event handler.
361  */
362 struct event_base* comm_base_internal(struct comm_base* b);
363 
364 /**
365  * Create an UDP comm point. Calls malloc.
366  * setups the structure with the parameters you provide.
367  * @param base: in which base to alloc the commpoint.
368  * @param fd : file descriptor of open UDP socket.
369  * @param buffer: shared buffer by UDP sockets from this thread.
370  * @param callback: callback function pointer.
371  * @param callback_arg: will be passed to your callback function.
372  * @return: returns the allocated communication point. NULL on error.
373  * Sets timeout to NULL. Turns off TCP options.
374  */
375 struct comm_point* comm_point_create_udp(struct comm_base* base,
376 	int fd, struct sldns_buffer* buffer,
377 	comm_point_callback_t* callback, void* callback_arg);
378 
379 /**
380  * Create an UDP with ancillary data comm point. Calls malloc.
381  * Uses recvmsg instead of recv to get udp message.
382  * setups the structure with the parameters you provide.
383  * @param base: in which base to alloc the commpoint.
384  * @param fd : file descriptor of open UDP socket.
385  * @param buffer: shared buffer by UDP sockets from this thread.
386  * @param callback: callback function pointer.
387  * @param callback_arg: will be passed to your callback function.
388  * @return: returns the allocated communication point. NULL on error.
389  * Sets timeout to NULL. Turns off TCP options.
390  */
391 struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
392 	int fd, struct sldns_buffer* buffer,
393 	comm_point_callback_t* callback, void* callback_arg);
394 
395 /**
396  * Create a TCP listener comm point. Calls malloc.
397  * Setups the structure with the parameters you provide.
398  * Also Creates TCP Handlers, pre allocated for you.
399  * Uses the parameters you provide.
400  * @param base: in which base to alloc the commpoint.
401  * @param fd: file descriptor of open TCP socket set to listen nonblocking.
402  * @param num: becomes max_tcp_count, the routine allocates that
403  *	many tcp handler commpoints.
404  * @param bufsize: size of buffer to create for handlers.
405  * @param callback: callback function pointer for TCP handlers.
406  * @param callback_arg: will be passed to your callback function.
407  * @return: returns the TCP listener commpoint. You can find the
408  *  	TCP handlers in the array inside the listener commpoint.
409  *	returns NULL on error.
410  * Inits timeout to NULL. All handlers are on the free list.
411  */
412 struct comm_point* comm_point_create_tcp(struct comm_base* base,
413 	int fd, int num, size_t bufsize,
414 	comm_point_callback_t* callback, void* callback_arg);
415 
416 /**
417  * Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
418  * @param base: in which base to alloc the commpoint.
419  * @param bufsize: size of buffer to create for handlers.
420  * @param callback: callback function pointer for the handler.
421  * @param callback_arg: will be passed to your callback function.
422  * @return: the commpoint or NULL on error.
423  */
424 struct comm_point* comm_point_create_tcp_out(struct comm_base* base,
425 	size_t bufsize, comm_point_callback_t* callback, void* callback_arg);
426 
427 /**
428  * Create commpoint to listen to a local domain file descriptor.
429  * @param base: in which base to alloc the commpoint.
430  * @param fd: file descriptor of open AF_UNIX socket set to listen nonblocking.
431  * @param bufsize: size of buffer to create for handlers.
432  * @param callback: callback function pointer for the handler.
433  * @param callback_arg: will be passed to your callback function.
434  * @return: the commpoint or NULL on error.
435  */
436 struct comm_point* comm_point_create_local(struct comm_base* base,
437 	int fd, size_t bufsize,
438 	comm_point_callback_t* callback, void* callback_arg);
439 
440 /**
441  * Create commpoint to listen to a local domain pipe descriptor.
442  * @param base: in which base to alloc the commpoint.
443  * @param fd: file descriptor.
444  * @param writing: true if you want to listen to writes, false for reads.
445  * @param callback: callback function pointer for the handler.
446  * @param callback_arg: will be passed to your callback function.
447  * @return: the commpoint or NULL on error.
448  */
449 struct comm_point* comm_point_create_raw(struct comm_base* base,
450 	int fd, int writing,
451 	comm_point_callback_t* callback, void* callback_arg);
452 
453 /**
454  * Close a comm point fd.
455  * @param c: comm point to close.
456  */
457 void comm_point_close(struct comm_point* c);
458 
459 /**
460  * Close and deallocate (free) the comm point. If the comm point is
461  * a tcp-accept point, also its tcp-handler points are deleted.
462  * @param c: comm point to delete.
463  */
464 void comm_point_delete(struct comm_point* c);
465 
466 /**
467  * Send reply. Put message into commpoint buffer.
468  * @param repinfo: The reply info copied from a commpoint callback call.
469  */
470 void comm_point_send_reply(struct comm_reply* repinfo);
471 
472 /**
473  * Drop reply. Cleans up.
474  * @param repinfo: The reply info copied from a commpoint callback call.
475  */
476 void comm_point_drop_reply(struct comm_reply* repinfo);
477 
478 /**
479  * Send an udp message over a commpoint.
480  * @param c: commpoint to send it from.
481  * @param packet: what to send.
482  * @param addr: where to send it to.
483  * @param addrlen: length of addr.
484  * @return: false on a failure.
485  */
486 int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
487 	struct sockaddr* addr, socklen_t addrlen);
488 
489 /**
490  * Stop listening for input on the commpoint. No callbacks will happen.
491  * @param c: commpoint to disable. The fd is not closed.
492  */
493 void comm_point_stop_listening(struct comm_point* c);
494 
495 /**
496  * Start listening again for input on the comm point.
497  * @param c: commpoint to enable again.
498  * @param newfd: new fd, or -1 to leave fd be.
499  * @param sec: timeout in seconds, or -1 for no (change to the) timeout.
500  */
501 void comm_point_start_listening(struct comm_point* c, int newfd, int sec);
502 
503 /**
504  * Stop listening and start listening again for reading or writing.
505  * @param c: commpoint
506  * @param rd: if true, listens for reading.
507  * @param wr: if true, listens for writing.
508  */
509 void comm_point_listen_for_rw(struct comm_point* c, int rd, int wr);
510 
511 /**
512  * Get size of memory used by comm point.
513  * For TCP handlers this includes subhandlers.
514  * For UDP handlers, this does not include the (shared) UDP buffer.
515  * @param c: commpoint.
516  * @return size in bytes.
517  */
518 size_t comm_point_get_mem(struct comm_point* c);
519 
520 /**
521  * create timer. Not active upon creation.
522  * @param base: event handling base.
523  * @param cb: callback function: void myfunc(void* myarg);
524  * @param cb_arg: user callback argument.
525  * @return: the new timer or NULL on error.
526  */
527 struct comm_timer* comm_timer_create(struct comm_base* base,
528 	void (*cb)(void*), void* cb_arg);
529 
530 /**
531  * disable timer. Stops callbacks from happening.
532  * @param timer: to disable.
533  */
534 void comm_timer_disable(struct comm_timer* timer);
535 
536 /**
537  * reset timevalue for timer.
538  * @param timer: timer to (re)set.
539  * @param tv: when the timer should activate. if NULL timer is disabled.
540  */
541 void comm_timer_set(struct comm_timer* timer, struct timeval* tv);
542 
543 /**
544  * delete timer.
545  * @param timer: to delete.
546  */
547 void comm_timer_delete(struct comm_timer* timer);
548 
549 /**
550  * see if timeout has been set to a value.
551  * @param timer: the timer to examine.
552  * @return: false if disabled or not set.
553  */
554 int comm_timer_is_set(struct comm_timer* timer);
555 
556 /**
557  * Get size of memory used by comm timer.
558  * @param timer: the timer to examine.
559  * @return size in bytes.
560  */
561 size_t comm_timer_get_mem(struct comm_timer* timer);
562 
563 /**
564  * Create a signal handler. Call signal_bind() later to bind to a signal.
565  * @param base: communication base to use.
566  * @param callback: called when signal is caught.
567  * @param cb_arg: user argument to callback
568  * @return: the signal struct or NULL on error.
569  */
570 struct comm_signal* comm_signal_create(struct comm_base* base,
571 	void (*callback)(int, void*), void* cb_arg);
572 
573 /**
574  * Bind signal struct to catch a signal. A signle comm_signal can be bound
575  * to multiple signals, calling comm_signal_bind multiple times.
576  * @param comsig: the communication point, with callback information.
577  * @param sig: signal number.
578  * @return: true on success. false on error.
579  */
580 int comm_signal_bind(struct comm_signal* comsig, int sig);
581 
582 /**
583  * Delete the signal communication point.
584  * @param comsig: to delete.
585  */
586 void comm_signal_delete(struct comm_signal* comsig);
587 
588 /**
589  * perform accept(2) with error checking.
590  * @param c: commpoint with accept fd.
591  * @param addr: remote end returned here.
592  * @param addrlen: length of remote end returned here.
593  * @return new fd, or -1 on error.
594  *	if -1, error message has been printed if necessary, simply drop
595  *	out of the reading handler.
596  */
597 int comm_point_perform_accept(struct comm_point* c,
598 	struct sockaddr_storage* addr, socklen_t* addrlen);
599 
600 /**** internal routines ****/
601 
602 /**
603  * This routine is published for checks and tests, and is only used internally.
604  * handle libevent callback for udp comm point.
605  * @param fd: file descriptor.
606  * @param event: event bits from libevent:
607  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
608  * @param arg: the comm_point structure.
609  */
610 void comm_point_udp_callback(int fd, short event, void* arg);
611 
612 /**
613  * This routine is published for checks and tests, and is only used internally.
614  * handle libevent callback for udp ancillary data comm point.
615  * @param fd: file descriptor.
616  * @param event: event bits from libevent:
617  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
618  * @param arg: the comm_point structure.
619  */
620 void comm_point_udp_ancil_callback(int fd, short event, void* arg);
621 
622 /**
623  * This routine is published for checks and tests, and is only used internally.
624  * handle libevent callback for tcp accept comm point
625  * @param fd: file descriptor.
626  * @param event: event bits from libevent:
627  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
628  * @param arg: the comm_point structure.
629  */
630 void comm_point_tcp_accept_callback(int fd, short event, void* arg);
631 
632 /**
633  * This routine is published for checks and tests, and is only used internally.
634  * handle libevent callback for tcp data comm point
635  * @param fd: file descriptor.
636  * @param event: event bits from libevent:
637  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
638  * @param arg: the comm_point structure.
639  */
640 void comm_point_tcp_handle_callback(int fd, short event, void* arg);
641 
642 /**
643  * This routine is published for checks and tests, and is only used internally.
644  * handle libevent callback for timer comm.
645  * @param fd: file descriptor (always -1).
646  * @param event: event bits from libevent:
647  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
648  * @param arg: the comm_timer structure.
649  */
650 void comm_timer_callback(int fd, short event, void* arg);
651 
652 /**
653  * This routine is published for checks and tests, and is only used internally.
654  * handle libevent callback for signal comm.
655  * @param fd: file descriptor (used for the signal number).
656  * @param event: event bits from libevent:
657  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
658  * @param arg: the internal commsignal structure.
659  */
660 void comm_signal_callback(int fd, short event, void* arg);
661 
662 /**
663  * This routine is published for checks and tests, and is only used internally.
664  * libevent callback for AF_UNIX fds
665  * @param fd: file descriptor.
666  * @param event: event bits from libevent:
667  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
668  * @param arg: the comm_point structure.
669  */
670 void comm_point_local_handle_callback(int fd, short event, void* arg);
671 
672 /**
673  * This routine is published for checks and tests, and is only used internally.
674  * libevent callback for raw fd access.
675  * @param fd: file descriptor.
676  * @param event: event bits from libevent:
677  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
678  * @param arg: the comm_point structure.
679  */
680 void comm_point_raw_handle_callback(int fd, short event, void* arg);
681 
682 /**
683  * This routine is published for checks and tests, and is only used internally.
684  * libevent callback for timeout on slow accept.
685  * @param fd: file descriptor.
686  * @param event: event bits from libevent:
687  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
688  * @param arg: the comm_point structure.
689  */
690 void comm_base_handle_slow_accept(int fd, short event, void* arg);
691 
692 #ifdef USE_WINSOCK
693 /**
694  * Callback for openssl BIO to on windows detect WSAEWOULDBLOCK and notify
695  * the winsock_event of this for proper TCP nonblocking implementation.
696  * @param c: comm_point, fd must be set its struct event is registered.
697  * @param ssl: openssl SSL, fd must be set so it has a bio.
698  */
699 void comm_point_tcp_win_bio_cb(struct comm_point* c, void* ssl);
700 #endif
701 
702 /** see if errno for tcp connect has to be logged or not. This uses errno */
703 int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen);
704 
705 #endif /* NET_EVENT_H */
706