]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/CommCalls.cc
3 #include "comm/Connection.h"
6 /* CommCommonCbParams */
8 CommCommonCbParams::CommCommonCbParams(void *aData
):
9 data(cbdataReference(aData
)), fd(-1), xerrno(0), flag(COMM_OK
)
13 CommCommonCbParams::CommCommonCbParams(const CommCommonCbParams
&p
):
14 data(cbdataReference(p
.data
)), fd(p
.fd
), xerrno(p
.xerrno
), flag(p
.flag
)
18 CommCommonCbParams::~CommCommonCbParams()
20 cbdataReferenceDone(data
);
24 CommCommonCbParams::print(std::ostream
&os
) const
32 os
<< ", errno=" << xerrno
;
34 os
<< ", flag=" << flag
;
36 os
<< ", data=" << data
;
40 /* CommAcceptCbParams */
42 CommAcceptCbParams::CommAcceptCbParams(void *aData
):
43 CommCommonCbParams(aData
)
48 /* CommConnectCbParams */
50 CommConnectCbParams::CommConnectCbParams(void *aData
):
51 CommCommonCbParams(aData
)
56 CommConnectCbParams::syncWithComm()
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
);
64 return true; // now we are in sync and can handle the call
69 CommIoCbParams::CommIoCbParams(void *aData
): CommCommonCbParams(aData
),
75 CommIoCbParams::syncWithComm()
77 // transition only: read/write legacy code does not know about conn, it just sets FD
80 conn
= new Comm::Connection
;
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
;
92 return true; // now we are in sync and can handle the call
97 CommIoCbParams::print(std::ostream
&os
) const
99 CommCommonCbParams::print(os
);
101 os
<< ", size=" << size
;
102 os
<< ", buf=" << (void*)buf
;
107 /* CommCloseCbParams */
109 CommCloseCbParams::CommCloseCbParams(void *aData
):
110 CommCommonCbParams(aData
)
114 /* CommTimeoutCbParams */
116 CommTimeoutCbParams::CommTimeoutCbParams(void *aData
):
117 CommCommonCbParams(aData
)
122 /* CommAcceptCbPtrFun */
124 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB
*aHandler
,
125 const CommAcceptCbParams
&aParams
):
126 CommDialerParamsT
<CommAcceptCbParams
>(aParams
),
131 CommAcceptCbPtrFun::CommAcceptCbPtrFun(const CommAcceptCbPtrFun
&o
):
132 CommDialerParamsT
<CommAcceptCbParams
>(o
.params
),
138 CommAcceptCbPtrFun::dial()
140 handler(params
.fd
, params
.conn
, params
.flag
, params
.xerrno
, params
.data
);
144 CommAcceptCbPtrFun::print(std::ostream
&os
) const
152 /* CommConnectCbPtrFun */
154 CommConnectCbPtrFun::CommConnectCbPtrFun(CNCB
*aHandler
,
155 const CommConnectCbParams
&aParams
):
156 CommDialerParamsT
<CommConnectCbParams
>(aParams
),
162 CommConnectCbPtrFun::dial()
164 handler(params
.conn
, params
.flag
, params
.xerrno
, params
.data
);
168 CommConnectCbPtrFun::print(std::ostream
&os
) const
178 CommIoCbPtrFun::CommIoCbPtrFun(IOCB
*aHandler
, const CommIoCbParams
&aParams
):
179 CommDialerParamsT
<CommIoCbParams
>(aParams
),
185 CommIoCbPtrFun::dial()
187 handler(params
.conn
, params
.buf
, params
.size
, params
.flag
, params
.xerrno
, params
.data
);
191 CommIoCbPtrFun::print(std::ostream
&os
) const
199 /* CommCloseCbPtrFun */
201 CommCloseCbPtrFun::CommCloseCbPtrFun(PF
*aHandler
,
202 const CommCloseCbParams
&aParams
):
203 CommDialerParamsT
<CommCloseCbParams
>(aParams
),
209 CommCloseCbPtrFun::dial()
211 handler(params
.fd
, params
.data
);
215 CommCloseCbPtrFun::print(std::ostream
&os
) const
222 /* CommTimeoutCbPtrFun */
224 CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF
*aHandler
,
225 const CommTimeoutCbParams
&aParams
):
226 CommDialerParamsT
<CommTimeoutCbParams
>(aParams
),
232 CommTimeoutCbPtrFun::dial()
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() ?
244 handler(params
.fd
, params
.data
);
248 CommTimeoutCbPtrFun::print(std::ostream
&os
) const