]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/IoCallback.cc
2 * Copyright (C) 1996-2022 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 "ClientInfo.h"
11 #include "comm/Connection.h"
12 #include "comm/IoCallback.h"
13 #include "comm/Loops.h"
14 #include "comm/Write.h"
15 #include "CommCalls.h"
19 Comm::CbEntry
*Comm::iocb_table
;
22 Comm::CallbackTableInit()
24 // XXX: convert this to a std::map<> ?
25 iocb_table
= static_cast<CbEntry
*>(xcalloc(Squid_MaxFD
, sizeof(CbEntry
)));
26 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
27 iocb_table
[pos
].fd
= pos
;
28 iocb_table
[pos
].readcb
.type
= IOCB_READ
;
29 iocb_table
[pos
].writecb
.type
= IOCB_WRITE
;
34 Comm::CallbackTableDestruct()
36 // release any Comm::Connections being held.
37 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
38 iocb_table
[pos
].readcb
.conn
= nullptr;
39 iocb_table
[pos
].writecb
.conn
= nullptr;
41 safe_free(iocb_table
);
45 * Configure Comm::Callback for I/O
47 * @param fd filedescriptor
48 * @param t IO callback type (read or write)
50 * @param buf buffer, if applicable
51 * @param func freefunc, if applicable
52 * @param sz buffer size
55 Comm::IoCallback::setCallback(Comm::iocb_type t
, AsyncCall::Pointer
&cb
, char *b
, FREE
*f
, int sz
)
59 assert(cb
!= nullptr);
69 Comm::IoCallback::selectOrQueueWrite()
72 if (BandwidthBucket
*bucket
= BandwidthBucket::SelectBucket(&fd_table
[conn
->fd
])) {
73 bucket
->scheduleWrite(this);
78 SetSelect(conn
->fd
, COMM_SELECT_WRITE
, Comm::HandleWrite
, this, 0);
82 Comm::IoCallback::cancel(const char *reason
)
87 callback
->cancel(reason
);
93 Comm::IoCallback::reset()
104 quotaQueueReserv
= 0;
108 // Schedule the callback call and clear the callback
110 Comm::IoCallback::finish(Comm::Flag code
, int xerrn
)
112 debugs(5, 3, "called for " << conn
<< " (" << code
<< ", " << xerrn
<< ")");
116 if (freefunc
&& buf
) {
122 if (callback
!= nullptr) {
123 typedef CommIoCbParams Params
;
124 Params
¶ms
= GetCommParams
<Params
>(callback
);
125 if (conn
!= nullptr) params
.fd
= conn
->fd
; // for legacy write handlers...
128 params
.size
= offset
;
130 params
.xerrno
= xerrn
;
131 ScheduleCallHere(callback
);
135 /* Reset for next round. */