AcceptLimiter.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #include "squid.h"
10 #include "comm/AcceptLimiter.h"
11 #include "comm/Connection.h"
12 #include "comm/TcpAcceptor.h"
13 #include "fde.h"
14 #include "globals.h"
15 
18 {
19  static const auto Instance_ = new AcceptLimiter();
20  return *Instance_;
21 }
22 
23 void
25 {
26  debugs(5, 5, afd->conn << "; already queued: " << deferred_.size());
27  deferred_.push_back(afd);
28 }
29 
30 void
32 {
33  for (auto it = deferred_.begin(); it != deferred_.end(); ++it) {
34  if (*it == afd) {
35  *it = nullptr; // fast. kick() will skip empty entries later.
36  debugs(5,4, "Abandoned client TCP SYN by closing socket: " << afd->conn);
37  return;
38  }
39  }
40  debugs(5,4, "Not found " << afd->conn << " in queue, size: " << deferred_.size());
41 }
42 
43 void
45 {
46  debugs(5, 5, "size=" << deferred_.size());
47  while (deferred_.size() > 0 && Comm::TcpAcceptor::okToAccept()) {
48  /* NP: shift() is equivalent to pop_front(). Giving us a FIFO queue. */
49  TcpAcceptor::Pointer temp = deferred_.front();
50  deferred_.erase(deferred_.begin());
51  if (temp.valid()) {
52  debugs(5, 5, "doing one.");
53  temp->acceptNext();
54  break;
55  }
56  }
57 }
58 
static AcceptLimiter & Instance()
void defer(const TcpAcceptor::Pointer &afd)
void removeDead(const TcpAcceptor::Pointer &afd)
static bool okToAccept()
Definition: TcpAcceptor.cc:232
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192

 

Introduction

Documentation

Support

Miscellaneous