2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 54 Interprocess Communication */
11 #ifndef SQUID_IPC_ASYNCUDSOP_H
12 #define SQUID_IPC_ASYNCUDSOP_H
14 #include "base/AsyncJob.h"
15 #include "base/forward.h"
17 #include "comm/forward.h"
18 #include "ipc/FdNotes.h"
19 #include "ipc/TypedMsgHdr.h"
20 #include "SquidString.h"
22 class CommTimeoutCbParams
;
28 /// code shared by unix-domain socket senders (e.g., UdsSender or Coordinator)
29 /// and receivers (e.g. Port or Coordinator)
30 class UdsOp
: public AsyncJob
33 UdsOp(const String
&pathAddr
);
37 struct sockaddr_un address
; ///< UDS address from path; treat as read-only
40 virtual void timedout() {} ///< called after setTimeout() if timed out
42 Comm::ConnectionPointer
&conn(); ///< creates if needed and returns raw UDS socket descriptor
44 /// call timedout() if no UDS messages in a given number of seconds
45 void setTimeout(int seconds
, const char *handlerName
);
46 void clearTimeout(); ///< remove previously set timeout, if any
48 void setOptions(int newOptions
); ///< changes socket options
51 /// Comm timeout callback; calls timedout()
52 void noteTimeout(const CommTimeoutCbParams
&p
);
55 int options
; ///< UDS options
56 Comm::ConnectionPointer conn_
; ///< UDS descriptor
59 UdsOp(const UdsOp
&); // not implemented
60 UdsOp
&operator= (const UdsOp
&); // not implemented
63 /// converts human-readable filename path into UDS address
64 struct sockaddr_un
PathToAddress(const String
&pathAddr
);
66 // XXX: move UdsSender code to UdsSender.{cc,h}
67 /// attempts to send an IPC message a few times, with a timeout
68 class UdsSender
: public UdsOp
70 CBDATA_CLASS(UdsSender
);
73 UdsSender(const String
& pathAddr
, const TypedMsgHdr
& aMessage
);
75 CodeContextPointer codeContext
;
78 virtual void swanSong(); // UdsOp (AsyncJob) API
79 virtual void start(); // UdsOp (AsyncJob) API
80 virtual bool doneAll() const; // UdsOp (AsyncJob) API
81 virtual void timedout(); // UdsOp API
86 static void DelayedRetry(void *data
);
89 void write(); ///< schedule writing
90 void wrote(const CommIoCbParams
& params
); ///< done writing or error
93 TypedMsgHdr message
; ///< what to send
94 int retries
; ///< how many times to try after a write error
95 int timeout
; ///< total time to send the message
96 bool sleeping
; ///< whether we are waiting to retry a failed write
97 bool writing
; ///< whether Comm started and did not finish writing
100 UdsSender(const UdsSender
&); // not implemented
101 UdsSender
& operator= (const UdsSender
&); // not implemented
104 void SendMessage(const String
& toAddress
, const TypedMsgHdr
& message
);
105 /// import socket fd from another strand into our Comm state
106 const Comm::ConnectionPointer
& ImportFdIntoComm(const Comm::ConnectionPointer
&conn
, int socktype
, int protocol
, FdNoteId noteId
);
110 #endif /* SQUID_IPC_ASYNCUDSOP_H */