]>
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"
11 Comm::CbEntry
*Comm::iocb_table
;
14 Comm::CallbackTableInit()
16 // XXX: convert this to a std::map<> ?
17 iocb_table
= static_cast<CbEntry
*>(xcalloc(Squid_MaxFD
, sizeof(CbEntry
)));
18 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
19 iocb_table
[pos
].fd
= pos
;
20 iocb_table
[pos
].readcb
.type
= IOCB_READ
;
21 iocb_table
[pos
].writecb
.type
= IOCB_WRITE
;
26 Comm::CallbackTableDestruct()
28 // release any Comm::Connections being held.
29 for (int pos
= 0; pos
< Squid_MaxFD
; ++pos
) {
30 iocb_table
[pos
].readcb
.conn
= NULL
;
31 iocb_table
[pos
].writecb
.conn
= NULL
;
33 safe_free(iocb_table
);
37 * Configure Comm::Callback for I/O
39 * @param fd filedescriptor
40 * @param t IO callback type (read or write)
42 * @param buf buffer, if applicable
43 * @param func freefunc, if applicable
44 * @param sz buffer size
47 Comm::IoCallback::setCallback(Comm::iocb_type t
, AsyncCall::Pointer
&cb
, char *b
, FREE
*f
, int sz
)
61 Comm::IoCallback::selectOrQueueWrite()
64 // stand in line if there is one
65 if (ClientInfo
*clientInfo
= fd_table
[conn
->fd
].clientInfo
) {
66 if (clientInfo
->writeLimitingActive
) {
67 quotaQueueReserv
= clientInfo
->quotaEnqueue(conn
->fd
);
68 clientInfo
->kickQuotaQueue();
74 SetSelect(conn
->fd
, COMM_SELECT_WRITE
, Comm::HandleWrite
, this, 0);
78 Comm::IoCallback::cancel(const char *reason
)
83 callback
->cancel(reason
);
89 Comm::IoCallback::reset()
100 quotaQueueReserv
= 0;
104 // Schedule the callback call and clear the callback
106 Comm::IoCallback::finish(Comm::Flag code
, int xerrn
)
108 debugs(5, 3, HERE
<< "called for " << conn
<< " (" << code
<< ", " << xerrno
<< ")");
112 if (freefunc
&& buf
) {
118 if (callback
!= NULL
) {
119 typedef CommIoCbParams Params
;
120 Params
¶ms
= GetCommParams
<Params
>(callback
);
121 if (conn
!= NULL
) params
.fd
= conn
->fd
; // for legacy write handlers...
124 params
.size
= offset
;
126 params
.xerrno
= xerrn
;
127 ScheduleCallHere(callback
);
131 /* Reset for next round. */