]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/SharedListen.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / SharedListen.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #ifndef SQUID_IPC_SHARED_LISTEN_H
9 #define SQUID_IPC_SHARED_LISTEN_H
10
11 #include "base/AsyncCall.h"
12 #include "base/Subscription.h"
13
14 namespace Ipc
15 {
16
17 /// "shared listen" is when concurrent processes are listening on the same fd
18
19 /// Comm::ConnAcceptor parameters holder
20 /// all the details necessary to recreate a Comm::Connection and fde entry for the kid listener FD
21 class OpenListenerParams
22 {
23 public:
24 OpenListenerParams();
25
26 bool operator <(const OpenListenerParams &p) const; ///< useful for map<>
27
28 // bits to re-create the fde entry
29 int sock_type;
30 int proto;
31 int fdNote; ///< index into fd_note() comment strings
32
33 // bits to re-create the listener Comm::Connection descriptor
34 Ip::Address addr; ///< will be memset and memcopied
35 int flags;
36
37 /// handler to subscribe to Comm::ConnAcceptor when we get the response
38 Subscription::Pointer handlerSubscription;
39 };
40
41 class TypedMsgHdr;
42
43 /// a request for a listen socket with given parameters
44 class SharedListenRequest
45 {
46 public:
47 SharedListenRequest(); ///< from OpenSharedListen() which then sets public data
48 explicit SharedListenRequest(const TypedMsgHdr &hdrMsg); ///< from recvmsg()
49 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg()
50
51 public:
52 int requestorId; ///< kidId of the requestor
53
54 OpenListenerParams params; ///< actual comm_open_sharedListen() parameters
55
56 int mapId; ///< to map future response to the requestor's callback
57 };
58
59 /// a response to SharedListenRequest
60 class SharedListenResponse
61 {
62 public:
63 SharedListenResponse(int fd, int errNo, int mapId);
64 explicit SharedListenResponse(const TypedMsgHdr &hdrMsg); ///< from recvmsg()
65 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg()
66
67 public:
68 int fd; ///< opened listening socket or -1
69 int errNo; ///< errno value from comm_open_sharedListen() call
70 int mapId; ///< to map future response to the requestor's callback
71 };
72
73 /// prepare and send SharedListenRequest to Coordinator
74 extern void JoinSharedListen(const OpenListenerParams &, AsyncCall::Pointer &);
75
76 /// process Coordinator response to SharedListenRequest
77 extern void SharedListenJoined(const SharedListenResponse &response);
78
79 } // namespace Ipc;
80
81 #endif /* SQUID_IPC_SHARED_LISTEN_H */