]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_COMM_H
10 #define SQUID_SRC_COMM_H
12 #include "comm/IoCallback.h"
13 #include "CommCalls.h"
14 #include "StoreIOBuffer.h"
21 bool comm_iocallbackpending(void); /* inline candidate */
23 int commSetNonBlocking(int fd
);
24 int commUnsetNonBlocking(int fd
);
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.
33 void commSetCloseOnExec(int fd
);
35 void _comm_close(int fd
, char const *file
, int line
);
36 #define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
37 void old_comm_reset_close(int fd
);
38 void comm_reset_close(const Comm::ConnectionPointer
&conn
);
40 int comm_connect_addr(int sock
, const Ip::Address
&addr
);
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
);
46 /// update Comm state after getting a comm_open() FD from another process
47 void comm_import_opened(const Comm::ConnectionPointer
&, const char *note
, struct addrinfo
*AI
);
50 * Open a port specially bound for listening or sending through a specific port.
51 * Please use for all listening sockets and bind() outbound sockets.
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 [::]
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.
63 int comm_open_listener(int sock_type
, int proto
, Ip::Address
&addr
, int flags
, const char *note
);
64 void comm_open_listener(int sock_type
, int proto
, Comm::ConnectionPointer
&conn
, const char *note
);
66 unsigned short comm_local_port(int fd
);
68 int comm_udp_sendto(int sock
, const Ip::Address
&to
, const void *buf
, int buflen
);
69 void commCallCloseHandlers(int fd
);
71 /// clear a timeout handler by FD number
72 void commUnsetFdTimeout(int fd
);
75 * Set or clear the timeout for some action on an active connection.
76 * API to replace commSetTimeout() when a Comm::ConnectionPointer is available.
78 int commSetConnTimeout(const Comm::ConnectionPointer
&conn
, time_t seconds
, AsyncCall::Pointer
&callback
);
79 int commUnsetConnTimeout(const Comm::ConnectionPointer
&conn
);
82 void commCloseAllSockets(void);
83 void checkTimeouts(void);
85 AsyncCall::Pointer
comm_add_close_handler(int fd
, CLCB
*, void *);
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
&);
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);
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.
100 void commStartHalfClosedMonitor(int fd
);
101 bool commHasHalfClosedMonitor(int fd
);
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
); }
106 /* A comm engine that calls comm_select */
108 class CommSelectEngine
: public AsyncEngine
112 int checkEvents(int timeout
) override
;
115 #endif /* SQUID_SRC_COMM_H */