]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
10 #include "anyp/PortCfg.h"
11 #include "comm/Connection.h"
12 #include "CommCalls.h"
16 /* CommCommonCbParams */
18 CommCommonCbParams::CommCommonCbParams(void *aData
):
19 data(cbdataReference(aData
)), conn(), flag(Comm::OK
), xerrno(0), fd(-1)
23 CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams
&p
):
24 data(cbdataReference(p
.data
)), conn(p
.conn
), flag(p
.flag
), xerrno(p
.xerrno
), fd(p
.fd
)
28 CommCommonCbParams::~CommCommonCbParams()
30 cbdataReferenceDone(data
);
34 CommCommonCbParams::print(std::ostream
&os
) const
42 os
<< ", errno=" << xerrno
;
44 os
<< ", flag=" << flag
;
46 os
<< ", data=" << data
;
49 /* CommAcceptCbParams */
51 CommAcceptCbParams::CommAcceptCbParams(void *aData
):
52 CommCommonCbParams(aData
)
56 // XXX: Add CommAcceptCbParams::syncWithComm(). Adjust syncWithComm() API if all
57 // implementations always return true.
60 CommAcceptCbParams::print(std::ostream
&os
) const
62 CommCommonCbParams::print(os
);
64 if (port
&& port
->listenConn
)
65 os
<< ", " << port
->listenConn
->codeContextGist();
68 /* CommConnectCbParams */
70 CommConnectCbParams::CommConnectCbParams(void *aData
):
71 CommCommonCbParams(aData
)
76 CommConnectCbParams::syncWithComm()
80 // change parameters if this is a successful callback that was scheduled
81 // after its Comm-registered connection started to close
83 if (flag
!= Comm::OK
) {
84 assert(!conn
->isOpen());
85 return true; // not a successful callback; cannot go out of sync
88 assert(conn
->isOpen());
89 if (!fd_table
[conn
->fd
].closing())
90 return true; // no closing in progress; in sync (for now)
92 debugs(5, 3, "converting to Comm::ERR_CLOSING: " << conn
);
94 flag
= Comm::ERR_CLOSING
;
95 return true; // now the callback is in sync with Comm again
100 CommIoCbParams::CommIoCbParams(void *aData
): CommCommonCbParams(aData
),
101 buf(nullptr), size(0)
106 CommIoCbParams::syncWithComm()
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
;
114 return true; // now we are in sync and can handle the call
118 CommIoCbParams::print(std::ostream
&os
) const
120 CommCommonCbParams::print(os
);
122 os
<< ", size=" << size
;
123 os
<< ", buf=" << (void*)buf
;
127 /* CommCloseCbParams */
129 CommCloseCbParams::CommCloseCbParams(void *aData
):
130 CommCommonCbParams(aData
)
134 /* CommTimeoutCbParams */
136 CommTimeoutCbParams::CommTimeoutCbParams(void *aData
):
137 CommCommonCbParams(aData
)
141 /* CommAcceptCbPtrFun */
143 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB
*aHandler
,
144 const CommAcceptCbParams
&aParams
):
145 CommDialerParamsT
<CommAcceptCbParams
>(aParams
),
150 CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun
&o
):
151 CommDialerParamsT
<CommAcceptCbParams
>(o
.params
),
157 CommAcceptCbPtrFun::dial()
163 CommAcceptCbPtrFun::print(std::ostream
&os
) const
170 /* CommConnectCbPtrFun */
172 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB
*aHandler
,
173 const CommConnectCbParams
&aParams
):
174 CommDialerParamsT
<CommConnectCbParams
>(aParams
),
180 CommConnectCbPtrFun::dial()
182 handler(params
.conn
, params
.flag
, params
.xerrno
, params
.data
);
186 CommConnectCbPtrFun::print(std::ostream
&os
) const
195 CommIoCbPtrFun::CommIoCbPtrFun(IOCB
*aHandler
, const CommIoCbParams
&aParams
):
196 CommDialerParamsT
<CommIoCbParams
>(aParams
),
202 CommIoCbPtrFun::dial()
204 handler(params
.conn
, params
.buf
, params
.size
, params
.flag
, params
.xerrno
, params
.data
);
208 CommIoCbPtrFun::print(std::ostream
&os
) const
215 /* CommCloseCbPtrFun */
217 CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB
*aHandler
,
218 const CommCloseCbParams
&aParams
):
219 CommDialerParamsT
<CommCloseCbParams
>(aParams
),
225 CommCloseCbPtrFun::dial()
231 CommCloseCbPtrFun::print(std::ostream
&os
) const
238 /* CommTimeoutCbPtrFun */
240 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB
*aHandler
,
241 const CommTimeoutCbParams
&aParams
):
242 CommDialerParamsT
<CommTimeoutCbParams
>(aParams
),
248 CommTimeoutCbPtrFun::dial()
254 CommTimeoutCbPtrFun::print(std::ostream
&os
) const