]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 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 | { | |
7957e704 AJ |
36 | if (conn != NULL) |
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): |
f53969cc | 52 | CommCommonCbParams(aData), xaction() |
b0469965 | 53 | { |
94bfd31f AJ |
54 | } |
55 | ||
56 | void | |
57 | CommAcceptCbParams::print(std::ostream &os) const | |
58 | { | |
59 | CommCommonCbParams::print(os); | |
60 | ||
61 | if (xaction != NULL) | |
62 | os << ", " << xaction->id; | |
b0469965 | 63 | } |
64 | ||
b0469965 | 65 | /* CommConnectCbParams */ |
66 | ||
67 | CommConnectCbParams::CommConnectCbParams(void *aData): | |
f53969cc | 68 | CommCommonCbParams(aData) |
b0469965 | 69 | { |
70 | } | |
71 | ||
4c3ba68d AR |
72 | bool |
73 | CommConnectCbParams::syncWithComm() | |
74 | { | |
75 | // drop the call if the call was scheduled before comm_close but | |
76 | // is being fired after comm_close | |
77 | if (fd >= 0 && fd_table[fd].closing()) { | |
2aecafa9 | 78 | debugs(5, 3, HERE << "dropping late connect call: FD " << fd); |
4c3ba68d AR |
79 | return false; |
80 | } | |
81 | return true; // now we are in sync and can handle the call | |
82 | } | |
b0469965 | 83 | |
84 | /* CommIoCbParams */ | |
85 | ||
86 | CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData), | |
f53969cc | 87 | buf(NULL), size(0) |
b0469965 | 88 | { |
89 | } | |
90 | ||
4c3ba68d | 91 | bool |
82ec8dfc AR |
92 | CommIoCbParams::syncWithComm() |
93 | { | |
94 | // change parameters if the call was scheduled before comm_close but | |
95 | // is being fired after comm_close | |
c8407295 AJ |
96 | if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) { |
97 | debugs(5, 3, HERE << "converting late call to Comm::ERR_CLOSING: " << conn); | |
98 | flag = Comm::ERR_CLOSING; | |
82ec8dfc | 99 | } |
4c3ba68d | 100 | return true; // now we are in sync and can handle the call |
26ac0430 | 101 | } |
82ec8dfc | 102 | |
b0469965 | 103 | void |
104 | CommIoCbParams::print(std::ostream &os) const | |
105 | { | |
106 | CommCommonCbParams::print(os); | |
107 | if (buf) { | |
108 | os << ", size=" << size; | |
109 | os << ", buf=" << (void*)buf; | |
26ac0430 | 110 | } |
b0469965 | 111 | } |
112 | ||
b0469965 | 113 | /* CommCloseCbParams */ |
114 | ||
115 | CommCloseCbParams::CommCloseCbParams(void *aData): | |
f53969cc | 116 | CommCommonCbParams(aData) |
b0469965 | 117 | { |
118 | } | |
119 | ||
120 | /* CommTimeoutCbParams */ | |
121 | ||
122 | CommTimeoutCbParams::CommTimeoutCbParams(void *aData): | |
f53969cc | 123 | CommCommonCbParams(aData) |
b0469965 | 124 | { |
125 | } | |
126 | ||
a17bf806 AJ |
127 | /* FdeCbParams */ |
128 | ||
129 | FdeCbParams::FdeCbParams(void *aData): | |
f53969cc | 130 | CommCommonCbParams(aData) |
a17bf806 AJ |
131 | { |
132 | } | |
80463bb4 | 133 | |
b0469965 | 134 | /* CommAcceptCbPtrFun */ |
135 | ||
136 | CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler, | |
26ac0430 | 137 | const CommAcceptCbParams &aParams): |
f53969cc SM |
138 | CommDialerParamsT<CommAcceptCbParams>(aParams), |
139 | handler(aHandler) | |
b0469965 | 140 | { |
141 | } | |
142 | ||
b9ddfca2 | 143 | CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o): |
f53969cc SM |
144 | CommDialerParamsT<CommAcceptCbParams>(o.params), |
145 | handler(o.handler) | |
b9ddfca2 AJ |
146 | { |
147 | } | |
148 | ||
b0469965 | 149 | void |
150 | CommAcceptCbPtrFun::dial() | |
151 | { | |
449f0115 | 152 | handler(params); |
b0469965 | 153 | } |
154 | ||
155 | void | |
156 | CommAcceptCbPtrFun::print(std::ostream &os) const | |
157 | { | |
158 | os << '('; | |
159 | params.print(os); | |
160 | os << ')'; | |
161 | } | |
162 | ||
b0469965 | 163 | /* CommConnectCbPtrFun */ |
164 | ||
165 | CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler, | |
26ac0430 | 166 | const CommConnectCbParams &aParams): |
f53969cc SM |
167 | CommDialerParamsT<CommConnectCbParams>(aParams), |
168 | handler(aHandler) | |
b0469965 | 169 | { |
170 | } | |
171 | ||
172 | void | |
173 | CommConnectCbPtrFun::dial() | |
174 | { | |
aed188fd | 175 | handler(params.conn, params.flag, params.xerrno, params.data); |
b0469965 | 176 | } |
177 | ||
178 | void | |
179 | CommConnectCbPtrFun::print(std::ostream &os) const | |
180 | { | |
181 | os << '('; | |
182 | params.print(os); | |
183 | os << ')'; | |
184 | } | |
185 | ||
b0469965 | 186 | /* CommIoCbPtrFun */ |
187 | ||
188 | CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams): | |
f53969cc SM |
189 | CommDialerParamsT<CommIoCbParams>(aParams), |
190 | handler(aHandler) | |
b0469965 | 191 | { |
192 | } | |
193 | ||
194 | void | |
195 | CommIoCbPtrFun::dial() | |
196 | { | |
a138c8fc | 197 | handler(params.conn, params.buf, params.size, params.flag, params.xerrno, params.data); |
b0469965 | 198 | } |
199 | ||
200 | void | |
201 | CommIoCbPtrFun::print(std::ostream &os) const | |
202 | { | |
203 | os << '('; | |
204 | params.print(os); | |
205 | os << ')'; | |
206 | } | |
207 | ||
b0469965 | 208 | /* CommCloseCbPtrFun */ |
209 | ||
575d05c4 | 210 | CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler, |
26ac0430 | 211 | const CommCloseCbParams &aParams): |
f53969cc SM |
212 | CommDialerParamsT<CommCloseCbParams>(aParams), |
213 | handler(aHandler) | |
b0469965 | 214 | { |
215 | } | |
216 | ||
217 | void | |
218 | CommCloseCbPtrFun::dial() | |
219 | { | |
575d05c4 | 220 | handler(params); |
b0469965 | 221 | } |
222 | ||
223 | void | |
224 | CommCloseCbPtrFun::print(std::ostream &os) const | |
225 | { | |
226 | os << '('; | |
227 | params.print(os); | |
228 | os << ')'; | |
229 | } | |
230 | ||
231 | /* CommTimeoutCbPtrFun */ | |
232 | ||
8d77a37c | 233 | CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler, |
26ac0430 | 234 | const CommTimeoutCbParams &aParams): |
f53969cc SM |
235 | CommDialerParamsT<CommTimeoutCbParams>(aParams), |
236 | handler(aHandler) | |
b0469965 | 237 | { |
238 | } | |
239 | ||
240 | void | |
241 | CommTimeoutCbPtrFun::dial() | |
242 | { | |
8d77a37c | 243 | handler(params); |
b0469965 | 244 | } |
245 | ||
246 | void | |
247 | CommTimeoutCbPtrFun::print(std::ostream &os) const | |
248 | { | |
249 | os << '('; | |
250 | params.print(os); | |
251 | os << ')'; | |
252 | } | |
a17bf806 AJ |
253 | |
254 | /* FdeCbPtrFun */ | |
255 | ||
256 | FdeCbPtrFun::FdeCbPtrFun(FDECB *aHandler, const FdeCbParams &aParams) : | |
f53969cc SM |
257 | CommDialerParamsT<FdeCbParams>(aParams), |
258 | handler(aHandler) | |
a17bf806 AJ |
259 | { |
260 | } | |
261 | ||
262 | void | |
263 | FdeCbPtrFun::dial() | |
264 | { | |
265 | handler(params); | |
266 | } | |
267 | ||
268 | void | |
269 | FdeCbPtrFun::print(std::ostream &os) const | |
270 | { | |
271 | os << '('; | |
272 | params.print(os); | |
273 | os << ')'; | |
274 | } | |
f53969cc | 275 |