#include <ConnOpener.h>

Inheritance diagram for Comm::ConnOpener:
Collaboration diagram for Comm::ConnOpener:

Classes

struct  Calls
 handles to calls which we may need to cancel. More...
 

Public Types

typedef CbcPointer< ConnOpenerPointer
 

Public Member Functions

void noteAbort ()
 
virtual bool doneAll () const
 whether positive goal has been reached More...
 
 ConnOpener (Comm::ConnectionPointer &, const AsyncCall::Pointer &handler, time_t connect_timeout)
 
 ~ConnOpener ()
 
void setHost (const char *)
 set the hostname note for this connection More...
 
const char * getHost () const
 get the hostname noted for this 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...
 

Protected Member Functions

virtual void start ()
 called by AsyncStart; do not call directly More...
 
virtual void swanSong ()
 
void deleteThis (const char *aReason)
 
void mustStop (const char *aReason)
 
bool done () const
 the job is destroyed in callEnd() when done() More...
 
virtual const char * status () const
 internal cleanup; do not call directly 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 (ConnOpener)
 
 ConnOpener (const ConnOpener &)
 
ConnOpeneroperator= (const ConnOpener &c)
 
void earlyAbort (const CommCloseCbParams &)
 
void timeout (const CommTimeoutCbParams &)
 
void sendAnswer (Comm::Flag errFlag, int xerrno, const char *why)
 
void doConnect ()
 Make an FD connection attempt. More...
 
void connected ()
 
void lookupLocalAddress ()
 
void retrySleep ()
 Close and wait a little before trying to open and connect again. More...
 
void restart ()
 called at the end of Comm::ConnOpener::DelayedConnectRetry event More...
 
bool createFd ()
 
void closeFd ()
 cleans I/O state and ends I/O for temporaryFd_ More...
 
void keepFd ()
 cleans I/O state and moves temporaryFd_ to the conn_ for long-term use More...
 
void cleanFd ()
 
void cancelSleep ()
 cleans up this job sleep state More...
 

Static Private Member Functions

static void InProgressConnectRetry (int fd, void *data)
 
static void DelayedConnectRetry (void *data)
 

Private Attributes

char * host_
 domain name we are trying to connect to. More...
 
int temporaryFd_
 the FD being opened. Do NOT set conn_->fd until it is fully open. More...
 
Comm::ConnectionPointer conn_
 single connection currently to be opened. More...
 
AsyncCall::Pointer callback_
 handler to be called on connection completion. More...
 
int totalTries_
 total number of connection attempts over all destinations so far. More...
 
int failRetries_
 number of retries current destination has been tried. More...
 
time_t deadline_
 if we are not done by then, we will call back with Comm::TIMEOUT More...
 
struct Comm::ConnOpener::Calls calls_
 

Detailed Description

Async-opener of a Comm connection.

Definition at line 25 of file ConnOpener.h.

Member Typedef Documentation

◆ Pointer

Definition at line 32 of file ConnOpener.h.

Constructor & Destructor Documentation

◆ ConnOpener() [1/2]

Comm::ConnOpener::ConnOpener ( Comm::ConnectionPointer c,
const AsyncCall::Pointer handler,
time_t  connect_timeout 
)

Definition at line 33 of file ConnOpener.cc.

References debugs.

◆ ~ConnOpener()

Comm::ConnOpener::~ConnOpener ( )

Definition at line 46 of file ConnOpener.cc.

References host_, and safe_free.

◆ ConnOpener() [2/2]

Comm::ConnOpener::ConnOpener ( const ConnOpener )
private

Member Function Documentation

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

◆ cancelSleep()

void Comm::ConnOpener::cancelSleep ( )
private

Definition at line 388 of file ConnOpener.cc.

References calls_, conn_, debugs, and Comm::ConnOpener::Calls::sleep_.

Referenced by swanSong().

◆ CBDATA_CLASS()

Comm::ConnOpener::CBDATA_CLASS ( ConnOpener  )
private

◆ cleanFd()

void Comm::ConnOpener::cleanFd ( )
private

cleans up this job I/O state without closing temporaryFd required before closing temporaryFd or keeping it in conn_ leaves FD bare so must only be called via closeFd() or keepFd()

Definition at line 153 of file ConnOpener.cc.

References calls_, AsyncCall::cancel(), comm_remove_close_handler(), COMM_SELECT_WRITE, conn_, debugs, Comm::ConnOpener::Calls::earlyAbort_, fd_table, HERE(), Must, NULL, Comm::SetSelect(), temporaryFd_, fde::timeout, Comm::ConnOpener::Calls::timeout_, fde::timeoutHandler, fde::write_data, and fde::write_handler.

Referenced by closeFd(), and keepFd().

◆ closeFd()

void Comm::ConnOpener::closeFd ( )
private

Definition at line 199 of file ConnOpener.cc.

References cleanFd(), comm_close, and temporaryFd_.

Referenced by retrySleep(), and swanSong().

◆ connected()

void Comm::ConnOpener::connected ( )
private

◆ createFd()

◆ DelayedConnectRetry()

void Comm::ConnOpener::DelayedConnectRetry ( void *  data)
staticprivate

Definition at line 472 of file ConnOpener.cc.

References assert, data, JobCallback, restart(), ScheduleCallHere, and CbcPointer< Cbc >::valid().

Referenced by retrySleep().

◆ deleteThis()

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

◆ doConnect()

◆ done()

◆ doneAll()

bool Comm::ConnOpener::doneAll ( ) const
virtual

◆ earlyAbort()

void Comm::ConnOpener::earlyAbort ( const CommCloseCbParams io)
private

Abort connection attempt. Handles the case(s) when a partially setup connection gets closed early.

Definition at line 430 of file ConnOpener.cc.

References calls_, CommCommonCbParams::conn, debugs, Comm::ConnOpener::Calls::earlyAbort_, Comm::ERR_CLOSING, HERE(), NULL, sendAnswer(), and CommCommonCbParams::xerrno.

Referenced by createFd().

◆ getHost()

const char * Comm::ConnOpener::getHost ( ) const

Definition at line 101 of file ConnOpener.cc.

References host_.

◆ InProgressConnectRetry()

void Comm::ConnOpener::InProgressConnectRetry ( int  fd,
void *  data 
)
staticprivate

Definition at line 454 of file ConnOpener.cc.

References assert, data, doConnect(), JobCallback, ScheduleCallHere, and CbcPointer< Cbc >::valid().

Referenced by doConnect().

◆ keepFd()

void Comm::ConnOpener::keepFd ( )
private

Definition at line 218 of file ConnOpener.cc.

References cleanFd(), conn_, Comm::Connection::fd, Must, NULL, and temporaryFd_.

Referenced by connected().

◆ lookupLocalAddress()

void Comm::ConnOpener::lookupLocalAddress ( )
private

Lookup local-end address and port of the TCP link just opened. This ensure the connection local details are set correctly

Definition at line 409 of file ConnOpener.cc.

References addr, addrinfo::ai_addr, addrinfo::ai_addrlen, conn_, DBG_IMPORTANT, debugs, Comm::Connection::fd, Ip::Address::FreeAddr(), HERE(), Ip::Address::InitAddr(), Comm::Connection::local, NULL, and xstrerr().

Referenced by connected().

◆ 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(), Comm::TcpAcceptor::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(), Http::Tunneler::handleConnectionClosure(), Mgr::Forwarder::handleError(), Ipc::Forwarder::handleError(), Ipc::Forwarder::handleException(), Ipc::Inquirer::handleException(), HttpStateData::handleMoreRequestBodyAvailable(), Ipc::Inquirer::handleRemoteAck(), Ipc::Forwarder::handleTimeout(), HttpStateData::httpStateConnClosed(), HttpStateData::httpTimeout(), 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(), sendAnswer(), Rock::Rebuild::start(), Security::PeerConnector::start(), HttpStateData::start(), Ipc::UdsSender::timedout(), and HttpStateData::wroteLast().

◆ noteAbort()

void Comm::ConnOpener::noteAbort ( )
inline

Definition at line 30 of file ConnOpener.h.

References AsyncJob::mustStop().

◆ operator=()

ConnOpener& Comm::ConnOpener::operator= ( const ConnOpener c)
private

◆ restart()

void Comm::ConnOpener::restart ( )
private

Definition at line 246 of file ConnOpener.cc.

References calls_, conn_, createFd(), debugs, doConnect(), and Comm::ConnOpener::Calls::sleep_.

Referenced by DelayedConnectRetry().

◆ retrySleep()

void Comm::ConnOpener::retrySleep ( )
private

Definition at line 376 of file ConnOpener.cc.

References calls_, closeFd(), DelayedConnectRetry(), eventAdd(), Must, and Comm::ConnOpener::Calls::sleep_.

Referenced by doConnect().

◆ sendAnswer()

void Comm::ConnOpener::sendAnswer ( Comm::Flag  errFlag,
int  xerrno,
const char *  why 
)
private

◆ setHost()

void Comm::ConnOpener::setHost ( const char *  new_host)

◆ Start()

◆ start()

◆ status()

◆ swanSong()

void Comm::ConnOpener::swanSong ( )
protectedvirtual

◆ timeout()

void Comm::ConnOpener::timeout ( const CommTimeoutCbParams )
private

Handles the case(s) when a partially setup connection gets timed out. NP: When commSetConnTimeout accepts generic CommCommonCbParams this can die.

Definition at line 443 of file ConnOpener.cc.

References calls_, conn_, debugs, HERE(), NULL, sendAnswer(), Comm::TIMEOUT, and Comm::ConnOpener::Calls::timeout_.

Referenced by createFd().

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

Member Data Documentation

◆ callback_

AsyncCall::Pointer Comm::ConnOpener::callback_
private

Definition at line 74 of file ConnOpener.h.

Referenced by createFd(), doneAll(), sendAnswer(), and swanSong().

◆ calls_

struct Comm::ConnOpener::Calls Comm::ConnOpener::calls_
private

◆ conn_

◆ deadline_

time_t Comm::ConnOpener::deadline_
private

Definition at line 80 of file ConnOpener.h.

Referenced by createFd().

◆ failRetries_

int Comm::ConnOpener::failRetries_
private

Definition at line 77 of file ConnOpener.h.

Referenced by doConnect().

◆ host_

char* Comm::ConnOpener::host_
private

Definition at line 71 of file ConnOpener.h.

Referenced by createFd(), getHost(), sendAnswer(), setHost(), and ~ConnOpener().

◆ id

const InstanceId<AsyncJob> AsyncJob::id
protectedinherited

Definition at line 72 of file AsyncJob.h.

◆ inCall

◆ stopReason

const char* AsyncJob::stopReason
protectedinherited

◆ temporaryFd_

int Comm::ConnOpener::temporaryFd_
private

Definition at line 72 of file ConnOpener.h.

Referenced by cleanFd(), closeFd(), connected(), createFd(), doConnect(), doneAll(), keepFd(), and swanSong().

◆ totalTries_

int Comm::ConnOpener::totalTries_
private

Definition at line 76 of file ConnOpener.h.

Referenced by doConnect().

◆ typeName


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors