]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / UdsOp.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #ifndef SQUID_IPC_ASYNCUDSOP_H
9 #define SQUID_IPC_ASYNCUDSOP_H
10
11 #include "SquidString.h"
12 #include "base/AsyncJob.h"
13 #include "cbdata.h"
14 #include "comm/forward.h"
15 #include "ipc/TypedMsgHdr.h"
16 #include "ipc/FdNotes.h"
17
18 class CommTimeoutCbParams;
19 class CommIoCbParams;
20
21 namespace Ipc
22 {
23
24 /// code shared by unix-domain socket senders (e.g., UdsSender or Coordinator)
25 /// and receivers (e.g. Port or Coordinator)
26 class UdsOp: public AsyncJob
27 {
28 public:
29 UdsOp(const String &pathAddr);
30 virtual ~UdsOp();
31
32 public:
33 struct sockaddr_un address; ///< UDS address from path; treat as read-only
34
35 protected:
36 virtual void timedout() {} ///< called after setTimeout() if timed out
37
38 Comm::ConnectionPointer &conn(); ///< creates if needed and returns raw UDS socket descriptor
39
40 /// call timedout() if no UDS messages in a given number of seconds
41 void setTimeout(int seconds, const char *handlerName);
42 void clearTimeout(); ///< remove previously set timeout, if any
43
44 void setOptions(int newOptions); ///< changes socket options
45
46 private:
47 /// Comm timeout callback; calls timedout()
48 void noteTimeout(const CommTimeoutCbParams &p);
49
50 private:
51 int options; ///< UDS options
52 Comm::ConnectionPointer conn_; ///< UDS descriptor
53
54 private:
55 UdsOp(const UdsOp &); // not implemented
56 UdsOp &operator= (const UdsOp &); // not implemented
57 };
58
59 /// converts human-readable filename path into UDS address
60 extern struct sockaddr_un PathToAddress(const String &pathAddr);
61
62 // XXX: move UdsSender code to UdsSender.{cc,h}
63 /// attempts to send an IPC message a few times, with a timeout
64 class UdsSender: public UdsOp
65 {
66 public:
67 UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage);
68
69 protected:
70 virtual void start(); // UdsOp (AsyncJob) API
71 virtual bool doneAll() const; // UdsOp (AsyncJob) API
72 virtual void timedout(); // UdsOp API
73
74 private:
75 void write(); ///< schedule writing
76 void wrote(const CommIoCbParams& params); ///< done writing or error
77
78 private:
79 TypedMsgHdr message; ///< what to send
80 int retries; ///< how many times to try after a write error
81 int timeout; ///< total time to send the message
82 bool writing; ///< whether Comm started and did not finish writing
83
84 private:
85 UdsSender(const UdsSender&); // not implemented
86 UdsSender& operator= (const UdsSender&); // not implemented
87
88 CBDATA_CLASS2(UdsSender);
89 };
90
91 void SendMessage(const String& toAddress, const TypedMsgHdr& message);
92 /// import socket fd from another strand into our Comm state
93 const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId);
94
95 }
96
97 #endif /* SQUID_IPC_ASYNCUDSOP_H */