]> git.ipfire.org Git - thirdparty/squid.git/blame - src/CommCalls.cc
Make CNCB use const conn
[thirdparty/squid.git] / src / CommCalls.cc
CommitLineData
b0469965 1#include "squid.h"
82ec8dfc 2#include "fde.h"
f9b72e0c 3#include "comm/Connection.h"
b0469965 4#include "CommCalls.h"
5
6/* CommCommonCbParams */
7
8CommCommonCbParams::CommCommonCbParams(void *aData):
26ac0430 9 data(cbdataReference(aData)), fd(-1), xerrno(0), flag(COMM_OK)
b0469965 10{
11}
12
13CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
26ac0430 14 data(cbdataReference(p.data)), fd(p.fd), xerrno(p.xerrno), flag(p.flag)
b0469965 15{
16}
17
18CommCommonCbParams::~CommCommonCbParams()
19{
20 cbdataReferenceDone(data);
21}
22
23void
24CommCommonCbParams::print(std::ostream &os) const
25{
26 os << "FD " << fd;
27 if (xerrno)
28 os << ", errno=" << xerrno;
29 if (flag != COMM_OK)
30 os << ", flag=" << flag;
31 if (data)
32 os << ", data=" << data;
33}
34
35
36/* CommAcceptCbParams */
37
38CommAcceptCbParams::CommAcceptCbParams(void *aData): CommCommonCbParams(aData),
26ac0430 39 nfd(-1)
b0469965 40{
41}
42
43void
44CommAcceptCbParams::print(std::ostream &os) const
45{
46 CommCommonCbParams::print(os);
47 if (nfd >= 0)
48 os << ", newFD " << nfd;
903198a7 49 if (details != NULL)
f01d4b80 50 os << ", " << details;
b0469965 51}
52
53
54/* CommConnectCbParams */
55
56CommConnectCbParams::CommConnectCbParams(void *aData):
26ac0430 57 CommCommonCbParams(aData)
b0469965 58{
59}
60
4c3ba68d
AR
61bool
62CommConnectCbParams::syncWithComm()
63{
64 // drop the call if the call was scheduled before comm_close but
65 // is being fired after comm_close
66 if (fd >= 0 && fd_table[fd].closing()) {
2aecafa9 67 debugs(5, 3, HERE << "dropping late connect call: FD " << fd);
4c3ba68d
AR
68 return false;
69 }
70 return true; // now we are in sync and can handle the call
71}
b0469965 72
3ff65596
AR
73void
74CommConnectCbParams::print(std::ostream &os) const
75{
76 CommCommonCbParams::print(os);
93ad6f77 77 if (conn != NULL)
f01d4b80 78 os << ", " << conn;
3ff65596
AR
79}
80
b0469965 81/* CommIoCbParams */
82
83CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
26ac0430 84 buf(NULL), size(0)
b0469965 85{
86}
87
4c3ba68d 88bool
82ec8dfc
AR
89CommIoCbParams::syncWithComm()
90{
91 // change parameters if the call was scheduled before comm_close but
92 // is being fired after comm_close
93 if (fd >= 0 && fd_table[fd].closing() && flag != COMM_ERR_CLOSING) {
26ac0430
AJ
94 debugs(5, 3, HERE << "converting late call to COMM_ERR_CLOSING: FD " << fd);
95 flag = COMM_ERR_CLOSING;
96 size = 0;
82ec8dfc 97 }
4c3ba68d 98 return true; // now we are in sync and can handle the call
26ac0430 99}
82ec8dfc
AR
100
101
b0469965 102void
103CommIoCbParams::print(std::ostream &os) const
104{
105 CommCommonCbParams::print(os);
106 if (buf) {
107 os << ", size=" << size;
108 os << ", buf=" << (void*)buf;
26ac0430 109 }
b0469965 110}
111
112
113/* CommCloseCbParams */
114
115CommCloseCbParams::CommCloseCbParams(void *aData):
26ac0430 116 CommCommonCbParams(aData)
b0469965 117{
118}
119
120/* CommTimeoutCbParams */
121
122CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
26ac0430 123 CommCommonCbParams(aData)
b0469965 124{
125}
126
127
128/* CommAcceptCbPtrFun */
129
130CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
26ac0430
AJ
131 const CommAcceptCbParams &aParams):
132 CommDialerParamsT<CommAcceptCbParams>(aParams),
133 handler(aHandler)
b0469965 134{
135}
136
137void
138CommAcceptCbPtrFun::dial()
139{
cfd66529 140 handler(params.fd, params.nfd, params.details, params.flag, params.xerrno, params.data);
b0469965 141}
142
143void
144CommAcceptCbPtrFun::print(std::ostream &os) const
145{
146 os << '(';
147 params.print(os);
148 os << ')';
149}
150
151
152/* CommConnectCbPtrFun */
153
154CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
26ac0430
AJ
155 const CommConnectCbParams &aParams):
156 CommDialerParamsT<CommConnectCbParams>(aParams),
157 handler(aHandler)
b0469965 158{
159}
160
161void
162CommConnectCbPtrFun::dial()
163{
aed188fd 164 handler(params.conn, params.flag, params.xerrno, params.data);
b0469965 165}
166
167void
168CommConnectCbPtrFun::print(std::ostream &os) const
169{
170 os << '(';
171 params.print(os);
172 os << ')';
173}
174
175
176/* CommIoCbPtrFun */
177
178CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
26ac0430
AJ
179 CommDialerParamsT<CommIoCbParams>(aParams),
180 handler(aHandler)
b0469965 181{
182}
183
184void
185CommIoCbPtrFun::dial()
186{
187 handler(params.fd, params.buf, params.size, params.flag, params.xerrno, params.data);
188}
189
190void
191CommIoCbPtrFun::print(std::ostream &os) const
192{
193 os << '(';
194 params.print(os);
195 os << ')';
196}
197
198
199/* CommCloseCbPtrFun */
200
201CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler,
26ac0430
AJ
202 const CommCloseCbParams &aParams):
203 CommDialerParamsT<CommCloseCbParams>(aParams),
204 handler(aHandler)
b0469965 205{
206}
207
208void
209CommCloseCbPtrFun::dial()
210{
211 handler(params.fd, params.data);
212}
213
214void
215CommCloseCbPtrFun::print(std::ostream &os) const
216{
217 os << '(';
218 params.print(os);
219 os << ')';
220}
221
222/* CommTimeoutCbPtrFun */
223
224CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
26ac0430
AJ
225 const CommTimeoutCbParams &aParams):
226 CommDialerParamsT<CommTimeoutCbParams>(aParams),
227 handler(aHandler)
b0469965 228{
229}
230
231void
232CommTimeoutCbPtrFun::dial()
233{
234 handler(params.fd, params.data);
235}
236
237void
238CommTimeoutCbPtrFun::print(std::ostream &os) const
239{
240 os << '(';
241 params.print(os);
242 os << ')';
243}