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