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