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