]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/IoCallback.cc
2 #include "ClientInfo.h"
3 #include "comm/IoCallback.h"
4 #include "comm/Write.h"
8 Comm::CbEntry
*Comm::iocb_table
;
11 Comm::CallbackTableInit()
13 // XXX: convert this to a std::map<> ?
14 iocb_table
= static_cast<CbEntry
*>(xcalloc(Squid_MaxFD
, sizeof(CbEntry
)));
15 for (int pos
= 0; pos
< Squid_MaxFD
; pos
++) {
16 iocb_table
[pos
].fd
= pos
;
17 iocb_table
[pos
].readcb
.fd
= pos
;
18 iocb_table
[pos
].readcb
.type
= IOCB_READ
;
19 iocb_table
[pos
].writecb
.fd
= pos
;
20 iocb_table
[pos
].writecb
.type
= IOCB_WRITE
;
25 Comm::CallbackTableDestruct()
27 safe_free(iocb_table
);
31 * Configure Comm::Callback for I/O
33 * @param fd filedescriptor
34 * @param t IO callback type (read or write)
36 * @param buf buffer, if applicable
37 * @param func freefunc, if applicable
38 * @param sz buffer size
41 Comm::IoCallback::setCallback(Comm::iocb_type t
, AsyncCall::Pointer
&cb
, char *b
, FREE
*f
, int sz
)
55 Comm::IoCallback::selectOrQueueWrite()
58 // stand in line if there is one
59 if (ClientInfo
*clientInfo
= fd_table
[fd
].clientInfo
) {
60 if (clientInfo
->writeLimitingActive
) {
61 quotaQueueReserv
= clientInfo
->quotaEnqueue(fd
);
62 clientInfo
->kickQuotaQueue();
68 commSetSelect(fd
, COMM_SELECT_WRITE
, Comm::HandleWrite
, this, 0);
72 Comm::IoCallback::cancel(const char *reason
)
77 callback
->cancel(reason
);
83 Comm::IoCallback::reset()
97 // Schedule the callback call and clear the callback
99 Comm::IoCallback::finish(comm_err_t code
, int xerrn
)
101 debugs(5, 3, HERE
<< "called for FD " << fd
<< " (" << code
<< ", " << xerrno
<< ")");
111 if (callback
!= NULL
) {
112 typedef CommIoCbParams Params
;
113 Params
¶ms
= GetCommParams
<Params
>(callback
);
116 params
.size
= offset
;
118 params
.xerrno
= xerrn
;
119 ScheduleCallHere(callback
);
123 /* Reset for next round. */