]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.h
2 * Copyright (C) 1996-2014 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"
16 #include "comm/forward.h"
17 #include "ipc/FdNotes.h"
18 #include "ipc/TypedMsgHdr.h"
19 #include "SquidString.h"
21 class CommTimeoutCbParams
;
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
32 UdsOp(const String
&pathAddr
);
36 struct sockaddr_un address
; ///< UDS address from path; treat as read-only
39 virtual void timedout() {} ///< called after setTimeout() if timed out
41 Comm::ConnectionPointer
&conn(); ///< creates if needed and returns raw UDS socket descriptor
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
47 void setOptions(int newOptions
); ///< changes socket options
50 /// Comm timeout callback; calls timedout()
51 void noteTimeout(const CommTimeoutCbParams
&p
);
54 int options
; ///< UDS options
55 Comm::ConnectionPointer conn_
; ///< UDS descriptor
58 UdsOp(const UdsOp
&); // not implemented
59 UdsOp
&operator= (const UdsOp
&); // not implemented
62 /// converts human-readable filename path into UDS address
63 struct sockaddr_un
PathToAddress(const String
&pathAddr
);
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
70 UdsSender(const String
& pathAddr
, const TypedMsgHdr
& aMessage
);
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
81 static void DelayedRetry(void *data
);
84 void write(); ///< schedule writing
85 void wrote(const CommIoCbParams
& params
); ///< done writing or error
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
95 UdsSender(const UdsSender
&); // not implemented
96 UdsSender
& operator= (const UdsSender
&); // not implemented
98 CBDATA_CLASS2(UdsSender
);
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
);
107 #endif /* SQUID_IPC_ASYNCUDSOP_H */