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