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