]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.h
4 * DEBUG: section 54 Interprocess Communication
8 #ifndef SQUID_IPC_ASYNCUDSOP_H
9 #define SQUID_IPC_ASYNCUDSOP_H
12 #include "SquidString.h"
13 #include "base/AsyncJob.h"
14 #include "ipc/TypedMsgHdr.h"
15 #include "ipc/FdNotes.h"
17 class CommTimeoutCbParams
;
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
28 UdsOp(const String
&pathAddr
);
32 struct sockaddr_un address
; ///< UDS address from path; treat as read-only
35 virtual void timedout() {} ///< called after setTimeout() if timed out
37 int fd(); ///< creates if needed and returns raw UDS socket descriptor
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
43 void setOptions(int newOptions
); ///< changes socket options
46 /// Comm timeout callback; calls timedout()
47 void noteTimeout(const CommTimeoutCbParams
&p
);
50 int options
; ///< UDS options
51 int fd_
; ///< UDS descriptor
54 UdsOp(const UdsOp
&); // not implemented
55 UdsOp
&operator= (const UdsOp
&); // not implemented
58 /// converts human-readable filename path into UDS address
59 extern struct sockaddr_un
PathToAddress(const String
&pathAddr
);
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
68 UdsSender(const String
& pathAddr
, const TypedMsgHdr
& aMessage
);
71 virtual void start(); // UdsOp (AsyncJob) API
72 virtual bool doneAll() const; // UdsOp (AsyncJob) API
73 virtual void timedout(); // UdsOp API
76 void write(); ///< schedule writing
77 void wrote(const CommIoCbParams
& params
); ///< done writing or error
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
86 UdsSender(const UdsSender
&); // not implemented
87 UdsSender
& operator= (const UdsSender
&); // not implemented
89 CBDATA_CLASS2(UdsSender
);
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
);
100 #endif /* SQUID_IPC_ASYNCUDSOP_H */