]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
Merged 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 /* CommIoCbParams */
71
72 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
73 buf(NULL), size(0)
74 {
75 }
76
77 bool
78 CommIoCbParams::syncWithComm()
79 {
80 // change parameters if the call was scheduled before comm_close but
81 // is being fired after comm_close
82 if (fd >= 0 && fd_table[fd].closing() && flag != COMM_ERR_CLOSING) {
83 debugs(5, 3, HERE << "converting late call to COMM_ERR_CLOSING: FD " << fd);
84 flag = COMM_ERR_CLOSING;
85 size = 0;
86 }
87 return true; // now we are in sync and can handle the call
88 }
89
90
91 void
92 CommIoCbParams::print(std::ostream &os) const
93 {
94 CommCommonCbParams::print(os);
95 if (buf) {
96 os << ", size=" << size;
97 os << ", buf=" << (void*)buf;
98 }
99 }
100
101
102 /* CommCloseCbParams */
103
104 CommCloseCbParams::CommCloseCbParams(void *aData):
105 CommCommonCbParams(aData)
106 {
107 }
108
109 /* CommTimeoutCbParams */
110
111 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
112 CommCommonCbParams(aData)
113 {
114 }
115
116
117 /* CommAcceptCbPtrFun */
118
119 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
120 const CommAcceptCbParams &aParams):
121 CommDialerParamsT<CommAcceptCbParams>(aParams),
122 handler(aHandler)
123 {
124 }
125
126 void
127 CommAcceptCbPtrFun::dial()
128 {
129 handler(params.fd, params.nfd, &params.details, params.flag, params.xerrno, params.data);
130 }
131
132 void
133 CommAcceptCbPtrFun::print(std::ostream &os) const
134 {
135 os << '(';
136 params.print(os);
137 os << ')';
138 }
139
140
141 /* CommConnectCbPtrFun */
142
143 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
144 const CommConnectCbParams &aParams):
145 CommDialerParamsT<CommConnectCbParams>(aParams),
146 handler(aHandler)
147 {
148 }
149
150 void
151 CommConnectCbPtrFun::dial()
152 {
153 handler(params.fd, params.flag, params.xerrno, params.data);
154 }
155
156 void
157 CommConnectCbPtrFun::print(std::ostream &os) const
158 {
159 os << '(';
160 params.print(os);
161 os << ')';
162 }
163
164
165 /* CommIoCbPtrFun */
166
167 CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
168 CommDialerParamsT<CommIoCbParams>(aParams),
169 handler(aHandler)
170 {
171 }
172
173 void
174 CommIoCbPtrFun::dial()
175 {
176 handler(params.fd, params.buf, params.size, params.flag, params.xerrno, params.data);
177 }
178
179 void
180 CommIoCbPtrFun::print(std::ostream &os) const
181 {
182 os << '(';
183 params.print(os);
184 os << ')';
185 }
186
187
188 /* CommCloseCbPtrFun */
189
190 CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler,
191 const CommCloseCbParams &aParams):
192 CommDialerParamsT<CommCloseCbParams>(aParams),
193 handler(aHandler)
194 {
195 }
196
197 void
198 CommCloseCbPtrFun::dial()
199 {
200 handler(params.fd, params.data);
201 }
202
203 void
204 CommCloseCbPtrFun::print(std::ostream &os) const
205 {
206 os << '(';
207 params.print(os);
208 os << ')';
209 }
210
211 /* CommTimeoutCbPtrFun */
212
213 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
214 const CommTimeoutCbParams &aParams):
215 CommDialerParamsT<CommTimeoutCbParams>(aParams),
216 handler(aHandler)
217 {
218 }
219
220 void
221 CommTimeoutCbPtrFun::dial()
222 {
223 handler(params.fd, params.data);
224 }
225
226 void
227 CommTimeoutCbPtrFun::print(std::ostream &os) const
228 {
229 os << '(';
230 params.print(os);
231 os << ')';
232 }