| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_POLL_EVENTS_H |
| 4 | #define NETDATA_POLL_EVENTS_H |
| 5 | |
| 6 | #include "nd-poll.h" |
| 7 | |
| 8 | #define POLLINFO_FLAG_SERVER_SOCKET (1U << 0) |
| 9 | #define POLLINFO_FLAG_CLIENT_SOCKET (1U << 1) |
| 10 | #define POLLINFO_FLAG_DONT_CLOSE (1U << 2) |
| 11 | #define POLLINFO_FLAG_REMOVED_FROM_POLL (1U << 3) |
| 12 | #define POLLINFO_FLAG_FIRST_REQUEST_RECEIVED (1U << 4) |
| 13 | |
| 14 | typedef struct poll POLLJOB; |
| 15 | typedef struct pollinfo POLLINFO; |
| 16 | |
| 17 | typedef void *(*poll_events_add_callback_t)(POLLINFO *pi, nd_poll_event_t *events, void *data); |
| 18 | typedef void (*poll_events_del_callback_t)(POLLINFO *pi); |
| 19 | typedef int (*poll_events_rcv_callback_t)(POLLINFO *pi, nd_poll_event_t *events); |
| 20 | typedef int (*poll_events_snd_callback_t)(POLLINFO *pi, nd_poll_event_t *events); |
| 21 | typedef void (*poll_events_tmr_callback_t)(void *timer_data); |
| 22 | |
| 23 | struct pollinfo { |
| 24 | POLLJOB *p; // the parent |
| 25 | |
| 26 | int fd; // the file descriptor |
| 27 | int socktype; // the client socket type |
| 28 | HTTP_ACL port_acl; // the access lists permitted on this web server port (it's -1 for client sockets) |
| 29 | char *client_ip; // Max INET6_ADDRSTRLEN bytes |
| 30 | char *client_port; // Max NI_MAXSERV bytes |
| 31 | char *client_host; // Max NI_MAXHOST bytes |
| 32 | |
| 33 | nd_poll_event_t events; |
| 34 | nd_poll_event_t events_we_wait_for; |
| 35 | |
| 36 | time_t connected_t; // the time the socket connected |
| 37 | time_t last_received_t; // the time the socket last received data |
| 38 | time_t last_sent_t; // the time the socket last sent data |
| 39 | |
| 40 | size_t recv_count; // the number of times the socket was ready for inbound traffic |
| 41 | size_t send_count; // the number of times the socket was ready for outbound traffic |
| 42 | |
| 43 | uint32_t flags; // internal flags |
| 44 | |
| 45 | // callbacks for this socket |
| 46 | poll_events_del_callback_t del_callback; |
| 47 | poll_events_rcv_callback_t rcv_callback; |
| 48 | poll_events_snd_callback_t snd_callback; |
| 49 | |
| 50 | // the user data |
| 51 | void *data; |
| 52 | |
| 53 | struct pollinfo *prev, *next; |
| 54 | }; |
| 55 | |
| 56 | struct poll { |
| 57 | nd_poll_t *ndpl; |
| 58 | POLLINFO *ll; |
| 59 | |
| 60 | size_t used; |
| 61 | size_t limit; |
| 62 | |
| 63 | time_t complete_request_timeout; |
| 64 | time_t idle_timeout; |
| 65 | time_t checks_every; |
| 66 | |
| 67 | time_t timer_milliseconds; |
| 68 | void *timer_data; |
| 69 | |
| 70 | SIMPLE_PATTERN *access_list; |
| 71 | int allow_dns; |
| 72 | |
| 73 | poll_events_add_callback_t add_callback; |
| 74 | poll_events_del_callback_t del_callback; |
| 75 | poll_events_rcv_callback_t rcv_callback; |
| 76 | poll_events_snd_callback_t snd_callback; |
| 77 | poll_events_tmr_callback_t tmr_callback; |
| 78 | }; |
| 79 | |
| 80 | int poll_default_snd_callback(POLLINFO *pi, nd_poll_event_t *events); |
| 81 | int poll_default_rcv_callback(POLLINFO *pi, nd_poll_event_t *events); |
| 82 | void poll_default_del_callback(POLLINFO *pi); |
| 83 | void *poll_default_add_callback(POLLINFO *pi, nd_poll_event_t *events, void *data); |
| 84 | |
| 85 | void poll_process_remove_from_poll(POLLINFO *pi); |
| 86 | |
| 87 | POLLINFO *poll_add_fd(POLLJOB *p |
| 88 | , int fd |
| 89 | , int socktype |
| 90 | , HTTP_ACL port_acl |
| 91 | , uint32_t flags |
| 92 | , const char *client_ip |
| 93 | , const char *client_port |
| 94 | , const char *client_host |
| 95 | , poll_events_add_callback_t add_callback |
| 96 | , poll_events_del_callback_t del_callback |
| 97 | , poll_events_rcv_callback_t rcv_callback |
| 98 | , poll_events_snd_callback_t snd_callback |
| 99 | , void *data |
| 100 | ); |
| 101 | |
| 102 | void poll_events(LISTEN_SOCKETS *sockets |
| 103 | , poll_events_add_callback_t add_callback |
| 104 | , poll_events_del_callback_t del_callback |
| 105 | , poll_events_rcv_callback_t rcv_callback |
| 106 | , poll_events_snd_callback_t snd_callback |
| 107 | , poll_events_tmr_callback_t tmr_callback |
| 108 | , bool (*check_to_stop_callback)(void) |
| 109 | , SIMPLE_PATTERN *access_list |
| 110 | , int allow_dns |
| 111 | , void *data |
| 112 | , time_t tcp_request_timeout_seconds |
| 113 | , time_t tcp_idle_timeout_seconds |
| 114 | , time_t timer_milliseconds |
| 115 | , void *timer_data |
| 116 | , size_t max_tcp_sockets |
| 117 | ); |
| 118 | |
| 119 | #endif //NETDATA_POLL_EVENTS_H |