]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.h
2 * DEBUG: section 54 Interprocess Communication
6 #ifndef SQUID_IPC_ASYNCUDSOP_H
7 #define SQUID_IPC_ASYNCUDSOP_H
9 #include "base/AsyncJob.h"
11 #include "comm/forward.h"
12 #include "ipc/FdNotes.h"
13 #include "ipc/TypedMsgHdr.h"
14 #include "SquidString.h"
16 class CommTimeoutCbParams
;
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
27 UdsOp(const String
&pathAddr
);
31 struct sockaddr_un address
; ///< UDS address from path; treat as read-only
34 virtual void timedout() {} ///< called after setTimeout() if timed out
36 Comm::ConnectionPointer
&conn(); ///< creates if needed and returns raw UDS socket descriptor
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
42 void setOptions(int newOptions
); ///< changes socket options
45 /// Comm timeout callback; calls timedout()
46 void noteTimeout(const CommTimeoutCbParams
&p
);
49 int options
; ///< UDS options
50 Comm::ConnectionPointer conn_
; ///< UDS descriptor
53 UdsOp(const UdsOp
&); // not implemented
54 UdsOp
&operator= (const UdsOp
&); // not implemented
57 /// converts human-readable filename path into UDS address
58 struct sockaddr_un
PathToAddress(const String
&pathAddr
);
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
65 UdsSender(const String
& pathAddr
, const TypedMsgHdr
& aMessage
);
68 virtual void start(); // UdsOp (AsyncJob) API
69 virtual bool doneAll() const; // UdsOp (AsyncJob) API
70 virtual void timedout(); // UdsOp API
73 void write(); ///< schedule writing
74 void wrote(const CommIoCbParams
& params
); ///< done writing or error
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
83 UdsSender(const UdsSender
&); // not implemented
84 UdsSender
& operator= (const UdsSender
&); // not implemented
86 CBDATA_CLASS2(UdsSender
);
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
);
95 #endif /* SQUID_IPC_ASYNCUDSOP_H */