]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / ipc / UdsOp.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 54 Interprocess Communication */
10
11 #ifndef SQUID_IPC_ASYNCUDSOP_H
12 #define SQUID_IPC_ASYNCUDSOP_H
13
14 #include "base/AsyncJob.h"
15 #include "cbdata.h"
16 #include "comm/forward.h"
17 #include "ipc/FdNotes.h"
18 #include "ipc/TypedMsgHdr.h"
19 #include "SquidString.h"
20
21 class CommTimeoutCbParams;
22 class CommIoCbParams;
23
24 namespace Ipc
25 {
26
27 /// code shared by unix-domain socket senders (e.g., UdsSender or Coordinator)
28 /// and receivers (e.g. Port or Coordinator)
29 class UdsOp: public AsyncJob
30 {
31 public:
32 UdsOp(const String &pathAddr);
33 virtual ~UdsOp();
34
35 public:
36 struct sockaddr_un address; ///< UDS address from path; treat as read-only
37
38 protected:
39 virtual void timedout() {} ///< called after setTimeout() if timed out
40
41 Comm::ConnectionPointer &conn(); ///< creates if needed and returns raw UDS socket descriptor
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
47 void setOptions(int newOptions); ///< changes socket options
48
49 private:
50 /// Comm timeout callback; calls timedout()
51 void noteTimeout(const CommTimeoutCbParams &p);
52
53 private:
54 int options; ///< UDS options
55 Comm::ConnectionPointer conn_; ///< UDS descriptor
56
57 private:
58 UdsOp(const UdsOp &); // not implemented
59 UdsOp &operator= (const UdsOp &); // not implemented
60 };
61
62 /// converts human-readable filename path into UDS address
63 struct sockaddr_un PathToAddress(const String &pathAddr);
64
65 // XXX: move UdsSender code to UdsSender.{cc,h}
66 /// attempts to send an IPC message a few times, with a timeout
67 class UdsSender: public UdsOp
68 {
69 public:
70 UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage);
71
72 protected:
73 virtual void swanSong(); // UdsOp (AsyncJob) API
74 virtual void start(); // UdsOp (AsyncJob) API
75 virtual bool doneAll() const; // UdsOp (AsyncJob) API
76 virtual void timedout(); // UdsOp API
77
78 private:
79 void startSleep();
80 void cancelSleep();
81 static void DelayedRetry(void *data);
82 void delayedRetry();
83
84 void write(); ///< schedule writing
85 void wrote(const CommIoCbParams& params); ///< done writing or error
86
87 private:
88 TypedMsgHdr message; ///< what to send
89 int retries; ///< how many times to try after a write error
90 int timeout; ///< total time to send the message
91 bool sleeping; ///< whether we are waiting to retry a failed write
92 bool writing; ///< whether Comm started and did not finish writing
93
94 private:
95 UdsSender(const UdsSender&); // not implemented
96 UdsSender& operator= (const UdsSender&); // not implemented
97
98 CBDATA_CLASS2(UdsSender);
99 };
100
101 void SendMessage(const String& toAddress, const TypedMsgHdr& message);
102 /// import socket fd from another strand into our Comm state
103 const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId);
104
105 }
106
107 #endif /* SQUID_IPC_ASYNCUDSOP_H */