]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/AcceptLimiter.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / comm / AcceptLimiter.cc
1 #include "squid.h"
2 #include "comm/AcceptLimiter.h"
3 #include "comm/Connection.h"
4 #include "comm/TcpAcceptor.h"
5 #include "fde.h"
6
7 Comm::AcceptLimiter Comm::AcceptLimiter::Instance_;
8
9 Comm::AcceptLimiter &Comm::AcceptLimiter::Instance()
10 {
11 return Instance_;
12 }
13
14 void
15 Comm::AcceptLimiter::defer(Comm::TcpAcceptor *afd)
16 {
17 afd->isLimited++;
18 debugs(5, 5, HERE << afd->conn << " x" << afd->isLimited);
19 deferred.push_back(afd);
20 }
21
22 void
23 Comm::AcceptLimiter::removeDead(const Comm::TcpAcceptor *afd)
24 {
25 for (unsigned int i = 0; i < deferred.size() && afd->isLimited > 0; i++) {
26 if (deferred[i] == afd) {
27 deferred[i]->isLimited--;
28 deferred[i] = NULL; // fast. kick() will skip empty entries later.
29 debugs(5, 5, HERE << afd->conn << " x" << afd->isLimited);
30 }
31 }
32 }
33
34 void
35 Comm::AcceptLimiter::kick()
36 {
37 // TODO: this could be optimized further with an iterator to search
38 // looking for first non-NULL, followed by dumping the first N
39 // with only one shift()/pop_front operation
40
41 debugs(5, 5, HERE << " size=" << deferred.size());
42 while (deferred.size() > 0 && fdNFree() >= RESERVED_FD) {
43 /* NP: shift() is equivalent to pop_front(). Giving us a FIFO queue. */
44 TcpAcceptor *temp = deferred.shift();
45 if (temp != NULL) {
46 debugs(5, 5, HERE << " doing one.");
47 temp->isLimited--;
48 temp->acceptNext();
49 break;
50 }
51 }
52 }