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