UdsOp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_IPC_UDSOP_H
12 #define SQUID_SRC_IPC_UDSOP_H
13 
14 #include "base/AsyncJob.h"
15 #include "base/forward.h"
16 #include "cbdata.h"
17 #include "comm/forward.h"
18 #include "ipc/FdNotes.h"
19 #include "ipc/TypedMsgHdr.h"
20 #include "SquidString.h"
21 
23 class CommIoCbParams;
24 
25 namespace Ipc
26 {
27 
30 class UdsOp: public AsyncJob
31 {
32 public:
33  UdsOp(const String &pathAddr);
34  ~UdsOp() override;
35 
36 public:
38 
39 protected:
40  virtual void timedout() {}
41 
43 
45  void setTimeout(time_t seconds, const char *handlerName);
46  void clearTimeout();
47 
48  void setOptions(int newOptions);
49 
50 private:
52  void noteTimeout(const CommTimeoutCbParams &p);
53 
54 private:
55  int options;
57 
58 private:
59  UdsOp(const UdsOp &); // not implemented
60  UdsOp &operator= (const UdsOp &); // not implemented
61 };
62 
64 struct sockaddr_un PathToAddress(const String &pathAddr);
65 
66 // XXX: move UdsSender code to UdsSender.{cc,h}
68 class UdsSender: public UdsOp
69 {
71 
72 public:
73  UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage);
74 
76 
77 protected:
78  void swanSong() override; // UdsOp (AsyncJob) API
79  void start() override; // UdsOp (AsyncJob) API
80  bool doneAll() const override; // UdsOp (AsyncJob) API
81  void timedout() override; // UdsOp API
82 
83 private:
84  void startSleep();
85  void cancelSleep();
86  static void DelayedRetry(void *data);
87  void delayedRetry();
88 
89  void write();
90  void wrote(const CommIoCbParams& params);
91 
92 private:
94  int retries;
95  time_t timeout;
96  bool sleeping;
97  bool writing;
98 
99 private:
100  UdsSender(const UdsSender&); // not implemented
101  UdsSender& operator= (const UdsSender&); // not implemented
102 };
103 
104 void SendMessage(const String& toAddress, const TypedMsgHdr& message);
106 const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId);
107 
108 }
109 
110 #endif /* SQUID_SRC_IPC_UDSOP_H */
111 
int options
UDS options.
Definition: UdsOp.h:55
CodeContextPointer codeContext
Definition: UdsOp.h:75
void write()
schedule writing
Definition: UdsOp.cc:118
void delayedRetry()
make another sending attempt after a pause
Definition: UdsOp.cc:173
struct sockaddr_un address
UDS address from path; treat as read-only.
Definition: UdsOp.h:37
bool sleeping
whether we are waiting to retry a failed write
Definition: UdsOp.h:96
void setOptions(int newOptions)
changes socket options
Definition: UdsOp.cc:35
bool writing
whether Comm started and did not finish writing
Definition: UdsOp.h:97
UdsOp & operator=(const UdsOp &)
void timedout() override
Definition: UdsOp.cc:182
~UdsOp() override
Definition: UdsOp.cc:27
int retries
how many times to try after a write error
Definition: UdsOp.h:94
void noteTimeout(const CommTimeoutCbParams &p)
Comm timeout callback; calls timedout()
Definition: UdsOp.cc:67
CBDATA_CHILD(UdsSender)
attempts to send an IPC message a few times, with a timeout
Definition: UdsOp.h:68
TypedMsgHdr message
what to send
Definition: UdsOp.h:93
void wrote(const CommIoCbParams &params)
done writing or error
Definition: UdsOp.cc:128
FdNoteId
We cannot send char* FD notes to other processes. Pass int IDs and convert.
Definition: FdNotes.h:20
void SendMessage(const String &toAddress, const TypedMsgHdr &message)
Definition: UdsOp.cc:188
void startSleep()
pause for a while before resending the message
Definition: UdsOp.cc:140
void clearTimeout()
remove previously set timeout, if any
Definition: UdsOp.cc:62
UdsSender(const String &pathAddr, const TypedMsgHdr &aMessage)
Definition: UdsOp.cc:84
bool doneAll() const override
whether positive goal has been reached
Definition: UdsOp.cc:113
void cancelSleep()
stop sleeping (or do nothing if we were not)
Definition: UdsOp.cc:150
void swanSong() override
Definition: UdsOp.cc:96
void setTimeout(time_t seconds, const char *handlerName)
call timedout() if no UDS messages in a given number of seconds
Definition: UdsOp.cc:54
Comm::ConnectionPointer conn_
UDS descriptor.
Definition: UdsOp.h:56
UdsSender & operator=(const UdsSender &)
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:34
time_t timeout
total time to send the message
Definition: UdsOp.h:95
const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId)
import socket fd from another strand into our Comm state
Definition: UdsOp.cc:194
struct sockaddr_un PathToAddress(const String &pathAddr)
converts human-readable filename path into UDS address
Definition: UdsOp.cc:73
void start() override
called by AsyncStart; do not call directly
Definition: UdsOp.cc:105
UdsOp(const String &pathAddr)
Definition: UdsOp.cc:19
static void DelayedRetry(void *data)
legacy wrapper for Ipc::UdsSender::delayedRetry()
Definition: UdsOp.cc:160
Definition: IpcIoFile.h:23
Comm::ConnectionPointer & conn()
creates if needed and returns raw UDS socket descriptor
Definition: UdsOp.cc:41

 

Introduction

Documentation

Support

Miscellaneous