master
h 58 lines 2.07 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_SOCKET_H
4 #define NETDATA_SOCKET_H
5
6 #include "../libnetdata.h"
7
8 #define ND_CHECK_CANCELLABILITY_WHILE_WAITING_EVERY_MS 100
9
10 ssize_t send_timeout(NETDATA_SSL *ssl,int sockfd, void *buf, size_t len, int flags, time_t timeout);
11 int wait_on_socket_or_cancel_with_timeout(NETDATA_SSL *ssl, int fd, int timeout_ms, short int poll_events, short int *revents);
12
13 bool fd_is_socket(int fd);
14 bool is_socket_closed(int fd);
15
16 // Returns -1 for errors, 0 if TCP_DEFER_ACCEPT is unset, 1 if TCP_DEFER_ACCEPT is set
17 int sock_set_tcp_defer_accept(int fd, bool defer);
18
19 // Returns -1 for errors, 0 if FD_CLOEXEC is unset, 1 if FD_CLOEXEC is set
20 int sock_setcloexec(int fd, bool cloexec);
21
22 // Returns -1 for errors, 0 if O_NONBLOCK is unset, 1 if O_NONBLOCK is set
23 int sock_setnonblock(int fd, bool nonblock);
24
25 // Returns -1 for errors, 0 if SO_REUSEADDR is unset, 1 if SO_REUSEADDR is set
26 int sock_setreuse_addr(int fd, bool reuse);
27
28 // Returns -1 for errors, 0 if SO_REUSEPORT is unset, 1 if SO_REUSEPORT is set
29 int sock_setreuse_port(int fd, bool reuse);
30
31 // Returns -1 for errors, current buffer size if successful
32 int sock_enlarge_rcv_buf(int fd);
33
34 // Returns -1 for errors, current buffer size if successful
35 int sock_enlarge_snd_buf(int fd);
36
37 // returns -1 for errors, 0 if cork is unset, 1 if cork is set
38 int sock_setcork(int fd, bool cork);
39
40 int connection_allowed(int fd, char *client_ip, char *client_host, size_t hostsize,
41 SIMPLE_PATTERN *access_list, const char *patname, int allow_dns);
42 int accept_socket(int fd, int flags, char *client_ip, size_t ipsize, char *client_port, size_t portsize,
43 char *client_host, size_t hostsize, SIMPLE_PATTERN *access_list, int allow_dns);
44
45 #ifndef HAVE_ACCEPT4
46 int accept4(int sock, struct sockaddr *addr, socklen_t *addrlen, int flags);
47 #endif /* #ifndef HAVE_ACCEPT4 */
48
49 #ifdef SOCK_CLOEXEC
50 #define DEFAULT_SOCKET_FLAGS SOCK_CLOEXEC
51 #else
52 #define DEFAULT_SOCKET_FLAGS 0
53 #endif
54
55
56 bool ip_to_hostname(const char *ip, char *dst, size_t dst_len);
57
58 #endif //NETDATA_SOCKET_H