]> 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 if (conn != NULL)
27 os << conn;
28 else
29 os << "FD " << fd;
30
31 if (xerrno)
32 os << ", errno=" << xerrno;
33 if (flag != COMM_OK)
34 os << ", flag=" << flag;
35 if (data)
36 os << ", data=" << data;
37 }
38
39
40 /* CommAcceptCbParams */
41
42 CommAcceptCbParams::CommAcceptCbParams(void *aData):
43 CommCommonCbParams(aData)
44 {
45 }
46
47
48 /* CommConnectCbParams */
49
50 CommConnectCbParams::CommConnectCbParams(void *aData):
51 CommCommonCbParams(aData)
52 {
53 }
54
55 bool
56 CommConnectCbParams::syncWithComm()
57 {
58 // drop the call if the call was scheduled before comm_close but
59 // is being fired after comm_close
60 if (fd >= 0 && fd_table[fd].closing()) {
61 debugs(5, 3, HERE << "dropping late connect call: FD " << fd);
62 return false;
63 }
64 return true; // now we are in sync and can handle the call
65 }
66
67 /* CommIoCbParams */
68
69 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
70 buf(NULL), size(0)
71 {
72 }
73
74 bool
75 CommIoCbParams::syncWithComm()
76 {
77 // transition only: read/write legacy code does not know about conn, it just sets FD
78 if (fd >= 0) {
79 if (conn == NULL)
80 conn = new Comm::Connection;
81 if (conn->fd != fd)
82 conn->fd = fd;
83 }
84
85 // change parameters if the call was scheduled before comm_close but
86 // is being fired after comm_close
87 if (conn->fd >= 0 && fd_table[conn->fd].closing() && flag != COMM_ERR_CLOSING) {
88 debugs(5, 3, HERE << "converting late call to COMM_ERR_CLOSING: " << conn);
89 flag = COMM_ERR_CLOSING;
90 size = 0;
91 }
92 return true; // now we are in sync and can handle the call
93 }
94
95
96 void
97 CommIoCbParams::print(std::ostream &os) const
98 {
99 CommCommonCbParams::print(os);
100 if (buf) {
101 os << ", size=" << size;
102 os << ", buf=" << (void*)buf;
103 }
104 }
105
106
107 /* CommCloseCbParams */
108
109 CommCloseCbParams::CommCloseCbParams(void *aData):
110 CommCommonCbParams(aData)
111 {
112 }
113
114 /* CommTimeoutCbParams */
115
116 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
117 CommCommonCbParams(aData)
118 {
119 }
120
121
122 /* CommAcceptCbPtrFun */
123
124 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
125 const CommAcceptCbParams &aParams):
126 CommDialerParamsT<CommAcceptCbParams>(aParams),
127 handler(aHandler)
128 {
129 }
130
131 CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o):
132 CommDialerParamsT<CommAcceptCbParams>(o.params),
133 handler(o.handler)
134 {
135 }
136
137 void
138 CommAcceptCbPtrFun::dial()
139 {
140 handler(params.fd, params.conn, 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.conn, 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 // AYJ NP: since the old code is still used by pipes and IPC
235 // we cant discard the params.fd functions entirely for old callbacks.
236 // new callers supposed to only set conn.
237 // sync FD and conn fields at this single failure point before dialing.
238 if (params.conn != NULL) {
239 if (params.fd < 0 && params.conn->fd > 0)
240 params.fd = params.conn->fd;
241 assert(params.fd == params.conn->fd); // Must() ?
242 }
243
244 handler(params.fd, params.data);
245 }
246
247 void
248 CommTimeoutCbPtrFun::print(std::ostream &os) const
249 {
250 os << '(';
251 params.print(os);
252 os << ')';
253 }