]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/IoCallback.cc
2 * Copyright (C) 1996-2015 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
= NULL
;
39 iocb_table
[pos
].writecb
.conn
= NULL
;
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
)
69 Comm::IoCallback::selectOrQueueWrite()
72 // stand in line if there is one
73 if (ClientInfo
*clientInfo
= fd_table
[conn
->fd
].clientInfo
) {
74 if (clientInfo
->writeLimitingActive
) {
75 quotaQueueReserv
= clientInfo
->quotaEnqueue(conn
->fd
);
76 clientInfo
->kickQuotaQueue();
82 SetSelect(conn
->fd
, COMM_SELECT_WRITE
, Comm::HandleWrite
, this, 0);
86 Comm::IoCallback::cancel(const char *reason
)
91 callback
->cancel(reason
);
97 Comm::IoCallback::reset()
108 quotaQueueReserv
= 0;
112 // Schedule the callback call and clear the callback
114 Comm::IoCallback::finish(Comm::Flag code
, int xerrn
)
116 debugs(5, 3, "called for " << conn
<< " (" << code
<< ", " << xerrn
<< ")");
120 if (freefunc
&& buf
) {
126 if (callback
!= NULL
) {
127 typedef CommIoCbParams Params
;
128 Params
¶ms
= GetCommParams
<Params
>(callback
);
129 if (conn
!= NULL
) params
.fd
= conn
->fd
; // for legacy write handlers...
132 params
.size
= offset
;
134 params
.xerrno
= xerrn
;
135 ScheduleCallHere(callback
);
139 /* Reset for next round. */