]>
Commit | Line | Data |
---|---|---|
10cefb7b | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
10cefb7b | 3 | * |
bbc27441 AJ |
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. | |
10cefb7b | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
10cefb7b | 11 | #ifndef SQUID_IPC_ASYNCUDSOP_H |
12 | #define SQUID_IPC_ASYNCUDSOP_H | |
13 | ||
1bac0258 | 14 | #include "base/AsyncJob.h" |
87388f15 | 15 | #include "base/forward.h" |
582c2af2 | 16 | #include "cbdata.h" |
e0d28505 | 17 | #include "comm/forward.h" |
51ea0904 | 18 | #include "ipc/FdNotes.h" |
602d9612 A |
19 | #include "ipc/TypedMsgHdr.h" |
20 | #include "SquidString.h" | |
10cefb7b | 21 | |
1bac0258 AR |
22 | class CommTimeoutCbParams; |
23 | class CommIoCbParams; | |
10cefb7b | 24 | |
25 | namespace Ipc | |
26 | { | |
27 | ||
ba568924 AR |
28 | /// code shared by unix-domain socket senders (e.g., UdsSender or Coordinator) |
29 | /// and receivers (e.g. Port or Coordinator) | |
10cefb7b | 30 | class UdsOp: public AsyncJob |
31 | { | |
10cefb7b | 32 | public: |
ba568924 | 33 | UdsOp(const String &pathAddr); |
10cefb7b | 34 | virtual ~UdsOp(); |
35 | ||
1bac0258 AR |
36 | public: |
37 | struct sockaddr_un address; ///< UDS address from path; treat as read-only | |
38 | ||
10cefb7b | 39 | protected: |
ba568924 AR |
40 | virtual void timedout() {} ///< called after setTimeout() if timed out |
41 | ||
e0d28505 | 42 | Comm::ConnectionPointer &conn(); ///< creates if needed and returns raw UDS socket descriptor |
ba568924 AR |
43 | |
44 | /// call timedout() if no UDS messages in a given number of seconds | |
45 | void setTimeout(int seconds, const char *handlerName); | |
46 | void clearTimeout(); ///< remove previously set timeout, if any | |
47 | ||
5667a628 | 48 | void setOptions(int newOptions); ///< changes socket options |
ba568924 AR |
49 | |
50 | private: | |
51 | /// Comm timeout callback; calls timedout() | |
52 | void noteTimeout(const CommTimeoutCbParams &p); | |
53 | ||
10cefb7b | 54 | private: |
ba568924 | 55 | int options; ///< UDS options |
e0d28505 | 56 | Comm::ConnectionPointer conn_; ///< UDS descriptor |
10cefb7b | 57 | |
58 | private: | |
ba568924 AR |
59 | UdsOp(const UdsOp &); // not implemented |
60 | UdsOp &operator= (const UdsOp &); // not implemented | |
10cefb7b | 61 | }; |
62 | ||
1bac0258 | 63 | /// converts human-readable filename path into UDS address |
82afb125 | 64 | struct sockaddr_un PathToAddress(const String &pathAddr); |
1bac0258 | 65 | |
ba568924 AR |
66 | // XXX: move UdsSender code to UdsSender.{cc,h} |
67 | /// attempts to send an IPC message a few times, with a timeout | |
10cefb7b | 68 | class UdsSender: public UdsOp |
69 | { | |
5c2f68b7 AJ |
70 | CBDATA_CLASS(UdsSender); |
71 | ||
10cefb7b | 72 | public: |
1bac0258 | 73 | UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage); |
10cefb7b | 74 | |
87388f15 EB |
75 | CodeContextPointer codeContext; |
76 | ||
ba568924 | 77 | protected: |
3e81ed3a | 78 | virtual void swanSong(); // UdsOp (AsyncJob) API |
ba568924 AR |
79 | virtual void start(); // UdsOp (AsyncJob) API |
80 | virtual bool doneAll() const; // UdsOp (AsyncJob) API | |
81 | virtual void timedout(); // UdsOp API | |
10cefb7b | 82 | |
83 | private: | |
6905e266 | 84 | void startSleep(); |
3e81ed3a AR |
85 | void cancelSleep(); |
86 | static void DelayedRetry(void *data); | |
87 | void delayedRetry(); | |
88 | ||
ba568924 AR |
89 | void write(); ///< schedule writing |
90 | void wrote(const CommIoCbParams& params); ///< done writing or error | |
10cefb7b | 91 | |
92 | private: | |
1bac0258 | 93 | TypedMsgHdr message; ///< what to send |
ba568924 AR |
94 | int retries; ///< how many times to try after a write error |
95 | int timeout; ///< total time to send the message | |
3e81ed3a | 96 | bool sleeping; ///< whether we are waiting to retry a failed write |
ba568924 | 97 | bool writing; ///< whether Comm started and did not finish writing |
10cefb7b | 98 | |
ba568924 AR |
99 | private: |
100 | UdsSender(const UdsSender&); // not implemented | |
101 | UdsSender& operator= (const UdsSender&); // not implemented | |
10cefb7b | 102 | }; |
103 | ||
1bac0258 | 104 | void SendMessage(const String& toAddress, const TypedMsgHdr& message); |
51ea0904 | 105 | /// import socket fd from another strand into our Comm state |
1b76e6c1 | 106 | const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId); |
10cefb7b | 107 | |
10cefb7b | 108 | } |
109 | ||
110 | #endif /* SQUID_IPC_ASYNCUDSOP_H */ | |
f53969cc | 111 |