]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/SharedListen.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / ipc / SharedListen.h
1 /*
2 * Copyright (C) 1996-2023 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 /* DEBUG: section 54 Interprocess Communication */
10
11 #ifndef SQUID_SRC_IPC_SHAREDLISTEN_H
12 #define SQUID_SRC_IPC_SHAREDLISTEN_H
13
14 #include "base/AsyncCall.h"
15 #include "base/Subscription.h"
16 #include "ip/Address.h"
17 #include "ipc/QuestionerId.h"
18 #include "ipc/RequestId.h"
19 #include "ipc/StartListening.h"
20
21 namespace Ipc
22 {
23
24 /// "shared listen" is when concurrent processes are listening on the same fd
25
26 /// Comm::ConnAcceptor parameters holder
27 /// all the details necessary to recreate a Comm::Connection and fde entry for the kid listener FD
28 class OpenListenerParams
29 {
30 public:
31 bool operator <(const OpenListenerParams &p) const; ///< useful for map<>
32
33 // bits to re-create the fde entry
34 int sock_type = 0;
35 int proto = 0;
36 int fdNote = 0; ///< index into fd_note() comment strings
37
38 // bits to re-create the listener Comm::Connection descriptor
39 Ip::Address addr; ///< will be memset and memcopied
40 int flags = 0;
41 };
42
43 class TypedMsgHdr;
44
45 /// a request for a listen socket with given parameters
46 class SharedListenRequest
47 {
48 public:
49 SharedListenRequest(const OpenListenerParams &, RequestId aMapId); ///< sender's constructor
50 explicit SharedListenRequest(const TypedMsgHdr &hdrMsg); ///< from recvmsg()
51 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg()
52
53 public:
54 int requestorId; ///< kidId of the requestor
55
56 OpenListenerParams params; ///< actual comm_open_sharedListen() parameters
57
58 RequestId mapId; ///< to map future response to the requestor's callback
59 };
60
61 /// a response to SharedListenRequest
62 class SharedListenResponse
63 {
64 public:
65 SharedListenResponse(int fd, int errNo, RequestId aMapId); ///< sender's constructor
66 explicit SharedListenResponse(const TypedMsgHdr &hdrMsg); ///< from recvmsg()
67 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg()
68
69 /// for Mine() tests
70 QuestionerId intendedRecepient() const { return mapId.questioner(); }
71
72 public:
73 int fd; ///< opened listening socket or -1
74 int errNo; ///< errno value from comm_open_sharedListen() call
75 RequestId mapId; ///< to map future response to the requestor's callback
76 };
77
78 /// prepare and send SharedListenRequest to Coordinator
79 void JoinSharedListen(const OpenListenerParams &, StartListeningCallback &);
80
81 /// process Coordinator response to SharedListenRequest
82 void SharedListenJoined(const SharedListenResponse &response);
83
84 } // namespace Ipc;
85
86 #endif /* SQUID_SRC_IPC_SHAREDLISTEN_H */
87