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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors