]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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 | ||
18 | CommCommonCbParams::CommCommonCbParams(void *aData): | |
f53969cc | 19 | data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1) |
b0469965 | 20 | { |
21 | } | |
22 | ||
23 | CommCommonCbParams::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 | ||
28 | CommCommonCbParams::~CommCommonCbParams() | |
29 | { | |
30 | cbdataReferenceDone(data); | |
31 | } | |
32 | ||
33 | void | |
34 | CommCommonCbParams::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 | 51 | CommAcceptCbParams::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 |
59 | void |
60 | CommAcceptCbParams::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 | ||
70 | CommConnectCbParams::CommConnectCbParams(void *aData): | |
f53969cc | 71 | CommCommonCbParams(aData) |
b0469965 | 72 | { |
73 | } | |
74 | ||
4c3ba68d AR |
75 | bool |
76 | CommConnectCbParams::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 | ||
100 | CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData), | |
aee3523a | 101 | buf(nullptr), size(0) |
b0469965 | 102 | { |
103 | } | |
104 | ||
4c3ba68d | 105 | bool |
82ec8dfc AR |
106 | CommIoCbParams::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 | 117 | void |
118 | CommIoCbParams::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 | ||
129 | CommCloseCbParams::CommCloseCbParams(void *aData): | |
f53969cc | 130 | CommCommonCbParams(aData) |
b0469965 | 131 | { |
132 | } | |
133 | ||
134 | /* CommTimeoutCbParams */ | |
135 | ||
136 | CommTimeoutCbParams::CommTimeoutCbParams(void *aData): | |
f53969cc | 137 | CommCommonCbParams(aData) |
b0469965 | 138 | { |
139 | } | |
140 | ||
b0469965 | 141 | /* CommAcceptCbPtrFun */ |
142 | ||
143 | CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler, | |
26ac0430 | 144 | const CommAcceptCbParams &aParams): |
f53969cc SM |
145 | CommDialerParamsT<CommAcceptCbParams>(aParams), |
146 | handler(aHandler) | |
b0469965 | 147 | { |
148 | } | |
149 | ||
b9ddfca2 | 150 | CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o): |
f53969cc SM |
151 | CommDialerParamsT<CommAcceptCbParams>(o.params), |
152 | handler(o.handler) | |
b9ddfca2 AJ |
153 | { |
154 | } | |
155 | ||
b0469965 | 156 | void |
157 | CommAcceptCbPtrFun::dial() | |
158 | { | |
449f0115 | 159 | handler(params); |
b0469965 | 160 | } |
161 | ||
162 | void | |
163 | CommAcceptCbPtrFun::print(std::ostream &os) const | |
164 | { | |
165 | os << '('; | |
166 | params.print(os); | |
167 | os << ')'; | |
168 | } | |
169 | ||
b0469965 | 170 | /* CommConnectCbPtrFun */ |
171 | ||
172 | CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler, | |
26ac0430 | 173 | const CommConnectCbParams &aParams): |
f53969cc SM |
174 | CommDialerParamsT<CommConnectCbParams>(aParams), |
175 | handler(aHandler) | |
b0469965 | 176 | { |
177 | } | |
178 | ||
179 | void | |
180 | CommConnectCbPtrFun::dial() | |
181 | { | |
aed188fd | 182 | handler(params.conn, params.flag, params.xerrno, params.data); |
b0469965 | 183 | } |
184 | ||
185 | void | |
186 | CommConnectCbPtrFun::print(std::ostream &os) const | |
187 | { | |
188 | os << '('; | |
189 | params.print(os); | |
190 | os << ')'; | |
191 | } | |
192 | ||
b0469965 | 193 | /* CommIoCbPtrFun */ |
194 | ||
195 | CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams): | |
f53969cc SM |
196 | CommDialerParamsT<CommIoCbParams>(aParams), |
197 | handler(aHandler) | |
b0469965 | 198 | { |
199 | } | |
200 | ||
201 | void | |
202 | CommIoCbPtrFun::dial() | |
203 | { | |
a138c8fc | 204 | handler(params.conn, params.buf, params.size, params.flag, params.xerrno, params.data); |
b0469965 | 205 | } |
206 | ||
207 | void | |
208 | CommIoCbPtrFun::print(std::ostream &os) const | |
209 | { | |
210 | os << '('; | |
211 | params.print(os); | |
212 | os << ')'; | |
213 | } | |
214 | ||
b0469965 | 215 | /* CommCloseCbPtrFun */ |
216 | ||
575d05c4 | 217 | CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler, |
26ac0430 | 218 | const CommCloseCbParams &aParams): |
f53969cc SM |
219 | CommDialerParamsT<CommCloseCbParams>(aParams), |
220 | handler(aHandler) | |
b0469965 | 221 | { |
222 | } | |
223 | ||
224 | void | |
225 | CommCloseCbPtrFun::dial() | |
226 | { | |
575d05c4 | 227 | handler(params); |
b0469965 | 228 | } |
229 | ||
230 | void | |
231 | CommCloseCbPtrFun::print(std::ostream &os) const | |
232 | { | |
233 | os << '('; | |
234 | params.print(os); | |
235 | os << ')'; | |
236 | } | |
237 | ||
238 | /* CommTimeoutCbPtrFun */ | |
239 | ||
8d77a37c | 240 | CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler, |
26ac0430 | 241 | const CommTimeoutCbParams &aParams): |
f53969cc SM |
242 | CommDialerParamsT<CommTimeoutCbParams>(aParams), |
243 | handler(aHandler) | |
b0469965 | 244 | { |
245 | } | |
246 | ||
247 | void | |
248 | CommTimeoutCbPtrFun::dial() | |
249 | { | |
8d77a37c | 250 | handler(params); |
b0469965 | 251 | } |
252 | ||
253 | void | |
254 | CommTimeoutCbPtrFun::print(std::ostream &os) const | |
255 | { | |
256 | os << '('; | |
257 | params.print(os); | |
258 | os << ')'; | |
259 | } | |
a17bf806 | 260 |