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