]> git.ipfire.org Git - thirdparty/squid.git/blame - src/CommCalls.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / CommCalls.cc
CommitLineData
bbc27441 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
bbc27441
AJ
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
582c2af2 9#include "squid.h"
fa720bfb 10#include "anyp/PortCfg.h"
f9b72e0c 11#include "comm/Connection.h"
b0469965 12#include "CommCalls.h"
582c2af2
FC
13#include "fde.h"
14#include "globals.h"
b0469965 15
16/* CommCommonCbParams */
17
18CommCommonCbParams::CommCommonCbParams(void *aData):
f53969cc 19 data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1)
b0469965 20{
21}
22
23CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
f53969cc 24 data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
b0469965 25{
26}
27
28CommCommonCbParams::~CommCommonCbParams()
29{
30 cbdataReferenceDone(data);
31}
32
33void
34CommCommonCbParams::print(std::ostream &os) const
35{
aee3523a 36 if (conn != nullptr)
7957e704
AJ
37 os << conn;
38 else
39 os << "FD " << fd;
40
b0469965 41 if (xerrno)
42 os << ", errno=" << xerrno;
c8407295 43 if (flag != Comm::OK)
b0469965 44 os << ", flag=" << flag;
45 if (data)
46 os << ", data=" << data;
47}
48
b0469965 49/* CommAcceptCbParams */
50
b9ddfca2 51CommAcceptCbParams::CommAcceptCbParams(void *aData):
ad05b958 52 CommCommonCbParams(aData)
b0469965 53{
94bfd31f
AJ
54}
55
2b6b1bcb
AR
56// XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57// implementations always return true.
58
94bfd31f
AJ
59void
60CommAcceptCbParams::print(std::ostream &os) const
61{
62 CommCommonCbParams::print(os);
63
ad05b958
EB
64 if (port && port->listenConn)
65 os << ", " << port->listenConn->codeContextGist();
b0469965 66}
67
b0469965 68/* CommConnectCbParams */
69
70CommConnectCbParams::CommConnectCbParams(void *aData):
f53969cc 71 CommCommonCbParams(aData)
b0469965 72{
73}
74
4c3ba68d
AR
75bool
76CommConnectCbParams::syncWithComm()
77{
2b6b1bcb
AR
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
4c3ba68d 86 }
2b6b1bcb
AR
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();
94 flag = Comm::ERR_CLOSING;
95 return true; // now the callback is in sync with Comm again
4c3ba68d 96}
b0469965 97
98/* CommIoCbParams */
99
100CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
aee3523a 101 buf(nullptr), size(0)
b0469965 102{
103}
104
4c3ba68d 105bool
82ec8dfc
AR
106CommIoCbParams::syncWithComm()
107{
108 // change parameters if the call was scheduled before comm_close but
109 // is being fired after comm_close
c8407295 110 if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) {
bf95c10a 111 debugs(5, 3, "converting late call to Comm::ERR_CLOSING: " << conn);
c8407295 112 flag = Comm::ERR_CLOSING;
82ec8dfc 113 }
4c3ba68d 114 return true; // now we are in sync and can handle the call
26ac0430 115}
82ec8dfc 116
b0469965 117void
118CommIoCbParams::print(std::ostream &os) const
119{
120 CommCommonCbParams::print(os);
121 if (buf) {
122 os << ", size=" << size;
123 os << ", buf=" << (void*)buf;
26ac0430 124 }
b0469965 125}
126
b0469965 127/* CommCloseCbParams */
128
129CommCloseCbParams::CommCloseCbParams(void *aData):
f53969cc 130 CommCommonCbParams(aData)
b0469965 131{
132}
133
134/* CommTimeoutCbParams */
135
136CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
f53969cc 137 CommCommonCbParams(aData)
b0469965 138{
139}
140
a17bf806
AJ
141/* FdeCbParams */
142
143FdeCbParams::FdeCbParams(void *aData):
f53969cc 144 CommCommonCbParams(aData)
a17bf806
AJ
145{
146}
80463bb4 147
b0469965 148/* CommAcceptCbPtrFun */
149
150CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
26ac0430 151 const CommAcceptCbParams &aParams):
f53969cc
SM
152 CommDialerParamsT<CommAcceptCbParams>(aParams),
153 handler(aHandler)
b0469965 154{
155}
156
b9ddfca2 157CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o):
f53969cc
SM
158 CommDialerParamsT<CommAcceptCbParams>(o.params),
159 handler(o.handler)
b9ddfca2
AJ
160{
161}
162
b0469965 163void
164CommAcceptCbPtrFun::dial()
165{
449f0115 166 handler(params);
b0469965 167}
168
169void
170CommAcceptCbPtrFun::print(std::ostream &os) const
171{
172 os << '(';
173 params.print(os);
174 os << ')';
175}
176
b0469965 177/* CommConnectCbPtrFun */
178
179CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
26ac0430 180 const CommConnectCbParams &aParams):
f53969cc
SM
181 CommDialerParamsT<CommConnectCbParams>(aParams),
182 handler(aHandler)
b0469965 183{
184}
185
186void
187CommConnectCbPtrFun::dial()
188{
aed188fd 189 handler(params.conn, params.flag, params.xerrno, params.data);
b0469965 190}
191
192void
193CommConnectCbPtrFun::print(std::ostream &os) const
194{
195 os << '(';
196 params.print(os);
197 os << ')';
198}
199
b0469965 200/* CommIoCbPtrFun */
201
202CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
f53969cc
SM
203 CommDialerParamsT<CommIoCbParams>(aParams),
204 handler(aHandler)
b0469965 205{
206}
207
208void
209CommIoCbPtrFun::dial()
210{
a138c8fc 211 handler(params.conn, params.buf, params.size, params.flag, params.xerrno, params.data);
b0469965 212}
213
214void
215CommIoCbPtrFun::print(std::ostream &os) const
216{
217 os << '(';
218 params.print(os);
219 os << ')';
220}
221
b0469965 222/* CommCloseCbPtrFun */
223
575d05c4 224CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler,
26ac0430 225 const CommCloseCbParams &aParams):
f53969cc
SM
226 CommDialerParamsT<CommCloseCbParams>(aParams),
227 handler(aHandler)
b0469965 228{
229}
230
231void
232CommCloseCbPtrFun::dial()
233{
575d05c4 234 handler(params);
b0469965 235}
236
237void
238CommCloseCbPtrFun::print(std::ostream &os) const
239{
240 os << '(';
241 params.print(os);
242 os << ')';
243}
244
245/* CommTimeoutCbPtrFun */
246
8d77a37c 247CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler,
26ac0430 248 const CommTimeoutCbParams &aParams):
f53969cc
SM
249 CommDialerParamsT<CommTimeoutCbParams>(aParams),
250 handler(aHandler)
b0469965 251{
252}
253
254void
255CommTimeoutCbPtrFun::dial()
256{
8d77a37c 257 handler(params);
b0469965 258}
259
260void
261CommTimeoutCbPtrFun::print(std::ostream &os) const
262{
263 os << '(';
264 params.print(os);
265 os << ')';
266}
a17bf806
AJ
267
268/* FdeCbPtrFun */
269
270FdeCbPtrFun::FdeCbPtrFun(FDECB *aHandler, const FdeCbParams &aParams) :
f53969cc
SM
271 CommDialerParamsT<FdeCbParams>(aParams),
272 handler(aHandler)
a17bf806
AJ
273{
274}
275
276void
277FdeCbPtrFun::dial()
278{
279 handler(params);
280}
281
282void
283FdeCbPtrFun::print(std::ostream &os) const
284{
285 os << '(';
286 params.print(os);
287 os << ')';
288}
f53969cc 289