#include <TcpAcceptor.h>

Inheritance diagram for Comm::TcpAcceptor:
Collaboration diagram for Comm::TcpAcceptor:

Public Types

typedef CbcPointer< Comm::TcpAcceptorPointer
 

Public Member Functions

 TcpAcceptor (const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub)
 
 TcpAcceptor (const AnyP::PortCfgPointer &listenPort, const char *note, const Subscription::Pointer &aSub)
 
void subscribe (const Subscription::Pointer &aSub)
 
void unsubscribe (const char *reason)
 
void acceptNext ()
 
void notify (const Comm::Flag flag, const Comm::ConnectionPointer &details) const
 Call the subscribed callback handler with details about a new connection. More...
 
bool canBeCalled (AsyncCall &call) const
 whether we can be called More...
 
void callStart (AsyncCall &call)
 
virtual void callEnd ()
 called right after the called job method More...
 
virtual void callException (const std::exception &e)
 called when the job throws during an async call More...
 
virtual void * toCbdata ()=0
 

Static Public Member Functions

static bool okToAccept ()
 
static Pointer Start (AsyncJob *job)
 starts a freshly created job (i.e., makes the job asynchronous) More...
 

Public Attributes

int errcode
 errno code of the last accept() or listen() action if one occurred. More...
 

Protected Member Functions

void deleteThis (const char *aReason)
 
void mustStop (const char *aReason)
 
bool done () const
 the job is destroyed in callEnd() when done() More...
 

Protected Attributes

const char * stopReason
 reason for forcing done() to be true More...
 
const char * typeName
 kid (leaf) class name, for debugging More...
 
AsyncCall::Pointer inCall
 the asynchronous call being handled, if any More...
 
const InstanceId< AsyncJobid
 job identifier More...
 

Private Member Functions

 CBDATA_CLASS (TcpAcceptor)
 
virtual void start ()
 called by AsyncStart; do not call directly More...
 
virtual bool doneAll () const
 whether positive goal has been reached More...
 
virtual void swanSong ()
 
virtual const char * status () const
 internal cleanup; do not call directly More...
 
 TcpAcceptor (const TcpAcceptor &)
 
void acceptOne ()
 
Comm::Flag oldAccept (Comm::ConnectionPointer &details)
 
void setListen ()
 
void handleClosure (const CommCloseCbParams &io)
 
bool intendedForUserConnections () const
 whether we are listening on one of the squid.conf *ports More...
 

Static Private Member Functions

static void doAccept (int fd, void *data)
 Method callback for whenever an FD is ready to accept a client connection. More...
 

Private Attributes

Subscription::Pointer theCallSub
 used to generate AsyncCalls handling our events. More...
 
ConnectionPointer conn
 
AnyP::PortCfgPointer listenPort_
 configuration details of the listening port (if provided) More...
 
AsyncCall::Pointer closer_
 listen socket closure handler More...
 

Friends

class AcceptLimiter
 

Detailed Description

Listens on a Comm::Connection for new incoming connections and emits an active Comm::Connection descriptor for the new client.

Handles all event limiting required to quash inbound connection floods within the global FD limits of available Squid_MaxFD and client_ip_max_connections.

Fills the emitted connection with all connection details able to be looked up. Currently these are the local/remote IP:port details and the listening socket transparent-mode flag.

Definition at line 38 of file TcpAcceptor.h.

Member Typedef Documentation

◆ Pointer

Constructor & Destructor Documentation

◆ TcpAcceptor() [1/3]

Comm::TcpAcceptor::TcpAcceptor ( const TcpAcceptor )
private

◆ TcpAcceptor() [2/3]

Comm::TcpAcceptor::TcpAcceptor ( const Comm::ConnectionPointer conn,
const char *  note,
const Subscription::Pointer aSub 
)

Definition at line 43 of file TcpAcceptor.cc.

◆ TcpAcceptor() [3/3]

Comm::TcpAcceptor::TcpAcceptor ( const AnyP::PortCfgPointer listenPort,
const char *  note,
const Subscription::Pointer aSub 
)

Definition at line 51 of file TcpAcceptor.cc.

Member Function Documentation

◆ acceptNext()

void Comm::TcpAcceptor::acceptNext ( )

Try and accept another connection (synchronous). If one is pending already the subscribed callback handler will be scheduled to handle it before this method returns.

Definition at line 314 of file TcpAcceptor.cc.

References acceptOne(), conn, debugs, HERE(), Comm::IsConnOpen(), and Must.

Referenced by doAccept().

◆ acceptOne()

◆ callEnd()

void AsyncJob::callEnd ( )
virtualinherited

◆ callException()

◆ callStart()

void AsyncJob::callStart ( AsyncCall call)
inherited

◆ canBeCalled()

bool AsyncJob::canBeCalled ( AsyncCall call) const
inherited

Definition at line 101 of file AsyncJob.cc.

References AsyncCall::cancel(), debugs, HERE(), AsyncJob::inCall, and NULL.

Referenced by AsyncJob::swanSong().

◆ CBDATA_CLASS()

Comm::TcpAcceptor::CBDATA_CLASS ( TcpAcceptor  )
private

◆ deleteThis()

void AsyncJob::deleteThis ( const char *  aReason)
protectedinherited

◆ doAccept()

void Comm::TcpAcceptor::doAccept ( int  fd,
void *  data 
)
staticprivate

This private callback is called whenever a filedescriptor is ready to dupe itself and fob off an accept()ed connection

It will either do that accept operation. Or if there are not enough FD available to do the clone safely will push the listening FD into a list of deferred operations. The list gets kicked and the dupe/accept() actually done later when enough sockets become available.

Definition at line 221 of file TcpAcceptor.cc.

References acceptNext(), data, debugs, Comm::AcceptLimiter::defer(), fatal(), fatalf(), HERE(), Comm::AcceptLimiter::Instance(), isOpen(), Must, and okToAccept().

Referenced by acceptOne(), and start().

◆ done()

◆ doneAll()

bool Comm::TcpAcceptor::doneAll ( ) const
privatevirtual

Reimplemented from AsyncJob.

Definition at line 91 of file TcpAcceptor.cc.

References conn, AsyncJob::doneAll(), Comm::IsConnOpen(), NULL, and theCallSub.

◆ handleClosure()

void Comm::TcpAcceptor::handleClosure ( const CommCloseCbParams io)
private

called when listening descriptor is closed by an external force such as clientHttpConnectionsClose()

Definition at line 204 of file TcpAcceptor.cc.

References closer_, conn, AsyncJob::done(), Must, and NULL.

Referenced by setListen().

◆ intendedForUserConnections()

bool Comm::TcpAcceptor::intendedForUserConnections ( ) const
inlineprivate

Definition at line 107 of file TcpAcceptor.h.

Referenced by acceptOne().

◆ mustStop()

void AsyncJob::mustStop ( const char *  aReason)
protectedinherited

Definition at line 69 of file AsyncJob.cc.

References debugs, AsyncJob::inCall, Must, NULL, AsyncJob::stopReason, and AsyncJob::typeName.

Referenced by HttpStateData::abortAll(), Ftp::Client::abortAll(), acceptOne(), Adaptation::Ecap::XactionRep::adaptationAborted(), Adaptation::AccessCheck::callBack(), AsyncJob::callException(), Security::PeerConnector::connectionClosed(), HttpStateData::continueAfterParsingHeader(), Ftp::Client::ctrlClosed(), Adaptation::Iterator::handleAdaptationBlock(), Adaptation::Iterator::handleAdaptationError(), Log::TcpLogger::handleClosure(), Adaptation::Icap::Xaction::handleCommClosed(), Mgr::Forwarder::handleError(), Ipc::Forwarder::handleError(), Ipc::Forwarder::handleException(), Ipc::Inquirer::handleException(), HttpStateData::handleMoreRequestBodyAvailable(), Ipc::Inquirer::handleRemoteAck(), Ipc::Forwarder::handleTimeout(), HttpStateData::httpStateConnClosed(), HttpStateData::httpTimeout(), Comm::ConnOpener::noteAbort(), Adaptation::Icap::ModXact::noteBodyConsumerAborted(), Snmp::Forwarder::noteCommClosed(), Snmp::Inquirer::noteCommClosed(), Mgr::Inquirer::noteCommClosed(), Mgr::Forwarder::noteCommClosed(), Mgr::StoreToCommWriter::noteCommClosed(), Adaptation::Icap::Xaction::noteCommRead(), Rock::HeaderUpdater::noteDoneReading(), Adaptation::Iterator::noteInitiatorAborted(), Adaptation::Icap::Xaction::noteInitiatorAborted(), Adaptation::Ecap::XactionRep::noteInitiatorAborted(), HttpStateData::readReply(), Comm::ConnOpener::sendAnswer(), Rock::Rebuild::start(), Security::PeerConnector::start(), HttpStateData::start(), Ipc::UdsSender::timedout(), and HttpStateData::wroteLast().

◆ notify()

◆ okToAccept()

bool Comm::TcpAcceptor::okToAccept ( )
static

Method to test if there are enough file descriptors to open a new client connection if not the accept() will be postponed

Definition at line 243 of file TcpAcceptor.cc.

References DBG_CRITICAL, debugs, fdNFree(), RESERVED_FD, and squid_curtime.

Referenced by doAccept(), and Comm::AcceptLimiter::kick().

◆ oldAccept()

◆ setListen()

void Comm::TcpAcceptor::setListen ( )
private

New-style listen and accept routines

setListen simply registers our interest in an FD for listening. The constructor takes a callback to call when an FD has been accept()ed some time later.

Definition at line 151 of file TcpAcceptor.cc.

References SquidConfig::accept_filter, closer_, comm_add_close_handler(), Config, conn, DBG_CRITICAL, DBG_IMPORTANT, debugs, errcode, Comm::Connection::fd, handleClosure(), JobCallback, Comm::Connection::nfmark, Ip::Qos::setSockNfmark(), Ip::Qos::setSockTos(), Squid_MaxFD, status(), Comm::Connection::tos, xstrerr(), and xstrncpy().

Referenced by start().

◆ Start()

◆ start()

void Comm::TcpAcceptor::start ( )
privatevirtual

◆ status()

const char * Comm::TcpAcceptor::status ( ) const
privatevirtual

◆ subscribe()

void Comm::TcpAcceptor::subscribe ( const Subscription::Pointer aSub)

Subscribe a handler to receive calls back about new connections. Unsubscribes any existing subscribed handler.

Definition at line 60 of file TcpAcceptor.cc.

References debugs, HERE(), status(), theCallSub, and unsubscribe().

◆ swanSong()

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

◆ unsubscribe()

void Comm::TcpAcceptor::unsubscribe ( const char *  reason)

Remove the currently waiting callback subscription. Already scheduled callbacks remain scheduled.

Definition at line 68 of file TcpAcceptor.cc.

References debugs, HERE(), NULL, status(), and theCallSub.

Referenced by subscribe(), and swanSong().

Friends And Related Function Documentation

◆ AcceptLimiter

friend class AcceptLimiter
friend

Definition at line 84 of file TcpAcceptor.h.

Member Data Documentation

◆ closer_

AsyncCall::Pointer Comm::TcpAcceptor::closer_
private

Definition at line 97 of file TcpAcceptor.h.

Referenced by handleClosure(), setListen(), and swanSong().

◆ conn

ConnectionPointer Comm::TcpAcceptor::conn
private

conn being listened on for new connections Reserved for read-only use.

Definition at line 91 of file TcpAcceptor.h.

Referenced by acceptNext(), acceptOne(), doneAll(), handleClosure(), logAcceptError(), notify(), oldAccept(), setListen(), start(), status(), and swanSong().

◆ errcode

int Comm::TcpAcceptor::errcode

Definition at line 77 of file TcpAcceptor.h.

Referenced by notify(), oldAccept(), setListen(), and start().

◆ id

const InstanceId<AsyncJob> AsyncJob::id
protectedinherited

Definition at line 72 of file AsyncJob.h.

◆ inCall

◆ listenPort_

AnyP::PortCfgPointer Comm::TcpAcceptor::listenPort_
private

Definition at line 94 of file TcpAcceptor.h.

Referenced by notify().

◆ stopReason

const char* AsyncJob::stopReason
protectedinherited

◆ theCallSub

Subscription::Pointer Comm::TcpAcceptor::theCallSub
private

Definition at line 87 of file TcpAcceptor.h.

Referenced by acceptOne(), doneAll(), notify(), start(), subscribe(), and unsubscribe().

◆ typeName


The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors