-#include "config.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
#include "comm/AcceptLimiter.h"
-#include "comm/ListenStateData.h"
+#include "comm/Connection.h"
+#include "comm/TcpAcceptor.h"
#include "fde.h"
+#include "globals.h"
Comm::AcceptLimiter Comm::AcceptLimiter::Instance_;
-Comm::AcceptLimiter &Comm::AcceptLimiter::Instance()
+Comm::AcceptLimiter &
+Comm::AcceptLimiter::Instance()
{
return Instance_;
}
void
-Comm::AcceptLimiter::defer(Comm::ListenStateData *afd)
+Comm::AcceptLimiter::defer(const Comm::TcpAcceptor::Pointer &afd)
{
- afd->isLimited++;
- debugs(5, 5, HERE << "FD " << afd->fd << " x" << afd->isLimited);
- deferred.push_back(afd);
+ debugs(5, 5, afd->conn << "; already queued: " << deferred_.size());
+ deferred_.push_back(afd);
+}
+
+void
+Comm::AcceptLimiter::removeDead(const Comm::TcpAcceptor::Pointer &afd)
+{
+ for (auto it = deferred_.begin(); it != deferred_.end(); ++it) {
+ if (*it == afd) {
+ *it = nullptr; // fast. kick() will skip empty entries later.
+ debugs(5,4, "Abandoned client TCP SYN by closing socket: " << afd->conn);
+ return;
+ }
+ }
+ debugs(5,4, "Not found " << afd->conn << " in queue, size: " << deferred_.size());
}
void
Comm::AcceptLimiter::kick()
{
- debugs(5, 5, HERE << " size=" << deferred.size());
- if (deferred.size() > 0 && fdNFree() >= RESERVED_FD) {
- debugs(5, 5, HERE << " doing one.");
+ debugs(5, 5, "size=" << deferred_.size());
+ while (deferred_.size() > 0 && Comm::TcpAcceptor::okToAccept()) {
/* NP: shift() is equivalent to pop_front(). Giving us a FIFO queue. */
- ListenStateData *temp = deferred.shift();
- temp->isLimited--;
- temp->acceptNext();
+ TcpAcceptor::Pointer temp = deferred_.front();
+ deferred_.erase(deferred_.begin());
+ if (temp.valid()) {
+ debugs(5, 5, "doing one.");
+ temp->acceptNext();
+ break;
+ }
}
}
+