]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/AcceptLimiter.cc
2 * Copyright (C) 1996-2017 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 "comm/AcceptLimiter.h"
11 #include "comm/Connection.h"
12 #include "comm/TcpAcceptor.h"
16 Comm::AcceptLimiter
Comm::AcceptLimiter::Instance_
;
19 Comm::AcceptLimiter::Instance()
25 Comm::AcceptLimiter::defer(const Comm::TcpAcceptor::Pointer
&afd
)
28 debugs(5, 5, afd
->conn
<< " x" << afd
->isLimited
);
29 deferred_
.push_back(afd
);
33 Comm::AcceptLimiter::removeDead(const Comm::TcpAcceptor::Pointer
&afd
)
35 uint64_t abandonedClients
= 0;
36 for (unsigned int i
= 0; i
< deferred_
.size() && afd
->isLimited
> 0; ++i
) {
37 if (deferred_
[i
] == afd
) {
38 -- deferred_
[i
]->isLimited
;
39 deferred_
[i
] = NULL
; // fast. kick() will skip empty entries later.
40 debugs(5, 5, afd
->conn
<< " x" << afd
->isLimited
);
44 debugs(5,4, "Abandoned " << abandonedClients
<< " client TCP SYN by closing socket: " << afd
->conn
);
48 Comm::AcceptLimiter::kick()
50 // TODO: this could be optimized further with an iterator to search
51 // looking for first non-NULL, followed by dumping the first N
52 // with only one shift()/pop_front operation
53 // OR, by reimplementing as a list instead of Vector.
55 debugs(5, 5, "size=" << deferred_
.size());
56 while (deferred_
.size() > 0 && fdNFree() >= RESERVED_FD
) {
57 /* NP: shift() is equivalent to pop_front(). Giving us a FIFO queue. */
58 TcpAcceptor::Pointer temp
= deferred_
.front();
59 deferred_
.erase(deferred_
.begin());
61 debugs(5, 5, "doing one.");