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