CommCalls.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 #include "squid.h"
10 #include "anyp/PortCfg.h"
11 #include "comm/Connection.h"
12 #include "CommCalls.h"
13 #include "fde.h"
14 #include "globals.h"
15 
16 /* CommCommonCbParams */
17 
19  data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1)
20 {
21 }
22 
24  data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
25 {
26 }
27 
29 {
31 }
32 
33 void
34 CommCommonCbParams::print(std::ostream &os) const
35 {
36  if (conn != NULL)
37  os << conn;
38  else
39  os << "FD " << fd;
40 
41  if (xerrno)
42  os << ", errno=" << xerrno;
43  if (flag != Comm::OK)
44  os << ", flag=" << flag;
45  if (data)
46  os << ", data=" << data;
47 }
48 
49 /* CommAcceptCbParams */
50 
52  CommCommonCbParams(aData), xaction()
53 {
54 }
55 
56 // XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57 // implementations always return true.
58 
59 void
60 CommAcceptCbParams::print(std::ostream &os) const
61 {
63 
64  if (xaction != NULL)
65  os << ", " << xaction->id;
66 }
67 
68 /* CommConnectCbParams */
69 
71  CommCommonCbParams(aData)
72 {
73 }
74 
75 bool
77 {
78  assert(conn);
79 
80  // change parameters if this is a successful callback that was scheduled
81  // after its Comm-registered connection started to close
82 
83  if (flag != Comm::OK) {
84  assert(!conn->isOpen());
85  return true; // not a successful callback; cannot go out of sync
86  }
87 
88  assert(conn->isOpen());
89  if (!fd_table[conn->fd].closing())
90  return true; // no closing in progress; in sync (for now)
91 
92  debugs(5, 3, "converting to Comm::ERR_CLOSING: " << conn);
93  conn->noteClosure();
95  return true; // now the callback is in sync with Comm again
96 }
97 
98 /* CommIoCbParams */
99 
101  buf(NULL), size(0)
102 {
103 }
104 
105 bool
107 {
108  // change parameters if the call was scheduled before comm_close but
109  // is being fired after comm_close
110  if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) {
111  debugs(5, 3, HERE << "converting late call to Comm::ERR_CLOSING: " << conn);
113  }
114  return true; // now we are in sync and can handle the call
115 }
116 
117 void
118 CommIoCbParams::print(std::ostream &os) const
119 {
121  if (buf) {
122  os << ", size=" << size;
123  os << ", buf=" << (void*)buf;
124  }
125 }
126 
127 /* CommCloseCbParams */
128 
130  CommCommonCbParams(aData)
131 {
132 }
133 
134 /* CommTimeoutCbParams */
135 
137  CommCommonCbParams(aData)
138 {
139 }
140 
141 /* FdeCbParams */
142 
144  CommCommonCbParams(aData)
145 {
146 }
147 
148 /* CommAcceptCbPtrFun */
149 
151  const CommAcceptCbParams &aParams):
153  handler(aHandler)
154 {
155 }
156 
159  handler(o.handler)
160 {
161 }
162 
163 void
165 {
166  handler(params);
167 }
168 
169 void
170 CommAcceptCbPtrFun::print(std::ostream &os) const
171 {
172  os << '(';
173  params.print(os);
174  os << ')';
175 }
176 
177 /* CommConnectCbPtrFun */
178 
180  const CommConnectCbParams &aParams):
182  handler(aHandler)
183 {
184 }
185 
186 void
188 {
190 }
191 
192 void
193 CommConnectCbPtrFun::print(std::ostream &os) const
194 {
195  os << '(';
196  params.print(os);
197  os << ')';
198 }
199 
200 /* CommIoCbPtrFun */
201 
204  handler(aHandler)
205 {
206 }
207 
208 void
210 {
212 }
213 
214 void
215 CommIoCbPtrFun::print(std::ostream &os) const
216 {
217  os << '(';
218  params.print(os);
219  os << ')';
220 }
221 
222 /* CommCloseCbPtrFun */
223 
225  const CommCloseCbParams &aParams):
227  handler(aHandler)
228 {
229 }
230 
231 void
233 {
234  handler(params);
235 }
236 
237 void
238 CommCloseCbPtrFun::print(std::ostream &os) const
239 {
240  os << '(';
241  params.print(os);
242  os << ')';
243 }
244 
245 /* CommTimeoutCbPtrFun */
246 
248  const CommTimeoutCbParams &aParams):
250  handler(aHandler)
251 {
252 }
253 
254 void
256 {
257  handler(params);
258 }
259 
260 void
261 CommTimeoutCbPtrFun::print(std::ostream &os) const
262 {
263  os << '(';
264  params.print(os);
265  os << ')';
266 }
267 
268 /* FdeCbPtrFun */
269 
270 FdeCbPtrFun::FdeCbPtrFun(FDECB *aHandler, const FdeCbParams &aParams) :
271  CommDialerParamsT<FdeCbParams>(aParams),
272  handler(aHandler)
273 {
274 }
275 
276 void
278 {
279  handler(params);
280 }
281 
282 void
283 FdeCbPtrFun::print(std::ostream &os) const
284 {
285  os << '(';
286  params.print(os);
287  os << ')';
288 }
289 
void IOACB(const CommAcceptCbParams &params)
Definition: CommCalls.h:33
CommConnectCbParams(void *aData)
Definition: CommCalls.cc:70
CommAcceptCbParams(void *aData)
Definition: CommCalls.cc:51
bool syncWithComm()
Definition: CommCalls.cc:106
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:215
void print(std::ostream &os) const
Definition: CommCalls.cc:34
CommConnectCbPtrFun(CNCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:179
static void handler(int signo)
Definition: purge.cc:854
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:170
CommAcceptCbPtrFun(IOACB *aHandler, const CommAcceptCbParams &aParams)
Definition: CommCalls.cc:150
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:17
int fd
FD which the call was about. Set by the async call creator.
Definition: CommCalls.h:90
@ OK
Definition: Flag.h:16
CommCloseCbPtrFun(CLCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:224
void CLCB(const CommCloseCbParams &params)
Definition: CommCalls.h:42
@ ERR_CLOSING
Definition: Flag.h:25
#define cbdataReference(var)
Definition: cbdata.h:341
int xerrno
The last errno to occur. non-zero if flag is Comm::COMM_ERROR.
Definition: CommCalls.h:88
FDECB * handler
Definition: CommCalls.h:302
CommCommonCbParams(void *aData)
Definition: CommCalls.cc:18
void print(std::ostream &os) const
Definition: CommCalls.cc:118
void CNCB(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno, void *data)
Definition: CommCalls.h:35
int size
Definition: ModDevPoll.cc:76
#define NULL
Definition: types.h:166
void CTCB(const CommTimeoutCbParams &params)
Definition: CommCalls.h:39
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:193
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:152
void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int xerrno, void *data)
Definition: CommCalls.h:36
IOCB * handler
Definition: CommCalls.h:256
Comm::ConnectionPointer conn
Definition: CommCalls.h:85
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:238
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:19
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:261
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:87
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
void FDECB(const FdeCbParams &params)
Definition: CommCalls.h:45
#define fd_table
Definition: fde.h:189
FdeCbParams(void *aData)
Definition: CommCalls.cc:143
CommCloseCbParams(void *aData)
Definition: CommCalls.cc:129
CommIoCbParams(void *aData)
Definition: CommCalls.cc:100
CommIoCbPtrFun(IOCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:202
virtual void print(std::ostream &os) const
Definition: CommCalls.cc:283
void print(std::ostream &os) const
Definition: CommCalls.cc:60
bool isOpen() const
Definition: Connection.h:99
CommTimeoutCbPtrFun(CTCB *aHandler, const Params &aParams)
Definition: CommCalls.cc:247
InstanceId< MasterXaction, uint64_t > id
transaction ID.
Definition: MasterXaction.h:44
FdeCbPtrFun(FDECB *aHandler, const Params &aParams)
Definition: CommCalls.cc:270
CommTimeoutCbParams(void *aData)
Definition: CommCalls.cc:136
MasterXaction::Pointer xaction
Transaction which this call is part of.
Definition: CommCalls.h:105
void dial()
Definition: CommCalls.cc:277

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors