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::Connection > | ConnectionPointer |
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 ¶ms, 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 |
CbEntry * | iocb_table |
PF | HandleRead |
callback handler to process an FD which is available for reading More... | |
Typedef Documentation
◆ ConnectionPointer
Enumeration Type Documentation
◆ Flag
enum Comm::Flag |
◆ iocb_type
enum Comm::iocb_type |
Enumerator | |
---|---|
IOCB_NONE | |
IOCB_READ | |
IOCB_WRITE |
Definition at line 22 of file IoCallback.h.
Function Documentation
◆ ApplyTcpKeepAlive()
void Comm::ApplyTcpKeepAlive | ( | int | fd, |
const TcpKeepAlive & | cfg | ||
) |
Definition at line 51 of file Tcp.cc.
References Comm::TcpKeepAlive::enabled, Comm::TcpKeepAlive::idle, Comm::TcpKeepAlive::interval, SetBooleanSocketOption(), SetSocketOption(), and Comm::TcpKeepAlive::timeout.
Referenced by Comm::TcpAcceptor::acceptInto().
◆ CallbackTableDestruct()
void Comm::CallbackTableDestruct | ( | ) |
Definition at line 34 of file IoCallback.cc.
References Comm::IoCallback::conn, iocb_table, Comm::CbEntry::readcb, safe_free, Squid_MaxFD, and Comm::CbEntry::writecb.
Referenced by comm_exit().
◆ CallbackTableInit()
void Comm::CallbackTableInit | ( | ) |
Definition at line 22 of file IoCallback.cc.
References Comm::CbEntry::fd, IOCB_READ, iocb_table, IOCB_WRITE, Comm::CbEntry::readcb, Squid_MaxFD, Comm::IoCallback::type, Comm::CbEntry::writecb, and xcalloc().
Referenced by comm_init().
◆ 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
-
msec milliseconds 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 | ||
) |
Definition at line 248 of file Read.cc.
References Config, min(), SquidConfig::read, squid_curtime, Ident::Timeout, and SquidConfig::Timeout.
Referenced by Security::PeerConnector::noteWantRead(), and Http::Tunneler::readMore().
◆ 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]
|
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()
void Comm::ReadCancel | ( | int | fd, |
AsyncCall::Pointer & | callback | ||
) |
Definition at line 219 of file Read.cc.
References Comm::IoCallback::active(), assert, Comm::IoCallback::callback, AsyncCall::cancel(), Comm::IoCallback::cancel(), COMM_SELECT_READ, COMMIO_FD_READCB, debugs, isOpen(), and SetSelect().
Referenced by Adaptation::Icap::Xaction::cancelRead(), Ftp::Server::closeDataConnection(), commStopHalfClosedMonitor(), Http::Tunneler::disconnect(), ConnStateData::stopPinnedConnectionMonitoring(), and Server::stopReading().
◆ 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::OK data has been read and placed in buf, amount in params.size Comm::COMM_ERROR an error occurred, the code is placed in params.xerrno Comm::INPROGRESS unable to read at this time, or a minor error occurred Comm::ENDFILE 0-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()
|
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
-
fd file descriptor to change type may be COMM_SELECT_READ (input) or COMM_SELECT_WRITE (output) handler callback function, or NULL to stop type of polling client_data pointer to be provided to call back function timeout if 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]
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 33 of file Write.cc.
References Comm::IoCallback::active(), assert, COMMIO_FD_WRITECB, Comm::IoCallback::conn, conn, debugs, fd_table, IOCB_WRITE, Comm::IoCallback::selectOrQueueWrite(), Comm::IoCallback::setCallback(), size, and squid_curtime.
Referenced by Ftp::Server::acceptDataConnection(), errorSend(), HttpStateData::finishingBrokenPost(), HttpStateData::finishingChunkedRequest(), Ftp::Server::handleDataReply(), helperDispatch(), helperDispatchWriteDone(), helperStatefulDispatch(), idnsDoSendQueryVC(), Mgr::StoreToCommWriter::scheduleCommWrite(), Adaptation::Icap::Xaction::scheduleWrite(), Client::sendMoreRequestBody(), HttpStateData::sendRequest(), ClientHttpRequest::sslBumpStart(), Mgr::Inquirer::start(), whoisStart(), Ipc::UdsSender::write(), TunnelStateData::Connection::write(), Write(), Server::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 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
|
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
|
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().