]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_COMM_H |
10 | #define SQUID_SRC_COMM_H | |
c4b7a5a9 | 11 | |
ec41b64c | 12 | #include "comm/IoCallback.h" |
602d9612 | 13 | #include "CommCalls.h" |
cfd66529 | 14 | #include "StoreIOBuffer.h" |
c4b7a5a9 | 15 | |
e4a14600 A |
16 | namespace Ip |
17 | { | |
fafe8849 FC |
18 | class Address; |
19 | } | |
20 | ||
8a648e8d FC |
21 | bool comm_iocallbackpending(void); /* inline candidate */ |
22 | ||
23 | int commSetNonBlocking(int fd); | |
24 | int commUnsetNonBlocking(int fd); | |
1a848e4e AR |
25 | |
26 | /// On platforms where FD_CLOEXEC is defined, close the given descriptor during | |
27 | /// a function call from the exec(3) family. Otherwise, do nothing; the platform | |
28 | /// itself may close-on-exec by default (e.g., MS Win32 is said to do that at | |
29 | /// https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873); other | |
30 | /// platforms are unsupported. Callers that want close-on-exec behavior must | |
31 | /// call this function on all platforms and are not responsible for the outcome | |
32 | /// on platforms without FD_CLOEXEC. | |
8a648e8d | 33 | void commSetCloseOnExec(int fd); |
1a848e4e | 34 | |
8a648e8d | 35 | void _comm_close(int fd, char const *file, int line); |
cfd66529 | 36 | #define comm_close(x) (_comm_close((x), __FILE__, __LINE__)) |
8a648e8d FC |
37 | void old_comm_reset_close(int fd); |
38 | void comm_reset_close(const Comm::ConnectionPointer &conn); | |
a553a5a3 | 39 | |
8a648e8d FC |
40 | int comm_connect_addr(int sock, const Ip::Address &addr); |
41 | void comm_init(void); | |
42 | void comm_exit(void); | |
a553a5a3 | 43 | |
8a648e8d FC |
44 | int comm_open(int, int, Ip::Address &, int, const char *note); |
45 | int comm_open_uds(int sock_type, int proto, struct sockaddr_un* addr, int flags); | |
56c3c9aa | 46 | /// update Comm state after getting a comm_open() FD from another process |
8a648e8d | 47 | void comm_import_opened(const Comm::ConnectionPointer &, const char *note, struct addrinfo *AI); |
a553a5a3 | 48 | |
31be869c AJ |
49 | /** |
50 | * Open a port specially bound for listening or sending through a specific port. | |
31be869c AJ |
51 | * Please use for all listening sockets and bind() outbound sockets. |
52 | * | |
53 | * It will open a socket bound for: | |
54 | * - IPv4 if IPv6 is disabled or address is IPv4-native. | |
55 | * - IPv6 if address is IPv6-native | |
56 | * - IPv6 dual-stack mode if able to open [::] | |
57 | * | |
58 | * When an open performs failover it update the given address to feedback | |
59 | * the new IPv4-only status of the socket. Further displays of the IP | |
60 | * (in debugs or cachemgr) will occur in Native IPv4 format. | |
61 | * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open. | |
62 | */ | |
8a648e8d | 63 | int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note); |
e02ed2e3 | 64 | void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note); |
31be869c | 65 | |
8a648e8d | 66 | unsigned short comm_local_port(int fd); |
a553a5a3 | 67 | |
8a648e8d FC |
68 | int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen); |
69 | void commCallCloseHandlers(int fd); | |
933dd095 AJ |
70 | |
71 | /// clear a timeout handler by FD number | |
8a648e8d | 72 | void commUnsetFdTimeout(int fd); |
7957e704 AJ |
73 | |
74 | /** | |
75 | * Set or clear the timeout for some action on an active connection. | |
76 | * API to replace commSetTimeout() when a Comm::ConnectionPointer is available. | |
77 | */ | |
4650a4fa | 78 | int commSetConnTimeout(const Comm::ConnectionPointer &conn, time_t seconds, AsyncCall::Pointer &callback); |
8a648e8d | 79 | int commUnsetConnTimeout(const Comm::ConnectionPointer &conn); |
7957e704 | 80 | |
8a648e8d FC |
81 | int ignoreErrno(int); |
82 | void commCloseAllSockets(void); | |
83 | void checkTimeouts(void); | |
a553a5a3 | 84 | |
398bc066 | 85 | AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *); |
8a648e8d FC |
86 | void comm_add_close_handler(int fd, AsyncCall::Pointer &); |
87 | void comm_remove_close_handler(int fd, CLCB *, void *); | |
88 | void comm_remove_close_handler(int fd, AsyncCall::Pointer &); | |
89 | ||
8a648e8d FC |
90 | int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from); |
91 | int comm_udp_recv(int fd, void *buf, size_t len, int flags); | |
92 | ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags); | |
93 | bool comm_has_incomplete_write(int); | |
cf3c0ee3 | 94 | |
82ec8dfc AR |
95 | /** The read channel has closed and the caller does not expect more data |
96 | * but needs to detect connection aborts. The current detection method uses | |
97 | * 0-length reads: We read until the error occurs or the writer closes | |
98 | * the connection. If there is a read error, we close the connection. | |
99 | */ | |
8a648e8d FC |
100 | void commStartHalfClosedMonitor(int fd); |
101 | bool commHasHalfClosedMonitor(int fd); | |
82ec8dfc AR |
102 | // XXX: remove these wrappers which minimize client_side.cc changes in a commit |
103 | inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); } | |
104 | inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); } | |
105 | ||
8ff3fa2e | 106 | /* A comm engine that calls comm_select */ |
107 | ||
108 | class CommSelectEngine : public AsyncEngine | |
109 | { | |
110 | ||
111 | public: | |
337b9aa4 | 112 | int checkEvents(int timeout) override; |
8ff3fa2e | 113 | }; |
114 | ||
ff9d9458 | 115 | #endif /* SQUID_SRC_COMM_H */ |
f53969cc | 116 |