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