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