#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)
 
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...
 
void handleStopRequest ()
 process external request to terminate now (i.e. during this async call) More...
 
virtual void * toCbdata ()=0
 

Static Public Member Functions

static void Start (const Pointer &job)
 

Public Attributes

const InstanceId< AsyncJobid
 job identifier More...
 

Protected Member Functions

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...
 
void deleteThis (const char *aReason)
 
void mustStop (const char *aReason)
 
bool done () const
 the job is destroyed in callEnd() when done() More...
 

Static Protected Member Functions

static bool okToAccept ()
 

Protected Attributes

int errcode
 errno code of the last accept() or listen() action if one occurred. More...
 
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...
 
bool started_ = false
 Start() has finished successfully. More...
 
bool swanSang_ = false
 swanSong() was called 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...
 
void logAcceptError (const ConnectionPointer &tcpClient) const
 

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 42 of file TcpAcceptor.cc.

◆ TcpAcceptor() [3/3]

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

Definition at line 50 of file TcpAcceptor.cc.

Member Function Documentation

◆ acceptNext()

void Comm::TcpAcceptor::acceptNext ( )
protected

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 306 of file TcpAcceptor.cc.

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

◆ acceptOne()

void Comm::TcpAcceptor::acceptOne ( )
private

◆ callEnd()

void AsyncJob::callEnd ( )
virtualinherited

◆ callException()

◆ callStart()

void AsyncJob::callStart ( AsyncCall call)
inherited

◆ canBeCalled()

bool AsyncJob::canBeCalled ( AsyncCall call) const
inherited

Definition at line 102 of file AsyncJob.cc.

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

◆ 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 212 of file TcpAcceptor.cc.

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

◆ done()

bool AsyncJob::done ( ) const
protectedinherited

◆ doneAll()

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

Reimplemented from AsyncJob.

Definition at line 92 of file TcpAcceptor.cc.

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

◆ 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 192 of file TcpAcceptor.cc.

References conn, Must, and NULL.

Referenced by setListen().

◆ handleStopRequest()

void AsyncJob::handleStopRequest ( )
inlineinherited

Definition at line 71 of file AsyncJob.h.

References AsyncJob::mustStop().

◆ intendedForUserConnections()

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

Definition at line 107 of file TcpAcceptor.h.

References listenPort_.

◆ logAcceptError()

◆ mustStop()

◆ notify()

◆ okToAccept()

bool Comm::TcpAcceptor::okToAccept ( )
staticprotected

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 234 of file TcpAcceptor.cc.

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

Referenced by 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 152 of file TcpAcceptor.cc.

References SquidConfig::accept_filter, comm_add_close_handler(), Config, conn, DBG_CRITICAL, DBG_IMPORTANT, debugs, handleClosure(), JobCallback, Squid_MaxFD, xstrerr(), and xstrncpy().

◆ start()

void Comm::TcpAcceptor::start ( )
privatevirtual

Reimplemented from AsyncJob.

Definition at line 74 of file TcpAcceptor.cc.

References COMM_SELECT_READ, conn, debugs, HERE(), Comm::IsConnOpen(), Must, CodeContext::Reset(), and Comm::SetSelect().

◆ Start()

◆ status()

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

for debugging, starts with space

Reimplemented from AsyncJob.

Definition at line 125 of file TcpAcceptor.cc.

References MemBuf::append(), Packable::appendf(), conn, MemBuf::content(), MAX_IPSTRLEN, NULL, MemBuf::reset(), and AsyncJob::status().

◆ subscribe()

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

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

Definition at line 59 of file TcpAcceptor.cc.

References debugs, and HERE().

◆ swanSong()

void Comm::TcpAcceptor::swanSong ( )
privatevirtual

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

◆ unsubscribe()

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

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

Definition at line 67 of file TcpAcceptor.cc.

References debugs, HERE(), and NULL.

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.

◆ 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.

◆ errcode

int Comm::TcpAcceptor::errcode
protected

Definition at line 78 of file TcpAcceptor.h.

◆ id

const InstanceId<AsyncJob> AsyncJob::id
inherited

Definition at line 73 of file AsyncJob.h.

◆ inCall

AsyncCall::Pointer AsyncJob::inCall
protectedinherited

◆ listenPort_

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

Definition at line 94 of file TcpAcceptor.h.

Referenced by intendedForUserConnections().

◆ started_

bool AsyncJob::started_ = false
protectedinherited

Definition at line 83 of file AsyncJob.h.

Referenced by AsyncJob::~AsyncJob(), AsyncJob::callEnd(), and AsyncJob::Start().

◆ stopReason

const char* AsyncJob::stopReason
protectedinherited

◆ swanSang_

bool AsyncJob::swanSang_ = false
protectedinherited

Definition at line 84 of file AsyncJob.h.

Referenced by AsyncJob::~AsyncJob(), and AsyncJob::callEnd().

◆ theCallSub

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

Definition at line 87 of file TcpAcceptor.h.

◆ typeName


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors