]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm.h
Bug 5069: Keep listening after getsockname() error (#1713)
[thirdparty/squid.git] / src / comm.h
CommitLineData
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
16namespace Ip
17{
fafe8849
FC
18class Address;
19}
20
8a648e8d
FC
21bool comm_iocallbackpending(void); /* inline candidate */
22
23int commSetNonBlocking(int fd);
24int 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 33void commSetCloseOnExec(int fd);
1a848e4e 34
8a648e8d 35void _comm_close(int fd, char const *file, int line);
cfd66529 36#define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
8a648e8d
FC
37void old_comm_reset_close(int fd);
38void comm_reset_close(const Comm::ConnectionPointer &conn);
a553a5a3 39
8a648e8d
FC
40int comm_connect_addr(int sock, const Ip::Address &addr);
41void comm_init(void);
42void comm_exit(void);
a553a5a3 43
8a648e8d
FC
44int comm_open(int, int, Ip::Address &, int, const char *note);
45int 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 47void 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 63int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note);
e02ed2e3 64void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note);
31be869c 65
8a648e8d 66unsigned short comm_local_port(int fd);
a553a5a3 67
8a648e8d
FC
68int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen);
69void commCallCloseHandlers(int fd);
933dd095
AJ
70
71/// clear a timeout handler by FD number
8a648e8d 72void 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 78int commSetConnTimeout(const Comm::ConnectionPointer &conn, time_t seconds, AsyncCall::Pointer &callback);
8a648e8d 79int commUnsetConnTimeout(const Comm::ConnectionPointer &conn);
7957e704 80
8a648e8d
FC
81int ignoreErrno(int);
82void commCloseAllSockets(void);
83void checkTimeouts(void);
a553a5a3 84
398bc066 85AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *);
8a648e8d
FC
86void comm_add_close_handler(int fd, AsyncCall::Pointer &);
87void comm_remove_close_handler(int fd, CLCB *, void *);
88void comm_remove_close_handler(int fd, AsyncCall::Pointer &);
89
8a648e8d
FC
90int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from);
91int comm_udp_recv(int fd, void *buf, size_t len, int flags);
92ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags);
93bool 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
100void commStartHalfClosedMonitor(int fd);
101bool commHasHalfClosedMonitor(int fd);
82ec8dfc
AR
102// XXX: remove these wrappers which minimize client_side.cc changes in a commit
103inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); }
104inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); }
105
8ff3fa2e 106/* A comm engine that calls comm_select */
107
108class CommSelectEngine : public AsyncEngine
109{
110
111public:
337b9aa4 112 int checkEvents(int timeout) override;
8ff3fa2e 113};
114
ff9d9458 115#endif /* SQUID_SRC_COMM_H */
f53969cc 116