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