#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

virtual bool doneAll () const
 whether positive goal has been reached More...
 
 ConnOpener (const 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...
 
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

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...
 
bool started_ = false
 Start() has finished successfully. More...
 
bool swanSang_ = false
 swanSong() was called 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

Asynchronously opens a TCP connection. Returns CommConnectCbParams: either Comm::OK with an open connection or another Comm::Flag with a closed one.

Definition at line 24 of file ConnOpener.h.

Member Typedef Documentation

◆ Pointer

Definition at line 29 of file ConnOpener.h.

Constructor & Destructor Documentation

◆ ConnOpener() [1/2]

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

Definition at line 33 of file ConnOpener.cc.

References assert, conn_, debugs, and Comm::Connection::isOpen().

◆ ~ConnOpener()

Comm::ConnOpener::~ConnOpener ( )

Definition at line 54 of file ConnOpener.cc.

References 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 102 of file AsyncJob.cc.

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

◆ cancelSleep()

void Comm::ConnOpener::cancelSleep ( )
private

Definition at line 410 of file ConnOpener.cc.

References debugs.

◆ 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 174 of file ConnOpener.cc.

References comm_remove_close_handler(), COMM_SELECT_WRITE, debugs, fd_table, Must, NULL, Comm::SetSelect(), fde::timeout, fde::timeoutHandler, fde::write_data, and fde::write_handler.

◆ closeFd()

void Comm::ConnOpener::closeFd ( )
private

Definition at line 220 of file ConnOpener.cc.

References comm_close.

◆ connected()

void Comm::ConnOpener::connected ( )
private

Definition at line 328 of file ConnOpener.cc.

References fd_table, Must, and Comm::OK.

◆ createFd()

bool Comm::ConnOpener::createFd ( )
private

Create a socket for the future connection or return false. If false is returned, done() is guaranteed to return true and end the job.

Definition at line 279 of file ConnOpener.cc.

References assert, comm_add_close_handler(), comm_openex(), debugs, earlyAbort(), Comm::ERR_CONNECT, fd_table, CachePeer::flags, JobCallback, Must, NULL, CachePeer::params, Ip::Qos::setSockNfmark(), Ip::Qos::setSockTos(), squid_curtime, Squid_MaxFD, and timeout().

◆ DelayedConnectRetry()

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

Definition at line 494 of file ConnOpener.cc.

References assert, JobCallback, restart(), and ScheduleCallHere.

Referenced by retrySleep().

◆ deleteThis()

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

◆ doConnect()

◆ done()

bool AsyncJob::done ( ) const
protectedinherited

◆ doneAll()

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

Reimplemented from AsyncJob.

Definition at line 60 of file ConnOpener.cc.

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

◆ 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 452 of file ConnOpener.cc.

References CommCommonCbParams::conn, debugs, Comm::ERR_CLOSING, HERE(), NULL, and CommCommonCbParams::xerrno.

Referenced by createFd().

◆ getHost()

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

Definition at line 113 of file ConnOpener.cc.

◆ handleStopRequest()

void AsyncJob::handleStopRequest ( )
inlineinherited

Definition at line 71 of file AsyncJob.h.

References AsyncJob::mustStop().

◆ InProgressConnectRetry()

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

Definition at line 476 of file ConnOpener.cc.

References assert, doConnect(), JobCallback, and ScheduleCallHere.

Referenced by doConnect().

◆ keepFd()

void Comm::ConnOpener::keepFd ( )
private

Definition at line 239 of file ConnOpener.cc.

References Must, and NULL.

◆ 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 431 of file ConnOpener.cc.

References addrinfo::ai_addr, addrinfo::ai_addrlen, DBG_IMPORTANT, debugs, Ip::Address::FreeAddr(), HERE(), Ip::Address::InitAddr(), NULL, and xstrerr().

◆ mustStop()

◆ operator=()

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

◆ restart()

void Comm::ConnOpener::restart ( )
private

Definition at line 267 of file ConnOpener.cc.

References debugs.

Referenced by DelayedConnectRetry().

◆ retrySleep()

void Comm::ConnOpener::retrySleep ( )
private

Definition at line 398 of file ConnOpener.cc.

References DelayedConnectRetry(), eventAdd(), and Must.

◆ sendAnswer()

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

Connection attempt are completed. One way or the other. Pass the results back to the external handler.

Definition at line 123 of file ConnOpener.cc.

References assert, Config, debugs, ipcacheMarkBadAddr(), ipcacheMarkGoodAddr(), netdbDeleteAddrNetwork(), NULL, Comm::OK, SquidConfig::onoff, CachePeer::params, ScheduleCallHere, and SquidConfig::test_reachability.

◆ setHost()

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

Definition at line 101 of file ConnOpener.cc.

References NULL, safe_free, and xstrdup.

Referenced by idnsInitVC(), and peerProbeConnect().

◆ start()

void Comm::ConnOpener::start ( )
protectedvirtual

Reimplemented from AsyncJob.

Definition at line 251 of file ConnOpener.cc.

References Ip::EnableIpv6, IPV6_SPECIAL_V4MAPPING, Must, and NULL.

◆ Start()

◆ status()

◆ swanSong()

void Comm::ConnOpener::swanSong ( )
protectedvirtual

Reimplemented from AsyncJob.

Definition at line 78 of file ConnOpener.cc.

References Comm::ERR_CONNECT, NULL, and AsyncJob::swanSong().

◆ 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 465 of file ConnOpener.cc.

References debugs, HERE(), NULL, and Comm::TIMEOUT.

Referenced by createFd().

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

Member Data Documentation

◆ callback_

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

Definition at line 71 of file ConnOpener.h.

◆ calls_

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

◆ conn_

Comm::ConnectionPointer Comm::ConnOpener::conn_
private

Definition at line 70 of file ConnOpener.h.

Referenced by ConnOpener().

◆ deadline_

time_t Comm::ConnOpener::deadline_
private

Definition at line 77 of file ConnOpener.h.

◆ failRetries_

int Comm::ConnOpener::failRetries_
private

Definition at line 74 of file ConnOpener.h.

◆ host_

char* Comm::ConnOpener::host_
private

Definition at line 68 of file ConnOpener.h.

◆ id

const InstanceId<AsyncJob> AsyncJob::id
inherited

Definition at line 73 of file AsyncJob.h.

◆ inCall

AsyncCall::Pointer AsyncJob::inCall
protectedinherited

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

◆ temporaryFd_

int Comm::ConnOpener::temporaryFd_
private

Definition at line 69 of file ConnOpener.h.

◆ totalTries_

int Comm::ConnOpener::totalTries_
private

Definition at line 73 of file ConnOpener.h.

◆ typeName


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors