#include <TcpAcceptor.h>

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

Public Types

typedef CbcPointer
< Comm::TcpAcceptor
Pointer
 

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

int32_t isLimited
 whether this socket is delayed and on the AcceptLimiter queue. 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...
 
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 bool okToAccept ()
 
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

Constructor & Destructor Documentation

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

Definition at line 43 of file TcpAcceptor.cc.

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

Definition at line 52 of file TcpAcceptor.cc.

Member Function Documentation

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

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

Referenced by doAccept().

void Comm::TcpAcceptor::acceptOne ( )
private
void AsyncJob::callEnd ( )
virtualinherited
void AsyncJob::callStart ( AsyncCall call)
inherited
bool AsyncJob::canBeCalled ( AsyncCall call) const
inherited

Definition at line 101 of file AsyncJob.cc.

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

Comm::TcpAcceptor::CBDATA_CLASS ( TcpAcceptor  )
private
void AsyncJob::deleteThis ( const char *  aReason)
protectedinherited
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 223 of file TcpAcceptor.cc.

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

bool AsyncJob::done ( ) const
protectedinherited

Definition at line 90 of file AsyncJob.cc.

References AsyncJob::doneAll(), NULL, and AsyncJob::stopReason.

Referenced by AsyncJob::callEnd(), and Downloader::downloadFinished().

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

Reimplemented from AsyncJob.

Definition at line 93 of file TcpAcceptor.cc.

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

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

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

Definition at line 206 of file TcpAcceptor.cc.

References conn, Must, and NULL.

Referenced by setListen().

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

Definition at line 108 of file TcpAcceptor.h.

References listenPort_.

bool Comm::TcpAcceptor::okToAccept ( )
staticprivate

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

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

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

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

void Comm::TcpAcceptor::start ( )
privatevirtual

Reimplemented from AsyncJob.

Definition at line 77 of file TcpAcceptor.cc.

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

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

for debugging, starts with space

Reimplemented from AsyncJob.

Definition at line 126 of file TcpAcceptor.cc.

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

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

References debugs, and HERE().

void Comm::TcpAcceptor::swanSong ( )
privatevirtual
virtual void* CbdataParent::toCbdata ( )
pure virtualinherited
void Comm::TcpAcceptor::unsubscribe ( const char *  reason)

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

Definition at line 70 of file TcpAcceptor.cc.

References debugs, HERE(), and NULL.

Friends And Related Function Documentation

friend class AcceptLimiter
friend

Definition at line 80 of file TcpAcceptor.h.

Member Data Documentation

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

Definition at line 94 of file TcpAcceptor.h.

ConnectionPointer Comm::TcpAcceptor::conn
private

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

Definition at line 88 of file TcpAcceptor.h.

int Comm::TcpAcceptor::errcode

Definition at line 77 of file TcpAcceptor.h.

const InstanceId<AsyncJob> AsyncJob::id
protectedinherited

Definition at line 70 of file AsyncJob.h.

AsyncCall::Pointer AsyncJob::inCall
protectedinherited
int32_t Comm::TcpAcceptor::isLimited
protected

Definition at line 81 of file TcpAcceptor.h.

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

Definition at line 91 of file TcpAcceptor.h.

Referenced by intendedForUserConnections().

const char* AsyncJob::stopReason
protectedinherited
Subscription::Pointer Comm::TcpAcceptor::theCallSub
private

Definition at line 84 of file TcpAcceptor.h.


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors