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  UdpOpenDialer
 dials a UDP port-opened call More...
 

Typedefs

typedef RefCount< Comm::ConnectionConnectionPointer
 
typedef std::vector< Comm::ConnectionPointerConnectionList
 

Enumerations

enum  Flag {
  OK = 0,
  COMM_ERROR = -1,
  NOMESSAGE = -3,
  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

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

◆ ConnectionList

◆ ConnectionPointer

Definition at line 25 of file forward.h.

Enumeration Type Documentation

◆ Flag

enum Comm::Flag
Enumerator
OK 
COMM_ERROR 
NOMESSAGE 
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

◆ 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 313 of file ModDevPoll.cc.

References COMM_ERROR, comm_flush_updates(), COMM_SELECT_READ, COMM_SELECT_WRITE, StatHist::count(), DEBUG_DEVPOLL, debugs, devpoll_fd, do_poll, dpoll_nfds, F(), fd_table, fde::flags, getCurrentTime(), HERE(), i, ignoreErrno(), int, max_poll_time, NULL, OK, PROF_start, PROF_stop, fde::read_data, fde::read_handler, fde::_fde_flags::read_pending, StatCounters::select_fds, StatCounters::select_fds_hist, StatCounters::select_loops, SetSelect(), statCounter, _devpoll_state::state, TIMEOUT, fde::write_data, and fde::write_handler.

Referenced by CommSelectEngine::checkEvents(), comm_poll_tcp_incoming(), commIncomingStats(), kq_update_events(), and ResetSelect().

◆ IsConnOpen()

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

Definition at line 26 of file Connection.cc.

References NULL.

Referenced by Mgr::StoreToCommWriter::Abort(), Ftp::Relay::abort(), FwdState::abort(), Ftp::Relay::abortOnData(), Comm::TcpAcceptor::acceptNext(), Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), clientReplyContext::buildReplyHeader(), Ftp::Server::callException(), ClientHttpRequest::callException(), Ftp::Server::checkDataConnPost(), Ftp::Server::checkDataConnPre(), IdentLookup::checkForAsync(), Snmp::Inquirer::cleanup(), Mgr::Inquirer::cleanup(), clientCheckPinning(), clientLifetimeTimeout(), clientListenerConnectionOpened(), Ftp::Server::clientPinnedConnectionClosed(), clientProcessRequestFinished(), ClientRequestContext::clientRedirectDone(), clientSocketRecipient(), Server::clientWriteDone(), Ftp::Channel::close(), Mgr::StoreToCommWriter::close(), Ftp::Server::closeDataConnection(), TunnelStateData::Connection::closeIfOpen(), HttpStateData::closeServer(), Ftp::Client::closeServer(), 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(), CreateSession(), FwdState::dispatch(), ClientHttpRequest::doCallouts(), Server::doClientRead(), Server::doneAll(), Comm::TcpAcceptor::doneAll(), HttpStateData::doneWithServer(), Ftp::Client::doneWithServer(), ConnStateData::endingShutdown(), errorSend(), HttpStateData::finishingBrokenPost(), Ftp::Channel::forget(), Mgr::Forwarder::Forwarder(), Ftp::Gateway::ftpAcceptDataConnection(), ftpOpenListenSocket(), ftpReadList(), ftpReadPORT(), ftpReadRetr(), ftpSendPORT(), Adaptation::Icap::ServiceRep::getConnection(), gopherTimeout(), Ftp::Server::handleDataReply(), Ftp::Client::handleEpsvReply(), Mgr::Forwarder::handleException(), HttpStateData::handleMoreRequestBodyAvailable(), Ftp::Client::handlePasvReply(), Adaptation::Icap::Xaction::handleSecuredPeer(), FwdState::handleUnregisteredServerEnd(), Ftp::Gateway::haveControlChannel(), helperHandleRead(), helperStatefulHandleRead(), htcpClear(), htcpIncomingConnectionOpened(), htcpOpenPorts(), htcpQuery(), htcpSocketShutdown(), ConnStateData::httpsPeeked(), icpConnectionShutdown(), icpIncomingConnectionOpened(), icpOpenPorts(), idnsReadVC(), idnsReadVCHeader(), idnsSentQueryVC(), idnsShutdownAndFreeState(), IdleConnList::isAvailable(), ConnStateData::isOpen(), TunnelStateData::keepGoingAfterRead(), ConnStateData::kick(), DeferredReadManager::kickARead(), Ftp::Gateway::listenForDataChannel(), Ftp::Server::listenForDataConnection(), ACLIdent::match(), HttpStateData::maybeReadVirginBody(), Ftp::Client::maybeReadVirginBody(), Ftp::Relay::mayReadVirginReplyBody(), Security::PeerConnector::negotiate(), neighbors_init(), neighborsRegisterWithCacheManager(), neighborsUdpPing(), TunnelStateData::noConnections(), ClientHttpRequest::noteBodyProducerAborted(), Snmp::Inquirer::noteCommClosed(), Mgr::Inquirer::noteCommClosed(), Mgr::StoreToCommWriter::noteCommClosed(), Adaptation::Icap::ServiceRep::noteConnectionUse(), FwdState::noteDestination(), TunnelStateData::noteDestination(), FwdState::noteDestinationsEnd(), TunnelStateData::noteDestinationsEnd(), Adaptation::Icap::Xaction::openConnection(), Ftp::Channel::opened(), OpenedHttpSocket(), Ipc::Coordinator::openListenSocket(), HttpStateData::persistentConnStatus(), ConnStateData::pinConnection(), DeferredReadManager::popHead(), Security::PeerConnector::prepareSocket(), PeerPoolMgr::pushNewConnection(), Adaptation::Icap::ServiceRep::putConnection(), Ftp::Client::readControlReply(), Http::Tunneler::readMore(), HttpStateData::readReply(), Ftp::Gateway::readStor(), Ftp::Server::readUploadData(), ConnStateData::requestTimeout(), Mgr::FunAction::respond(), Mgr::InfoAction::respond(), Mgr::StoreToCommWriter::scheduleCommWrite(), Ftp::Client::scheduleReadControlReply(), send_announce(), Ftp::Client::sendEprt(), Client::sendMoreRequestBody(), HttpStateData::sendRequest(), Ftp::Relay::serverComplete(), Ipc::SharedListenJoined(), Ftp::Server::shovelUploadData(), snmpClosePorts(), snmpPortOpened(), ClientRequestContext::sslBumpAccessCheckDone(), Security::PeerConnector::sslCrtvdHandleReply(), Snmp::Inquirer::start(), Mgr::Inquirer::start(), Mgr::StoreToCommWriter::start(), Comm::TcpAcceptor::start(), start_announce(), Ftp::Relay::startDataDownload(), Ftp::Relay::startDataUpload(), Ipc::StartListening(), statClientRequests(), Server::swanSong(), Mgr::Forwarder::swanSong(), Comm::TcpAcceptor::swanSong(), Ident::IdentStateData::swanSong(), FwdState::syncWithServerConn(), tunnelErrorComplete(), ConnStateData::unpinConnection(), FwdState::unregister(), Http::Tunneler::watchForClosures(), TunnelStateData::writeClientDone(), Ftp::Client::writeCommand(), Ftp::Server::writeForwardedReplyAndCall(), TunnelStateData::writeServerDone(), FwdState::~FwdState(), Ftp::Gateway::~Gateway(), helper_server::~helper_server(), helper_stateful_server::~helper_stateful_server(), AnyP::PortCfg::~PortCfg(), and Ipc::UdsOp::~UdsOp().

◆ MonitorsRead()

bool Comm::MonitorsRead ( int  fd)

Definition at line 29 of file Read.cc.

References assert, COMMIO_FD_READCB, isOpen(), and NULL.

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

◆ MortalReadTimeout()

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

◆ QuickPollRequired()

void Comm::QuickPollRequired ( void  )

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

Referenced by commHalfClosedCheck(), 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(), CommIoCbParams::size, StatCounters::sock, SBuf::spaceSize(), statCounter, StatCounters::syscalls, sz, 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

◆ SelectLoopInit()

void Comm::SelectLoopInit ( void  )

Initialise /dev/poll support.

Allocates memory, opens /dev/poll device handle.

Definition at line 178 of file ModDevPoll.cc.

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

Referenced by comm_init(), comm_select_dns_incoming(), commPollRegisterWithCacheManager(), and kq_update_events().

◆ 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 225 of file ModDevPoll.cc.

References assert, COMM_SELECT_READ, COMM_SELECT_WRITE, comm_update_fd(), debugs, F(), fd_table, fde::flags, handler(), HERE(), NULL, fde::_fde_flags::open, fde::read_data, fde::read_handler, fde::_fde_flags::read_pending, squid_curtime, _devpoll_state::state, fde::timeout, fde::write_data, and fde::write_handler.

Referenced by _comm_close(), Comm::TcpAcceptor::acceptOne(), checkTimeouts(), Comm::ConnOpener::cleanFd(), comm_read_base(), comm_read_cancel(), commCallCloseHandlers(), commHandleWriteHelper(), commIncomingStats(), diskHandleRead(), diskHandleWrite(), Comm::ConnOpener::doConnect(), ConnStateData::doPeekAndSpliceStep(), DoSelect(), epolltype_atoi(), htcpIncomingConnectionOpened(), htcpOpenPorts(), htcpRecv(), htcpSocketShutdown(), httpsEstablish(), icpConnectionShutdown(), icpHandleUdp(), icpIncomingConnectionOpened(), icpOpenPorts(), icpUdpSend(), idnsRead(), Dns::Init(), CommIO::Initialize(), kq_update_events(), 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(), tlsAttemptHandshake(), ConnStateData::tunnelOnError(), wccp2ConnectionOpen(), wccp2HandleUdp(), wccpConnectionOpen(), and wccpHandleUdp().

◆ Write() [1/2]

void Comm::Write ( const Comm::ConnectionPointer conn,
const char *  buf,
int  size,
AsyncCall::Pointer callback,
FREE free_func 
)

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

free_func is used to free the passed buffer when the write has completed.

Definition at line 35 of file Write.cc.

References BandwidthBucket::applyQuota(), assert, Comm::IoCallback::buf, COMM_ERROR, COMMIO_FD_WRITECB, conn, Comm::IoCallback::conn, data, DBG_IMPORTANT, debugs, Comm::Connection::fd, fd_bytes(), fd_table, FD_WRITE, FD_WRITE_METHOD(), Comm::IoCallback::finish(), HandleWrite, HERE(), ignoreErrno(), IOCB_WRITE, len, NULL, Comm::IoCallback::offset, OK, PROF_start, PROF_stop, BandwidthBucket::reduceBucket(), BandwidthBucket::SelectBucket(), Comm::IoCallback::selectOrQueueWrite(), BandwidthBucket::selectWaiting, Comm::IoCallback::size, StatCounters::sock, squid_curtime, statCounter, StatCounters::syscalls, and xstrerr().

Referenced by Ftp::Server::acceptDataConnection(), errorSend(), HttpStateData::finishingBrokenPost(), HttpStateData::finishingChunkedRequest(), gopherSendRequest(), Ftp::Server::handleDataReply(), helperDispatch(), helperDispatchWriteDone(), helperStatefulDispatch(), idnsDoSendQueryVC(), Ident::IdentStateData::notify(), Mgr::StoreToCommWriter::scheduleCommWrite(), Adaptation::Icap::Xaction::scheduleWrite(), Client::sendMoreRequestBody(), HttpStateData::sendRequest(), ClientHttpRequest::sslBumpStart(), Mgr::Inquirer::start(), whoisStart(), Write(), Server::write(), Ipc::UdsSender::write(), TunnelStateData::Connection::write(), Ftp::Client::writeCommand(), Http::One::Server::writeControlMsgAndCall(), Ftp::Server::writeEarlyReply(), Ftp::Server::writeForwardedReplyAndCall(), Log::TcpLogger::writeIfPossible(), Ftp::Server::writeReply(), and Http::Tunneler::writeRequest().

◆ 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 29 of file Write.cc.

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

◆ WriteCancel()

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

Variable Documentation

◆ HandleRead

void Comm::HandleRead

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 126 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 34 of file forward.h.

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

◆ iocb_table

Comm::CbEntry * Comm::iocb_table

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