]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/AcceptLimiter.cc
2 #include "comm/AcceptLimiter.h"
3 #include "comm/Connection.h"
4 #include "comm/TcpAcceptor.h"
8 Comm::AcceptLimiter
Comm::AcceptLimiter::Instance_
;
11 Comm::AcceptLimiter::Instance()
17 Comm::AcceptLimiter::defer(const Comm::TcpAcceptor::Pointer
&afd
)
20 debugs(5, 5, afd
->conn
<< " x" << afd
->isLimited
);
21 deferred_
.push_back(afd
);
25 Comm::AcceptLimiter::removeDead(const Comm::TcpAcceptor::Pointer
&afd
)
27 uint64_t abandonedClients
= 0;
28 for (unsigned int i
= 0; i
< deferred_
.size() && afd
->isLimited
> 0; ++i
) {
29 if (deferred_
[i
] == afd
) {
30 -- deferred_
[i
]->isLimited
;
31 deferred_
[i
] = NULL
; // fast. kick() will skip empty entries later.
32 debugs(5, 5, afd
->conn
<< " x" << afd
->isLimited
);
36 debugs(5,4, "Abandoned " << abandonedClients
<< " client TCP SYN by closing socket: " << afd
->conn
);
40 Comm::AcceptLimiter::kick()
42 // TODO: this could be optimized further with an iterator to search
43 // looking for first non-NULL, followed by dumping the first N
44 // with only one shift()/pop_front operation
45 // OR, by reimplementing as a list instead of Vector.
47 debugs(5, 5, "size=" << deferred_
.size());
48 while (deferred_
.size() > 0 && fdNFree() >= RESERVED_FD
) {
49 /* NP: shift() is equivalent to pop_front(). Giving us a FIFO queue. */
50 TcpAcceptor::Pointer temp
= deferred_
.front();
51 deferred_
.erase(deferred_
.begin());
53 debugs(5, 5, "doing one.");