1 /* 2 * Copyright (C) 1996-2021 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 bool operator <(const OpenListenerParams &p) const; ///< useful for map<> 28 29 // bits to re-create the fde entry 30 int sock_type = 0; 31 int proto = 0; 32 int fdNote = 0; ///< index into fd_note() comment strings 33 34 // bits to re-create the listener Comm::Connection descriptor 35 Ip::Address addr; ///< will be memset and memcopied 36 int flags = 0; 37 38 /// handler to subscribe to Comm::ConnAcceptor when we get the response 39 Subscription::Pointer handlerSubscription; 40 }; 41 42 class TypedMsgHdr; 43 44 /// a request for a listen socket with given parameters 45 class SharedListenRequest 46 { 47 public: 48 SharedListenRequest(); ///< from OpenSharedListen() which then sets public data 49 explicit SharedListenRequest(const TypedMsgHdr &hdrMsg); ///< from recvmsg() 50 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg() 51 52 public: 53 int requestorId; ///< kidId of the requestor 54 55 OpenListenerParams params; ///< actual comm_open_sharedListen() parameters 56 57 int mapId; ///< to map future response to the requestor's callback 58 }; 59 60 /// a response to SharedListenRequest 61 class SharedListenResponse 62 { 63 public: 64 SharedListenResponse(int fd, int errNo, int mapId); 65 explicit SharedListenResponse(const TypedMsgHdr &hdrMsg); ///< from recvmsg() 66 void pack(TypedMsgHdr &hdrMsg) const; ///< prepare for sendmsg() 67 68 public: 69 int fd; ///< opened listening socket or -1 70 int errNo; ///< errno value from comm_open_sharedListen() call 71 int mapId; ///< to map future response to the requestor's callback 72 }; 73 74 /// prepare and send SharedListenRequest to Coordinator 75 void JoinSharedListen(const OpenListenerParams &, AsyncCall::Pointer &); 76 77 /// process Coordinator response to SharedListenRequest 78 void SharedListenJoined(const SharedListenResponse &response); 79 80 } // namespace Ipc; 81 82 #endif /* SQUID_IPC_SHARED_LISTEN_H */ 83 84