Comm Namespace Reference

Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.

Classes

class  AcceptLimiter
 
class  CbEntry
 
class  Connection
 
class  ConnOpener
 
class  IoCallback
 Details about a particular Comm IO callback event. More...
 
class  TcpAcceptor
 
class  TcpKeepAlive
 Configuration settings for the TCP keep-alive feature. More...
 

Typedefs

typedef RefCount< Comm::ConnectionConnectionPointer
 

Enumerations

enum  Flag {
  OK = 0 ,
  COMM_ERROR = -1 ,
  TIMEOUT = -4 ,
  SHUTDOWN = -5 ,
  IDLE = -6 ,
  INPROGRESS = -7 ,
  ERR_CONNECT = -8 ,
  ERR_DNS = -9 ,
  ERR_CLOSING = -10 ,
  ERR_PROTOCOL = -11 ,
  ENDFILE = -12 ,
  ERR__END__ = -999999
}
 
enum  iocb_type {
  IOCB_NONE ,
  IOCB_READ ,
  IOCB_WRITE
}
 Type of IO callbacks the Comm layer deals with. More...
 

Functions

std::ostream & operator<< (std::ostream &, const Connection &)
 
std::ostream & operator<< (std::ostream &os, const ConnectionPointer &conn)
 
bool IsConnOpen (const Comm::ConnectionPointer &conn)
 
void SetSelect (int, unsigned int, PF *, void *, time_t)
 Mark an FD to be watched for its IO status. More...
 
void CallbackTableInit ()
 
void CallbackTableDestruct ()
 
void SelectLoopInit (void)
 Initialize the module on Squid startup. More...
 
void ResetSelect (int fd)
 reset/undo/unregister the watch for an FD which was set by Comm::SetSelect() More...
 
Comm::Flag DoSelect (int)
 Do poll and trigger callback functions as appropriate. More...
 
void QuickPollRequired (void)
 
void Read (const Comm::ConnectionPointer &conn, AsyncCall::Pointer &callback)
 
bool MonitorsRead (int fd)
 whether the FD socket is being monitored for read More...
 
Comm::Flag ReadNow (CommIoCbParams &params, SBuf &buf)
 
void ReadCancel (int fd, AsyncCall::Pointer &callback)
 Cancel the read pending on FD. No action if none pending. More...
 
time_t MortalReadTimeout (const time_t startTime, const time_t lifetimeLimit)
 maximum read delay for readers with limited lifetime More...
 
void ApplyTcpKeepAlive (int fd, const TcpKeepAlive &)
 apply configured TCP keep-alive settings to the given FD socket More...
 
void Write (const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
 
void Write (const Comm::ConnectionPointer &conn, MemBuf *mb, AsyncCall::Pointer &callback)
 
void WriteCancel (const Comm::ConnectionPointer &conn, const char *reason)
 Cancel the write pending on FD. No action if none pending. More...
 

Variables

PF HandleWrite
 
CbEntryiocb_table
 
PF HandleRead
 callback handler to process an FD which is available for reading More...
 

Typedef Documentation

◆ ConnectionPointer

Definition at line 28 of file forward.h.

Enumeration Type Documentation

◆ Flag

enum Comm::Flag
Enumerator
OK 
COMM_ERROR 
TIMEOUT 
SHUTDOWN 
IDLE 
INPROGRESS 
ERR_CONNECT 
ERR_DNS 
ERR_CLOSING 
ERR_PROTOCOL 
ENDFILE 

read(2) returned success, but with 0 bytes

ERR__END__ 

Definition at line 15 of file Flag.h.

◆ iocb_type

Enumerator
IOCB_NONE 
IOCB_READ 
IOCB_WRITE 

Definition at line 22 of file IoCallback.h.

Function Documentation

◆ ApplyTcpKeepAlive()

◆ CallbackTableDestruct()

void Comm::CallbackTableDestruct ( )

◆ CallbackTableInit()

void Comm::CallbackTableInit ( )

◆ DoSelect()

Comm::Flag Comm::DoSelect ( int  msec)

Perform a select() or equivalent call. This is used by the main select loop engine to check for FD with IO available.

Check all connections for new connections and input data that is to be processed. Also check for connections with data queued and whether we can write it out.

Called to do the new-style IO, courtesy of of squid (like most of this new IO code). This routine handles the stuff we've hidden in comm_setselect and fd_table[] and calls callbacks for IO ready events.

Parameters
msecmilliseconds to poll for (limited by max_poll_time)

Check all connections for new connections and input data that is to be processed. Also check for connections with data queued and whether we can write it out.

Called to do the new-style IO, courtesy of of squid (like most of this new IO code). This routine handles the stuff we've hidden in comm_setselect and fd_table[] and calls callbacks for IO ready events.

Definition at line 311 of file ModDevPoll.cc.

References COMM_ERROR, comm_flush_updates(), COMM_SELECT_READ, COMM_SELECT_WRITE, StatHist::count(), DEBUG_DEVPOLL, debugs, devpoll_fd, devpoll_state, do_poll, dpoll_nfds, F(), fd_table, getCurrentTime(), ignoreErrno(), int, max_poll_time, NULL, OK, StatCounters::select_fds, StatCounters::select_fds_hist, StatCounters::select_loops, SetSelect(), statCounter, _devpoll_state::state, and TIMEOUT.

Referenced by CommSelectEngine::checkEvents().

◆ IsConnOpen()

bool Comm::IsConnOpen ( const Comm::ConnectionPointer conn)

Definition at line 27 of file Connection.cc.

References conn.

Referenced by Mgr::Forwarder::Forwarder(), Security::PeerConnector::PeerConnector(), FwdState::~FwdState(), Ftp::Gateway::~Gateway(), helper_stateful_server::~helper_stateful_server(), Ident::IdentStateData::~IdentStateData(), AnyP::PortCfg::~PortCfg(), Helper::Session::~Session(), Ipc::UdsOp::~UdsOp(), Ftp::Relay::abortOnData(), Comm::TcpAcceptor::acceptNext(), Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), clientReplyContext::buildReplyHeader(), ClientHttpRequest::callException(), Ftp::Server::callException(), Security::PeerConnector::certDownloadingDone(), Ftp::Server::checkDataConnPost(), Ftp::Server::checkDataConnPre(), IdentLookup::checkForAsync(), Mgr::Inquirer::cleanup(), Snmp::Inquirer::cleanup(), clientCheckPinning(), clientListenerConnectionOpened(), Ftp::Server::clientPinnedConnectionClosed(), clientProcessRequestFinished(), ClientRequestContext::clientRedirectDone(), clientSocketRecipient(), Server::clientWriteDone(), Ftp::Channel::close(), Mgr::StoreToCommWriter::close(), TunnelStateData::closeConnections(), Ftp::Server::closeDataConnection(), FwdState::closePendingConnection(), TunnelStateData::closePendingConnection(), Ftp::Client::closeServer(), HttpStateData::closeServer(), FwdState::closeServerConnection(), comm_import_opened(), comm_init_opened(), comm_poll_udp_incoming(), comm_read_base(), comm_select_tcp_incoming(), comm_select_udp_incoming(), commSetConnTimeout(), FwdState::complete(), Ipc::UdsOp::conn(), Ftp::Client::connectDataChannel(), TunnelStateData::connectDone(), Ftp::Server::connectedForData(), FwdState::connectedToPeer(), CreateSession(), Http::Tunneler::disconnect(), Security::PeerConnector::disconnect(), FwdState::dispatch(), ClientHttpRequest::doCallouts(), Server::doClientRead(), Comm::TcpAcceptor::doneAll(), Server::doneAll(), Ftp::Client::doneWithServer(), HttpStateData::doneWithServer(), ConnStateData::endingShutdown(), errorSend(), HttpStateData::finishingBrokenPost(), Ftp::Channel::forget(), Ftp::Gateway::ftpAcceptDataConnection(), ftpOpenListenSocket(), ftpReadList(), ftpReadRetr(), ftpSendPORT(), Ftp::Server::handleDataReply(), Ftp::Client::handleEpsvReply(), Mgr::Forwarder::handleException(), Security::PeerConnector::handleMissingCertificates(), HttpStateData::handleMoreRequestBodyAvailable(), Ftp::Client::handlePasvReply(), FwdState::HandleStoreAbort(), Ftp::Relay::HandleStoreAbort(), Mgr::StoreToCommWriter::HandleStoreAbort(), FwdState::handleUnregisteredServerEnd(), Ftp::Gateway::haveControlChannel(), helperHandleRead(), helperStatefulHandleRead(), htcpClear(), htcpIncomingConnectionOpened(), htcpOpenPorts(), htcpQuery(), htcpSocketShutdown(), ConnStateData::httpsPeeked(), icpConnectionShutdown(), icpIncomingConnectionOpened(), icpOpenPorts(), idnsReadVC(), idnsReadVCHeader(), idnsSentQueryVC(), idnsShutdownAndFreeState(), TunnelStateData::Connection::initConnection(), Security::PeerConnector::initialize(), Ssl::PeekingPeerConnector::initialize(), IdleConnList::isAvailable(), ConnStateData::isOpen(), TunnelStateData::keepGoingAfterRead(), ConnStateData::kick(), Ftp::Gateway::listenForDataChannel(), Ftp::Server::listenForDataConnection(), Acl::ServerCertificateCheck::match(), ACLIdent::match(), Ftp::Client::maybeReadVirginBody(), HttpStateData::maybeReadVirginBody(), Ftp::Relay::mayReadVirginReplyBody(), Security::PeerConnector::negotiate(), neighbors_init(), neighborsUdpPing(), TunnelStateData::noConnections(), ClientHttpRequest::noteBodyProducerAborted(), Snmp::Inquirer::noteCommClosed(), FwdState::noteConnection(), TunnelStateData::noteConnection(), Adaptation::Icap::ServiceRep::noteConnectionUse(), Ssl::PeekingPeerConnector::noteNegotiationDone(), TunnelStateData::noteSecurityPeerConnectorAnswer(), Security::PeerConnector::noteWantRead(), Security::PeerConnector::noteWantWrite(), Ftp::Channel::opened(), OpenedHttpSocket(), Ipc::Coordinator::openListenSocket(), HttpStateData::persistentConnStatus(), ConnStateData::pinConnection(), PeerPoolMgr::pushNewConnection(), Adaptation::Icap::ServiceRep::putConnection(), Ftp::Client::readControlReply(), Http::Tunneler::readMore(), HttpStateData::readReply(), Ftp::Gateway::readStor(), Ftp::Server::readUploadData(), Security::PeerConnector::recordNegotiationDetails(), ConnStateData::requestTimeout(), Mgr::FunAction::respond(), Mgr::InfoAction::respond(), TunnelStateData::retryOrBail(), Mgr::StoreToCommWriter::scheduleCommWrite(), Ftp::Client::scheduleReadControlReply(), Ftp::Client::sendEprt(), Client::sendMoreRequestBody(), HttpStateData::sendRequest(), Snmp::Inquirer::sendResponse(), Http::Tunneler::sendSuccess(), Security::PeerConnector::sendSuccess(), FwdState::serverClosed(), Ftp::Relay::serverComplete(), Ipc::SharedListenJoined(), Ftp::Server::shovelUploadData(), snmpClosePorts(), snmpPortOpened(), ClientRequestContext::sslBumpAccessCheckDone(), Security::PeerConnector::sslCrtvdCheckForErrors(), Security::PeerConnector::sslCrtvdHandleReply(), Security::PeerConnector::sslFinalized(), Http::Tunneler::start(), Comm::TcpAcceptor::start(), Mgr::Inquirer::start(), Mgr::StoreToCommWriter::start(), Security::PeerConnector::start(), Snmp::Inquirer::start(), Ftp::Relay::startDataDownload(), Ftp::Relay::startDataUpload(), Ipc::StartListening(), statClientRequests(), Security::PeerConnector::status(), Http::Tunneler::swanSong(), Comm::TcpAcceptor::swanSong(), Mgr::Forwarder::swanSong(), Server::swanSong(), switchToTunnel(), FwdState::syncWithServerConn(), tunnelErrorComplete(), FwdState::tunnelEstablishmentDone(), TunnelStateData::tunnelEstablishmentDone(), ConnStateData::unpinConnection(), FwdState::unregister(), Adaptation::Icap::Xaction::useIcapConnection(), Adaptation::Icap::Xaction::useTransportConnection(), Http::Tunneler::watchForClosures(), TunnelStateData::writeClientDone(), Ftp::Client::writeCommand(), Ftp::Server::writeForwardedReplyAndCall(), and TunnelStateData::writeServerDone().

◆ MonitorsRead()

bool Comm::MonitorsRead ( int  fd)

Definition at line 29 of file Read.cc.

References assert, COMMIO_FD_READCB, and isOpen().

Referenced by HttpStateData::maybeReadVirginBody(), and fde::readPending().

◆ MortalReadTimeout()

time_t Comm::MortalReadTimeout ( const time_t  startTime,
const time_t  lifetimeLimit 
)

◆ operator<<() [1/2]

std::ostream & Comm::operator<< ( std::ostream &  os,
const Connection conn 
)

Definition at line 194 of file Connection.cc.

References COMM_UNSET, conn, and hier_code_str.

◆ operator<<() [2/2]

std::ostream & Comm::operator<< ( std::ostream &  os,
const ConnectionPointer conn 
)
inline

Definition at line 198 of file Connection.h.

References conn.

◆ QuickPollRequired()

void Comm::QuickPollRequired ( void  )

Definition at line 417 of file ModDevPoll.cc.

References max_poll_time.

Referenced by DiskdIOStrategy::init().

◆ Read()

void Comm::Read ( const Comm::ConnectionPointer conn,
AsyncCall::Pointer callback 
)

Start monitoring for read.

callback is scheduled when the read is possible, or on file descriptor close.

Definition at line 40 of file Read.cc.

References comm_read_base(), and conn.

Referenced by HttpStateData::maybeReadVirginBody(), Http::Tunneler::readMore(), Server::readSomeData(), Adaptation::Icap::Xaction::scheduleRead(), and ConnStateData::startPinnedConnectionMonitoring().

◆ ReadCancel()

◆ ReadNow()

Comm::Flag Comm::ReadNow ( CommIoCbParams params,
SBuf buf 
)

Perform a read(2) on a connection immediately.

If params.size is non-zero will limit size of the read to either the buffer free space or params.size, whichever is smallest.

The returned flag is also placed in params.flag.

Return values
Comm::OKdata has been read and placed in buf, amount in params.size
Comm::COMM_ERRORan error occurred, the code is placed in params.xerrno
Comm::INPROGRESSunable to read at this time, or a minor error occurred
Comm::ENDFILE0-byte read has occurred. Usually indicates the remote end has disconnected.

Definition at line 81 of file Read.cc.

References COMM_ERROR, CommCommonCbParams::conn, debugs, ENDFILE, Comm::Connection::fd, fd_bytes(), FD_READ, FD_READ_METHOD(), CommCommonCbParams::flag, ignoreErrno(), INPROGRESS, OK, SBuf::rawAppendFinish(), SBuf::rawAppendStart(), StatCounters::reads, CommIoCbParams::size, StatCounters::sock, SBuf::spaceSize(), statCounter, StatCounters::syscalls, CommCommonCbParams::xerrno, and xstrerr().

Referenced by Server::doClientRead(), Http::Tunneler::handleReadyRead(), Adaptation::Icap::Xaction::noteCommRead(), and HttpStateData::readReply().

◆ ResetSelect()

void Comm::ResetSelect ( int  fd)
inline

Definition at line 30 of file Loops.h.

References COMM_SELECT_READ, COMM_SELECT_WRITE, and SetSelect().

Referenced by fd_close(), and ConnStateData::parseTlsHandshake().

◆ SelectLoopInit()

void Comm::SelectLoopInit ( void  )

Initialise /dev/poll support.

Allocates memory, opens /dev/poll device handle.

Definition at line 176 of file ModDevPoll.cc.

References commDevPollRegisterWithCacheManager(), devpoll_fd, DEVPOLL_QUERYSIZE, devpoll_state, devpoll_update, DEVPOLL_UPDATESIZE, do_poll, dpoll_nfds, fatalf(), fd_open(), FD_UNKNOWN, xcalloc(), and xstrerr().

Referenced by comm_init().

◆ SetSelect()

void Comm::SetSelect ( int  fd,
unsigned int  type,
PF handler,
void *  client_data,
time_t  timeout 
)

Set polling state of file descriptor and callback functions.

Sets requested polling state for given file handle along with desired callback function in the event the request event triggers.

Note that setting a polling state with a NULL callback function will clear the polling for that event on that file descriptor.

Parameters
fdfile descriptor to change
typemay be COMM_SELECT_READ (input) or COMM_SELECT_WRITE (output)
handlercallback function, or NULL to stop type of polling
client_datapointer to be provided to call back function
timeoutif non-zero then timeout relative to now

This is a needed exported function which will be called to register and deregister interest in a pending IO state for a given FD.

Definition at line 223 of file ModDevPoll.cc.

References assert, COMM_SELECT_READ, COMM_SELECT_WRITE, comm_update_fd(), debugs, devpoll_state, F(), fd_table, handler(), NULL, squid_curtime, and _devpoll_state::state.

Referenced by _comm_close(), Comm::TcpAcceptor::acceptOne(), checkTimeouts(), Comm::ConnOpener::cleanFd(), clientNegotiateSSL(), comm_read_base(), comm_read_cancel(), diskHandleRead(), diskHandleWrite(), Comm::ConnOpener::doConnect(), ConnStateData::doPeekAndSpliceStep(), DoSelect(), htcpIncomingConnectionOpened(), htcpOpenPorts(), htcpRecv(), htcpSocketShutdown(), httpsEstablish(), icpConnectionShutdown(), icpHandleUdp(), icpIncomingConnectionOpened(), icpOpenPorts(), icpUdpSend(), idnsRead(), Dns::Init(), CommIO::Initialize(), logfileHandleWrite(), logfileQueueWrite(), Security::PeerConnector::noteWantRead(), Security::PeerConnector::noteWantWrite(), CommIO::NULLFDHandler(), IcmpSquid::Open(), ReadCancel(), IcmpSquid::Recv(), ResetSelect(), MessageBucket::scheduleWrite(), Comm::IoCallback::selectOrQueueWrite(), snmpHandleUdp(), snmpPortOpened(), Comm::TcpAcceptor::start(), ConnStateData::tunnelOnError(), wccp2ConnectionOpen(), wccp2HandleUdp(), wccpConnectionOpen(), and wccpHandleUdp().

◆ Write() [1/2]

◆ Write() [2/2]

void Comm::Write ( const Comm::ConnectionPointer conn,
MemBuf mb,
AsyncCall::Pointer callback 
)

Queue a write. callback is scheduled when the write completes, on error, or on file descriptor close.

Definition at line 27 of file Write.cc.

References MemBuf::buf, conn, MemBuf::freeFunc(), MemBuf::size, and Write().

◆ WriteCancel()

void Comm::WriteCancel ( const Comm::ConnectionPointer conn,
const char *  reason 
)

Variable Documentation

◆ HandleRead

void Comm::HandleRead
extern

Handle an FD which is ready for read(2).

If there is no provided buffer to fill call the callback.

Otherwise attempt a read into the provided buffer. If the read attempt succeeds or fails, call the callback. Else, wait for another IO notification.

Definition at line 128 of file Read.cc.

Referenced by comm_read_base().

◆ HandleWrite

void Comm::HandleWrite

Write to FD. This function is used by the lowest level of IO loop which only has access to FD numbers. We have to use the comm iocb_table to map FD numbers to waiting data and Comm::Connections. Once the write has been concluded we schedule the waiting call with success/fail results.

Definition at line 33 of file forward.h.

Referenced by checkTimeouts(), MessageBucket::scheduleWrite(), and Comm::IoCallback::selectOrQueueWrite().

◆ iocb_table

Comm::CbEntry * Comm::iocb_table
extern

Table of scheduled IO events which have yet to be processed ?? Callbacks which might be scheduled in future are stored in fd_table.

Definition at line 19 of file IoCallback.cc.

Referenced by CallbackTableDestruct(), and CallbackTableInit().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors