]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / src / CommCalls.cc
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "anyp/PortCfg.h"
11 #include "comm/Connection.h"
12 #include "CommCalls.h"
13 #include "fde.h"
14 #include "globals.h"
15
16 /* CommCommonCbParams */
17
18 CommCommonCbParams::CommCommonCbParams(void *aData):
19 data(cbdataReference(aData)), conn(), flag(Comm::OK), xerrno(0), fd(-1)
20 {
21 }
22
23 CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams &p):
24 data(cbdataReference(p.data)), conn(p.conn), flag(p.flag), xerrno(p.xerrno), fd(p.fd)
25 {
26 }
27
28 CommCommonCbParams::~CommCommonCbParams()
29 {
30 cbdataReferenceDone(data);
31 }
32
33 void
34 CommCommonCbParams::print(std::ostream &os) const
35 {
36 if (conn != nullptr)
37 os << conn;
38 else
39 os << "FD " << fd;
40
41 if (xerrno)
42 os << ", errno=" << xerrno;
43 if (flag != Comm::OK)
44 os << ", flag=" << flag;
45 if (data)
46 os << ", data=" << data;
47 }
48
49 /* CommAcceptCbParams */
50
51 CommAcceptCbParams::CommAcceptCbParams(void *aData):
52 CommCommonCbParams(aData)
53 {
54 }
55
56 // XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57 // implementations always return true.
58
59 void
60 CommAcceptCbParams::print(std::ostream &os) const
61 {
62 CommCommonCbParams::print(os);
63
64 if (port && port->listenConn)
65 os << ", " << port->listenConn->codeContextGist();
66 }
67
68 /* CommConnectCbParams */
69
70 CommConnectCbParams::CommConnectCbParams(void *aData):
71 CommCommonCbParams(aData)
72 {
73 }
74
75 bool
76 CommConnectCbParams::syncWithComm()
77 {
78 assert(conn);
79
80 // change parameters if this is a successful callback that was scheduled
81 // after its Comm-registered connection started to close
82
83 if (flag != Comm::OK) {
84 assert(!conn->isOpen());
85 return true; // not a successful callback; cannot go out of sync
86 }
87
88 assert(conn->isOpen());
89 if (!fd_table[conn->fd].closing())
90 return true; // no closing in progress; in sync (for now)
91
92 debugs(5, 3, "converting to Comm::ERR_CLOSING: " << conn);
93 conn->noteClosure();
94 flag = Comm::ERR_CLOSING;
95 return true; // now the callback is in sync with Comm again
96 }
97
98 /* CommIoCbParams */
99
100 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
101 buf(nullptr), size(0)
102 {
103 }
104
105 bool
106 CommIoCbParams::syncWithComm()
107 {
108 // change parameters if the call was scheduled before comm_close but
109 // is being fired after comm_close
110 if ((conn->fd < 0 || fd_table[conn->fd].closing()) && flag != Comm::ERR_CLOSING) {
111 debugs(5, 3, "converting late call to Comm::ERR_CLOSING: " << conn);
112 flag = Comm::ERR_CLOSING;
113 }
114 return true; // now we are in sync and can handle the call
115 }
116
117 void
118 CommIoCbParams::print(std::ostream &os) const
119 {
120 CommCommonCbParams::print(os);
121 if (buf) {
122 os << ", size=" << size;
123 os << ", buf=" << (void*)buf;
124 }
125 }
126
127 /* CommCloseCbParams */
128
129 CommCloseCbParams::CommCloseCbParams(void *aData):
130 CommCommonCbParams(aData)
131 {
132 }
133
134 /* CommTimeoutCbParams */
135
136 CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
137 CommCommonCbParams(aData)
138 {
139 }
140
141 /* CommAcceptCbPtrFun */
142
143 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
144 const CommAcceptCbParams &aParams):
145 CommDialerParamsT<CommAcceptCbParams>(aParams),
146 handler(aHandler)
147 {
148 }
149
150 CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun &o):
151 CommDialerParamsT<CommAcceptCbParams>(o.params),
152 handler(o.handler)
153 {
154 }
155
156 void
157 CommAcceptCbPtrFun::dial()
158 {
159 handler(params);
160 }
161
162 void
163 CommAcceptCbPtrFun::print(std::ostream &os) const
164 {
165 os << '(';
166 params.print(os);
167 os << ')';
168 }
169
170 /* CommConnectCbPtrFun */
171
172 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB *aHandler,
173 const CommConnectCbParams &aParams):
174 CommDialerParamsT<CommConnectCbParams>(aParams),
175 handler(aHandler)
176 {
177 }
178
179 void
180 CommConnectCbPtrFun::dial()
181 {
182 handler(params.conn, params.flag, params.xerrno, params.data);
183 }
184
185 void
186 CommConnectCbPtrFun::print(std::ostream &os) const
187 {
188 os << '(';
189 params.print(os);
190 os << ')';
191 }
192
193 /* CommIoCbPtrFun */
194
195 CommIoCbPtrFun::CommIoCbPtrFun(IOCB *aHandler, const CommIoCbParams &aParams):
196 CommDialerParamsT<CommIoCbParams>(aParams),
197 handler(aHandler)
198 {
199 }
200
201 void
202 CommIoCbPtrFun::dial()
203 {
204 handler(params.conn, params.buf, params.size, params.flag, params.xerrno, params.data);
205 }
206
207 void
208 CommIoCbPtrFun::print(std::ostream &os) const
209 {
210 os << '(';
211 params.print(os);
212 os << ')';
213 }
214
215 /* CommCloseCbPtrFun */
216
217 CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler,
218 const CommCloseCbParams &aParams):
219 CommDialerParamsT<CommCloseCbParams>(aParams),
220 handler(aHandler)
221 {
222 }
223
224 void
225 CommCloseCbPtrFun::dial()
226 {
227 handler(params);
228 }
229
230 void
231 CommCloseCbPtrFun::print(std::ostream &os) const
232 {
233 os << '(';
234 params.print(os);
235 os << ')';
236 }
237
238 /* CommTimeoutCbPtrFun */
239
240 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler,
241 const CommTimeoutCbParams &aParams):
242 CommDialerParamsT<CommTimeoutCbParams>(aParams),
243 handler(aHandler)
244 {
245 }
246
247 void
248 CommTimeoutCbPtrFun::dial()
249 {
250 handler(params);
251 }
252
253 void
254 CommTimeoutCbPtrFun::print(std::ostream &os) const
255 {
256 os << '(';
257 params.print(os);
258 os << ')';
259 }
260