xref: /freebsd/contrib/unbound/util/netevent.h (revision ea825d02749f382c3f7e17f28247f20a48733eab)
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 ub_event_base;
67 
68 /* internal event notification data storage structure. */
69 struct internal_event;
70 struct internal_base;
71 struct internal_timer; /* A sub struct of the comm_timer super struct */
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 	/** timeout in msec for TCP wait times for this connection */
229 	int tcp_timeout_msec;
230 
231 	/** if set, checks for pending error from nonblocking connect() call.*/
232 	int tcp_check_nb_connect;
233 
234 #ifdef USE_MSG_FASTOPEN
235 	/** used to track if the sendto() call should be done when using TFO. */
236 	int tcp_do_fastopen;
237 #endif
238 
239 	/** number of queries outstanding on this socket, used by
240 	 * outside network for udp ports */
241 	int inuse;
242 
243 	/** callback when done.
244 	    tcp_accept does not get called back, is NULL then.
245 	    If a timeout happens, callback with timeout=1 is called.
246 	    If an error happens, callback is called with error set
247 	    nonzero. If not NETEVENT_NOERROR, it is an errno value.
248 	    If the connection is closed (by remote end) then the
249 	    callback is called with error set to NETEVENT_CLOSED=-1.
250 	    If a timeout happens on the connection, the error is set to
251 	    NETEVENT_TIMEOUT=-2.
252 	    The reply_info can be copied if the reply needs to happen at a
253 	    later time. It consists of a struct with commpoint and address.
254 	    It can be passed to a msg send routine some time later.
255 	    Note the reply information is temporary and must be copied.
256 	    NULL is passed for_reply info, in cases where error happened.
257 
258 	    declare as:
259 	    int my_callback(struct comm_point* c, void* my_arg, int error,
260 		struct comm_reply *reply_info);
261 
262 	    if the routine returns 0, nothing is done.
263 	    Notzero, the buffer will be sent back to client.
264 	    		For UDP this is done without changing the commpoint.
265 			In TCP it sets write state.
266 	*/
267 	comm_point_callback_t* callback;
268 	/** argument to pass to callback. */
269 	void *cb_arg;
270 };
271 
272 /**
273  * Structure only for making timeout events.
274  */
275 struct comm_timer {
276 	/** the internal event stuff (derived) */
277 	struct internal_timer* ev_timer;
278 
279 	/** callback function, takes user arg only */
280 	void (*callback)(void*);
281 
282 	/** callback user argument */
283 	void* cb_arg;
284 };
285 
286 /**
287  * Structure only for signal events.
288  */
289 struct comm_signal {
290 	/** the communication base */
291 	struct comm_base* base;
292 
293 	/** the internal event stuff */
294 	struct internal_signal* ev_signal;
295 
296 	/** callback function, takes signal number and user arg */
297 	void (*callback)(int, void*);
298 
299 	/** callback user argument */
300 	void* cb_arg;
301 };
302 
303 /**
304  * Create a new comm base.
305  * @param sigs: if true it attempts to create a default loop for
306  *   signal handling.
307  * @return: the new comm base. NULL on error.
308  */
309 struct comm_base* comm_base_create(int sigs);
310 
311 /**
312  * Create comm base that uses the given ub_event_base (underlying pluggable
313  * event mechanism pointer).
314  * @param base: underlying pluggable event base.
315  * @return: the new comm base. NULL on error.
316  */
317 struct comm_base* comm_base_create_event(struct ub_event_base* base);
318 
319 /**
320  * Delete comm base structure but not the underlying lib event base.
321  * All comm points must have been deleted.
322  * @param b: the base to delete.
323  */
324 void comm_base_delete_no_base(struct comm_base* b);
325 
326 /**
327  * Destroy a comm base.
328  * All comm points must have been deleted.
329  * @param b: the base to delete.
330  */
331 void comm_base_delete(struct comm_base* b);
332 
333 /**
334  * Obtain two pointers. The pointers never change (until base_delete()).
335  * The pointers point to time values that are updated regularly.
336  * @param b: the communication base that will update the time values.
337  * @param tt: pointer to time in seconds is returned.
338  * @param tv: pointer to time in microseconds is returned.
339  */
340 void comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv);
341 
342 /**
343  * Dispatch the comm base events.
344  * @param b: the communication to perform.
345  */
346 void comm_base_dispatch(struct comm_base* b);
347 
348 /**
349  * Exit from dispatch loop.
350  * @param b: the communication base that is in dispatch().
351  */
352 void comm_base_exit(struct comm_base* b);
353 
354 /**
355  * Set the slow_accept mode handlers.  You can not provide these if you do
356  * not perform accept() calls.
357  * @param b: comm base
358  * @param stop_accept: function that stops listening to accept fds.
359  * @param start_accept: function that resumes listening to accept fds.
360  * @param arg: callback arg to pass to the functions.
361  */
362 void comm_base_set_slow_accept_handlers(struct comm_base* b,
363 	void (*stop_accept)(void*), void (*start_accept)(void*), void* arg);
364 
365 /**
366  * Access internal data structure (for util/tube.c on windows)
367  * @param b: comm base
368  * @return ub_event_base.
369  */
370 struct ub_event_base* comm_base_internal(struct comm_base* b);
371 
372 /**
373  * Create an UDP comm point. Calls malloc.
374  * setups the structure with the parameters you provide.
375  * @param base: in which base to alloc the commpoint.
376  * @param fd : file descriptor of open UDP socket.
377  * @param buffer: shared buffer by UDP sockets from this thread.
378  * @param callback: callback function pointer.
379  * @param callback_arg: will be passed to your callback function.
380  * @return: returns the allocated communication point. NULL on error.
381  * Sets timeout to NULL. Turns off TCP options.
382  */
383 struct comm_point* comm_point_create_udp(struct comm_base* base,
384 	int fd, struct sldns_buffer* buffer,
385 	comm_point_callback_t* callback, void* callback_arg);
386 
387 /**
388  * Create an UDP with ancillary data comm point. Calls malloc.
389  * Uses recvmsg instead of recv to get udp message.
390  * setups the structure with the parameters you provide.
391  * @param base: in which base to alloc the commpoint.
392  * @param fd : file descriptor of open UDP socket.
393  * @param buffer: shared buffer by UDP sockets from this thread.
394  * @param callback: callback function pointer.
395  * @param callback_arg: will be passed to your callback function.
396  * @return: returns the allocated communication point. NULL on error.
397  * Sets timeout to NULL. Turns off TCP options.
398  */
399 struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
400 	int fd, struct sldns_buffer* buffer,
401 	comm_point_callback_t* callback, void* callback_arg);
402 
403 /**
404  * Create a TCP listener comm point. Calls malloc.
405  * Setups the structure with the parameters you provide.
406  * Also Creates TCP Handlers, pre allocated for you.
407  * Uses the parameters you provide.
408  * @param base: in which base to alloc the commpoint.
409  * @param fd: file descriptor of open TCP socket set to listen nonblocking.
410  * @param num: becomes max_tcp_count, the routine allocates that
411  *	many tcp handler commpoints.
412  * @param bufsize: size of buffer to create for handlers.
413  * @param callback: callback function pointer for TCP handlers.
414  * @param callback_arg: will be passed to your callback function.
415  * @return: returns the TCP listener commpoint. You can find the
416  *  	TCP handlers in the array inside the listener commpoint.
417  *	returns NULL on error.
418  * Inits timeout to NULL. All handlers are on the free list.
419  */
420 struct comm_point* comm_point_create_tcp(struct comm_base* base,
421 	int fd, int num, size_t bufsize,
422 	comm_point_callback_t* callback, void* callback_arg);
423 
424 /**
425  * Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
426  * @param base: in which base to alloc the commpoint.
427  * @param bufsize: size of buffer to create for handlers.
428  * @param callback: callback function pointer for the handler.
429  * @param callback_arg: will be passed to your callback function.
430  * @return: the commpoint or NULL on error.
431  */
432 struct comm_point* comm_point_create_tcp_out(struct comm_base* base,
433 	size_t bufsize, comm_point_callback_t* callback, void* callback_arg);
434 
435 /**
436  * Create commpoint to listen to a local domain file descriptor.
437  * @param base: in which base to alloc the commpoint.
438  * @param fd: file descriptor of open AF_UNIX socket set to listen nonblocking.
439  * @param bufsize: size of buffer to create for handlers.
440  * @param callback: callback function pointer for the handler.
441  * @param callback_arg: will be passed to your callback function.
442  * @return: the commpoint or NULL on error.
443  */
444 struct comm_point* comm_point_create_local(struct comm_base* base,
445 	int fd, size_t bufsize,
446 	comm_point_callback_t* callback, void* callback_arg);
447 
448 /**
449  * Create commpoint to listen to a local domain pipe descriptor.
450  * @param base: in which base to alloc the commpoint.
451  * @param fd: file descriptor.
452  * @param writing: true if you want to listen to writes, false for reads.
453  * @param callback: callback function pointer for the handler.
454  * @param callback_arg: will be passed to your callback function.
455  * @return: the commpoint or NULL on error.
456  */
457 struct comm_point* comm_point_create_raw(struct comm_base* base,
458 	int fd, int writing,
459 	comm_point_callback_t* callback, void* callback_arg);
460 
461 /**
462  * Close a comm point fd.
463  * @param c: comm point to close.
464  */
465 void comm_point_close(struct comm_point* c);
466 
467 /**
468  * Close and deallocate (free) the comm point. If the comm point is
469  * a tcp-accept point, also its tcp-handler points are deleted.
470  * @param c: comm point to delete.
471  */
472 void comm_point_delete(struct comm_point* c);
473 
474 /**
475  * Send reply. Put message into commpoint buffer.
476  * @param repinfo: The reply info copied from a commpoint callback call.
477  */
478 void comm_point_send_reply(struct comm_reply* repinfo);
479 
480 /**
481  * Drop reply. Cleans up.
482  * @param repinfo: The reply info copied from a commpoint callback call.
483  */
484 void comm_point_drop_reply(struct comm_reply* repinfo);
485 
486 /**
487  * Send an udp message over a commpoint.
488  * @param c: commpoint to send it from.
489  * @param packet: what to send.
490  * @param addr: where to send it to.
491  * @param addrlen: length of addr.
492  * @return: false on a failure.
493  */
494 int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
495 	struct sockaddr* addr, socklen_t addrlen);
496 
497 /**
498  * Stop listening for input on the commpoint. No callbacks will happen.
499  * @param c: commpoint to disable. The fd is not closed.
500  */
501 void comm_point_stop_listening(struct comm_point* c);
502 
503 /**
504  * Start listening again for input on the comm point.
505  * @param c: commpoint to enable again.
506  * @param newfd: new fd, or -1 to leave fd be.
507  * @param msec: timeout in milliseconds, or -1 for no (change to the) timeout.
508  *	So seconds*1000.
509  */
510 void comm_point_start_listening(struct comm_point* c, int newfd, int msec);
511 
512 /**
513  * Stop listening and start listening again for reading or writing.
514  * @param c: commpoint
515  * @param rd: if true, listens for reading.
516  * @param wr: if true, listens for writing.
517  */
518 void comm_point_listen_for_rw(struct comm_point* c, int rd, int wr);
519 
520 /**
521  * Get size of memory used by comm point.
522  * For TCP handlers this includes subhandlers.
523  * For UDP handlers, this does not include the (shared) UDP buffer.
524  * @param c: commpoint.
525  * @return size in bytes.
526  */
527 size_t comm_point_get_mem(struct comm_point* c);
528 
529 /**
530  * create timer. Not active upon creation.
531  * @param base: event handling base.
532  * @param cb: callback function: void myfunc(void* myarg);
533  * @param cb_arg: user callback argument.
534  * @return: the new timer or NULL on error.
535  */
536 struct comm_timer* comm_timer_create(struct comm_base* base,
537 	void (*cb)(void*), void* cb_arg);
538 
539 /**
540  * disable timer. Stops callbacks from happening.
541  * @param timer: to disable.
542  */
543 void comm_timer_disable(struct comm_timer* timer);
544 
545 /**
546  * reset timevalue for timer.
547  * @param timer: timer to (re)set.
548  * @param tv: when the timer should activate. if NULL timer is disabled.
549  */
550 void comm_timer_set(struct comm_timer* timer, struct timeval* tv);
551 
552 /**
553  * delete timer.
554  * @param timer: to delete.
555  */
556 void comm_timer_delete(struct comm_timer* timer);
557 
558 /**
559  * see if timeout has been set to a value.
560  * @param timer: the timer to examine.
561  * @return: false if disabled or not set.
562  */
563 int comm_timer_is_set(struct comm_timer* timer);
564 
565 /**
566  * Get size of memory used by comm timer.
567  * @param timer: the timer to examine.
568  * @return size in bytes.
569  */
570 size_t comm_timer_get_mem(struct comm_timer* timer);
571 
572 /**
573  * Create a signal handler. Call signal_bind() later to bind to a signal.
574  * @param base: communication base to use.
575  * @param callback: called when signal is caught.
576  * @param cb_arg: user argument to callback
577  * @return: the signal struct or NULL on error.
578  */
579 struct comm_signal* comm_signal_create(struct comm_base* base,
580 	void (*callback)(int, void*), void* cb_arg);
581 
582 /**
583  * Bind signal struct to catch a signal. A signle comm_signal can be bound
584  * to multiple signals, calling comm_signal_bind multiple times.
585  * @param comsig: the communication point, with callback information.
586  * @param sig: signal number.
587  * @return: true on success. false on error.
588  */
589 int comm_signal_bind(struct comm_signal* comsig, int sig);
590 
591 /**
592  * Delete the signal communication point.
593  * @param comsig: to delete.
594  */
595 void comm_signal_delete(struct comm_signal* comsig);
596 
597 /**
598  * perform accept(2) with error checking.
599  * @param c: commpoint with accept fd.
600  * @param addr: remote end returned here.
601  * @param addrlen: length of remote end returned here.
602  * @return new fd, or -1 on error.
603  *	if -1, error message has been printed if necessary, simply drop
604  *	out of the reading handler.
605  */
606 int comm_point_perform_accept(struct comm_point* c,
607 	struct sockaddr_storage* addr, socklen_t* addrlen);
608 
609 /**** internal routines ****/
610 
611 /**
612  * This routine is published for checks and tests, and is only used internally.
613  * handle libevent callback for udp comm point.
614  * @param fd: file descriptor.
615  * @param event: event bits from libevent:
616  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
617  * @param arg: the comm_point structure.
618  */
619 void comm_point_udp_callback(int fd, short event, void* arg);
620 
621 /**
622  * This routine is published for checks and tests, and is only used internally.
623  * handle libevent callback for udp ancillary data comm point.
624  * @param fd: file descriptor.
625  * @param event: event bits from libevent:
626  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
627  * @param arg: the comm_point structure.
628  */
629 void comm_point_udp_ancil_callback(int fd, short event, void* arg);
630 
631 /**
632  * This routine is published for checks and tests, and is only used internally.
633  * handle libevent callback for tcp accept comm point
634  * @param fd: file descriptor.
635  * @param event: event bits from libevent:
636  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
637  * @param arg: the comm_point structure.
638  */
639 void comm_point_tcp_accept_callback(int fd, short event, void* arg);
640 
641 /**
642  * This routine is published for checks and tests, and is only used internally.
643  * handle libevent callback for tcp data comm point
644  * @param fd: file descriptor.
645  * @param event: event bits from libevent:
646  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
647  * @param arg: the comm_point structure.
648  */
649 void comm_point_tcp_handle_callback(int fd, short event, void* arg);
650 
651 /**
652  * This routine is published for checks and tests, and is only used internally.
653  * handle libevent callback for timer comm.
654  * @param fd: file descriptor (always -1).
655  * @param event: event bits from libevent:
656  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
657  * @param arg: the comm_timer structure.
658  */
659 void comm_timer_callback(int fd, short event, void* arg);
660 
661 /**
662  * This routine is published for checks and tests, and is only used internally.
663  * handle libevent callback for signal comm.
664  * @param fd: file descriptor (used for the signal number).
665  * @param event: event bits from libevent:
666  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
667  * @param arg: the internal commsignal structure.
668  */
669 void comm_signal_callback(int fd, short event, void* arg);
670 
671 /**
672  * This routine is published for checks and tests, and is only used internally.
673  * libevent callback for AF_UNIX fds
674  * @param fd: file descriptor.
675  * @param event: event bits from libevent:
676  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
677  * @param arg: the comm_point structure.
678  */
679 void comm_point_local_handle_callback(int fd, short event, void* arg);
680 
681 /**
682  * This routine is published for checks and tests, and is only used internally.
683  * libevent callback for raw fd access.
684  * @param fd: file descriptor.
685  * @param event: event bits from libevent:
686  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
687  * @param arg: the comm_point structure.
688  */
689 void comm_point_raw_handle_callback(int fd, short event, void* arg);
690 
691 /**
692  * This routine is published for checks and tests, and is only used internally.
693  * libevent callback for timeout on slow accept.
694  * @param fd: file descriptor.
695  * @param event: event bits from libevent:
696  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
697  * @param arg: the comm_point structure.
698  */
699 void comm_base_handle_slow_accept(int fd, short event, void* arg);
700 
701 #ifdef USE_WINSOCK
702 /**
703  * Callback for openssl BIO to on windows detect WSAEWOULDBLOCK and notify
704  * the winsock_event of this for proper TCP nonblocking implementation.
705  * @param c: comm_point, fd must be set its struct event is registered.
706  * @param ssl: openssl SSL, fd must be set so it has a bio.
707  */
708 void comm_point_tcp_win_bio_cb(struct comm_point* c, void* ssl);
709 #endif
710 
711 /** see if errno for tcp connect has to be logged or not. This uses errno */
712 int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen);
713 
714 #endif /* NET_EVENT_H */
715