]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm.h
Maintenance: Update astyle version to 3.1 (#841)
[thirdparty/squid.git] / src / comm.h
1 /*
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef __COMM_H__
10 #define __COMM_H__
11
12 #include "comm/IoCallback.h"
13 #include "CommCalls.h"
14 #include "StoreIOBuffer.h"
15
16 namespace Ip
17 {
18 class Address;
19 }
20
21 bool comm_iocallbackpending(void); /* inline candidate */
22
23 int commSetNonBlocking(int fd);
24 int commUnsetNonBlocking(int fd);
25 void commSetCloseOnExec(int fd);
26 void commSetTcpKeepalive(int fd, int idle, int interval, int timeout);
27 void _comm_close(int fd, char const *file, int line);
28 #define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
29 void old_comm_reset_close(int fd);
30 void comm_reset_close(const Comm::ConnectionPointer &conn);
31
32 int comm_connect_addr(int sock, const Ip::Address &addr);
33 void comm_init(void);
34 void comm_exit(void);
35
36 int comm_open(int, int, Ip::Address &, int, const char *note);
37 int comm_open_uds(int sock_type, int proto, struct sockaddr_un* addr, int flags);
38 /// update Comm state after getting a comm_open() FD from another process
39 void comm_import_opened(const Comm::ConnectionPointer &, const char *note, struct addrinfo *AI);
40
41 /**
42 * Open a port specially bound for listening or sending through a specific port.
43 * This is a wrapper providing IPv4/IPv6 failover around comm_openex().
44 * Please use for all listening sockets and bind() outbound sockets.
45 *
46 * It will open a socket bound for:
47 * - IPv4 if IPv6 is disabled or address is IPv4-native.
48 * - IPv6 if address is IPv6-native
49 * - IPv6 dual-stack mode if able to open [::]
50 *
51 * When an open performs failover it update the given address to feedback
52 * the new IPv4-only status of the socket. Further displays of the IP
53 * (in debugs or cachemgr) will occur in Native IPv4 format.
54 * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open.
55 */
56 int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note);
57 void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note);
58
59 int comm_openex(int, int, Ip::Address &, int, const char *);
60 unsigned short comm_local_port(int fd);
61
62 int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen);
63 void commCallCloseHandlers(int fd);
64
65 /// clear a timeout handler by FD number
66 void commUnsetFdTimeout(int fd);
67
68 /**
69 * Set or clear the timeout for some action on an active connection.
70 * API to replace commSetTimeout() when a Comm::ConnectionPointer is available.
71 */
72 int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &callback);
73 int commUnsetConnTimeout(const Comm::ConnectionPointer &conn);
74
75 int ignoreErrno(int);
76 void commCloseAllSockets(void);
77 void checkTimeouts(void);
78
79 AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *);
80 void comm_add_close_handler(int fd, AsyncCall::Pointer &);
81 void comm_remove_close_handler(int fd, CLCB *, void *);
82 void comm_remove_close_handler(int fd, AsyncCall::Pointer &);
83
84 int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from);
85 int comm_udp_recv(int fd, void *buf, size_t len, int flags);
86 ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags);
87 bool comm_has_incomplete_write(int);
88
89 /** The read channel has closed and the caller does not expect more data
90 * but needs to detect connection aborts. The current detection method uses
91 * 0-length reads: We read until the error occurs or the writer closes
92 * the connection. If there is a read error, we close the connection.
93 */
94 void commStartHalfClosedMonitor(int fd);
95 bool commHasHalfClosedMonitor(int fd);
96 // XXX: remove these wrappers which minimize client_side.cc changes in a commit
97 inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); }
98 inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); }
99
100 /* A comm engine that calls comm_select */
101
102 class CommSelectEngine : public AsyncEngine
103 {
104
105 public:
106 virtual int checkEvents(int timeout);
107 };
108
109 #endif
110