Squid Web Cache master
Loading...
Searching...
No Matches
UdsOp.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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
23class CommIoCbParams;
24
25namespace Ipc
26{
27
30class UdsOp: public AsyncJob
31{
32public:
33 UdsOp(const String &pathAddr);
34 ~UdsOp() override;
35
36public:
38
39protected:
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
50private:
52 void noteTimeout(const CommTimeoutCbParams &p);
53
54private:
55 int options;
57
58private:
59 UdsOp(const UdsOp &); // not implemented
60 UdsOp &operator= (const UdsOp &); // not implemented
61};
62
64struct sockaddr_un PathToAddress(const String &pathAddr);
65
66// XXX: move UdsSender code to UdsSender.{cc,h}
68class UdsSender: public UdsOp
69{
71
72public:
73 UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage);
74
76
77protected:
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
83private:
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
92private:
94 int retries;
95 time_t timeout;
96 bool sleeping;
97 bool writing;
98
99private:
100 UdsSender(const UdsSender&); // not implemented
101 UdsSender& operator= (const UdsSender&); // not implemented
102};
103
104void SendMessage(const String& toAddress, const TypedMsgHdr& message);
106const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId);
107
108}
109
110#endif /* SQUID_SRC_IPC_UDSOP_H */
111
struct msghdr with a known type, fixed-size I/O and control buffers
Definition TypedMsgHdr.h:35
void setTimeout(time_t seconds, const char *handlerName)
call timedout() if no UDS messages in a given number of seconds
Definition UdsOp.cc:55
~UdsOp() override
Definition UdsOp.cc:28
void noteTimeout(const CommTimeoutCbParams &p)
Comm timeout callback; calls timedout()
Definition UdsOp.cc:68
Comm::ConnectionPointer conn_
UDS descriptor.
Definition UdsOp.h:56
UdsOp & operator=(const UdsOp &)
UdsOp(const UdsOp &)
int options
UDS options.
Definition UdsOp.h:55
void setOptions(int newOptions)
changes socket options
Definition UdsOp.cc:36
virtual void timedout()
called after setTimeout() if timed out
Definition UdsOp.h:40
void clearTimeout()
remove previously set timeout, if any
Definition UdsOp.cc:63
Comm::ConnectionPointer & conn()
creates if needed and returns raw UDS socket descriptor
Definition UdsOp.cc:42
struct sockaddr_un address
UDS address from path; treat as read-only.
Definition UdsOp.h:37
attempts to send an IPC message a few times, with a timeout
Definition UdsOp.h:69
time_t timeout
total time to send the message
Definition UdsOp.h:95
void cancelSleep()
stop sleeping (or do nothing if we were not)
Definition UdsOp.cc:151
bool writing
whether Comm started and did not finish writing
Definition UdsOp.h:97
void start() override
called by AsyncStart; do not call directly
Definition UdsOp.cc:106
UdsSender(const UdsSender &)
CBDATA_CHILD(UdsSender)
static void DelayedRetry(void *data)
legacy wrapper for Ipc::UdsSender::delayedRetry()
Definition UdsOp.cc:161
int retries
how many times to try after a write error
Definition UdsOp.h:94
void delayedRetry()
make another sending attempt after a pause
Definition UdsOp.cc:174
void startSleep()
pause for a while before resending the message
Definition UdsOp.cc:141
void wrote(const CommIoCbParams &params)
done writing or error
Definition UdsOp.cc:129
void timedout() override
called after setTimeout() if timed out
Definition UdsOp.cc:183
void write()
schedule writing
Definition UdsOp.cc:119
bool sleeping
whether we are waiting to retry a failed write
Definition UdsOp.h:96
CodeContextPointer codeContext
Definition UdsOp.h:75
bool doneAll() const override
whether positive goal has been reached
Definition UdsOp.cc:114
UdsSender & operator=(const UdsSender &)
void swanSong() override
Definition UdsOp.cc:97
TypedMsgHdr message
what to send
Definition UdsOp.h:93
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:189
struct sockaddr_un PathToAddress(const String &pathAddr)
converts human-readable filename path into UDS address
Definition UdsOp.cc:74
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:195