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