]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/IoCallback.cc
2 #include "ClientInfo.h"
3 #include "comm/Connection.h"
4 #include "comm/IoCallback.h"
5 #include "comm/Loops.h"
6 #include "comm/Write.h"
10 Comm::CbEntry
*Comm::iocb_table
;
13 Comm::CallbackTableInit()
15 // XXX: convert this to a std::map<> ?
16 iocb_table
= static_cast<CbEntry
*>(xcalloc(Squid_MaxFD
, sizeof(CbEntry
)));
17 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
18 iocb_table
[pos
].fd
= pos
;
19 iocb_table
[pos
].readcb
.type
= IOCB_READ
;
20 iocb_table
[pos
].writecb
.type
= IOCB_WRITE
;
25 Comm::CallbackTableDestruct()
27 // release any Comm::Connections being held.
28 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
29 iocb_table
[pos
].readcb
.conn
= NULL
;
30 iocb_table
[pos
].writecb
.conn
= NULL
;
32 safe_free(iocb_table
);
36 * Configure Comm::Callback for I/O
38 * @param fd filedescriptor
39 * @param t IO callback type (read or write)
41 * @param buf buffer, if applicable
42 * @param func freefunc, if applicable
43 * @param sz buffer size
46 Comm::IoCallback::setCallback(Comm::iocb_type t
, AsyncCall::Pointer
&cb
, char *b
, FREE
*f
, int sz
)
60 Comm::IoCallback::selectOrQueueWrite()
63 // stand in line if there is one
64 if (ClientInfo
*clientInfo
= fd_table
[conn
->fd
].clientInfo
) {
65 if (clientInfo
->writeLimitingActive
) {
66 quotaQueueReserv
= clientInfo
->quotaEnqueue(conn
->fd
);
67 clientInfo
->kickQuotaQueue();
73 SetSelect(conn
->fd
, COMM_SELECT_WRITE
, Comm::HandleWrite
, this, 0);
77 Comm::IoCallback::cancel(const char *reason
)
82 callback
->cancel(reason
);
88 Comm::IoCallback::reset()
103 // Schedule the callback call and clear the callback
105 Comm::IoCallback::finish(comm_err_t code
, int xerrn
)
107 debugs(5, 3, HERE
<< "called for " << conn
<< " (" << code
<< ", " << xerrno
<< ")");
117 if (callback
!= NULL
) {
118 typedef CommIoCbParams Params
;
119 Params
¶ms
= GetCommParams
<Params
>(callback
);
120 if (conn
!= NULL
) params
.fd
= conn
->fd
; // for legacy write handlers...
123 params
.size
= offset
;
125 params
.xerrno
= xerrn
;
126 ScheduleCallHere(callback
);
130 /* Reset for next round. */