}
void
-commSetCloseOnExec(int fd) {
+commSetCloseOnExec(int fd)
+{
#ifdef FD_CLOEXEC
int flags;
int dummy = 0;
#ifdef TCP_NODELAY
static void
-commSetTcpNoDelay(int fd) {
+commSetTcpNoDelay(int fd)
+{
int on = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0)
#endif
void
-commSetTcpKeepalive(int fd, int idle, int interval, int timeout) {
+commSetTcpKeepalive(int fd, int idle, int interval, int timeout)
+{
int on = 1;
#ifdef TCP_KEEPCNT
if (timeout && interval) {
}
void
-comm_init(void) {
+comm_init(void)
+{
fd_table =(fde *) xcalloc(Squid_MaxFD, sizeof(fde));
fdd_table = (fd_debug_t *)xcalloc(Squid_MaxFD, sizeof(fd_debug_t));
}
void
-comm_exit(void) {
+comm_exit(void)
+{
delete TheHalfClosed;
TheHalfClosed = NULL;
/* Write to FD. */
static void
-commHandleWrite(int fd, void *data) {
+commHandleWrite(int fd, void *data)
+{
comm_io_callback_t *state = (comm_io_callback_t *)data;
int len = 0;
int nleft;
* free_func is used to free the passed buffer when the write has completed.
*/
void
-comm_write(int fd, const char *buf, int size, IOCB * handler, void *handler_data, FREE * free_func) {
+comm_write(int fd, const char *buf, int size, IOCB * handler, void *handler_data, FREE * free_func)
+{
AsyncCall::Pointer call = commCbCall(5,5, "SomeCommWriteHander",
CommIoCbPtrFun(handler, handler_data));
}
void
-comm_write(int fd, const char *buf, int size, AsyncCall::Pointer &callback, FREE * free_func) {
+comm_write(int fd, const char *buf, int size, AsyncCall::Pointer &callback, FREE * free_func)
+{
debugs(5, 5, "comm_write: FD " << fd << ": sz " << size << ": asynCall " << callback);
/* Make sure we are open, not closing, and not writing */
/* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */
void
-comm_write_mbuf(int fd, MemBuf *mb, IOCB * handler, void *handler_data) {
+comm_write_mbuf(int fd, MemBuf *mb, IOCB * handler, void *handler_data)
+{
comm_write(fd, mb->buf, mb->size, handler, handler_data, mb->freeFunc());
}
void
-comm_write_mbuf(int fd, MemBuf *mb, AsyncCall::Pointer &callback) {
+comm_write_mbuf(int fd, MemBuf *mb, AsyncCall::Pointer &callback)
+{
comm_write(fd, mb->buf, mb->size, callback, mb->freeFunc());
}
* like to use it.
*/
int
-ignoreErrno(int ierrno) {
+ignoreErrno(int ierrno)
+{
switch (ierrno) {
case EINPROGRESS:
}
void
-commCloseAllSockets(void) {
+commCloseAllSockets(void)
+{
int fd;
fde *F = NULL;
}
static bool
-AlreadyTimedOut(fde *F) {
+AlreadyTimedOut(fde *F)
+{
if (!F->flags.open)
return true;
}
void
-checkTimeouts(void) {
+checkTimeouts(void)
+{
int fd;
fde *F = NULL;
AsyncCall::Pointer callback;
* accept()ed.
*/
int
-comm_listen(int sock) {
+comm_listen(int sock)
+{
int x;
if ((x = listen(sock, Squid_MaxFD >> 2)) < 0) {
}
void
-comm_accept(int fd, IOACB *handler, void *handler_data) {
+comm_accept(int fd, IOACB *handler, void *handler_data)
+{
debugs(5, 5, "comm_accept: FD " << fd << " handler: " << (void*)handler);
assert(isOpen(fd));
}
void
-comm_accept(int fd, AsyncCall::Pointer &call) {
+comm_accept(int fd, AsyncCall::Pointer &call)
+{
debugs(5, 5, "comm_accept: FD " << fd << " AsyncCall: " << call);
assert(isOpen(fd));
// Called when somebody wants to be notified when our socket accepts new
// connection. We do not probe the FD until there is such interest.
void
-AcceptFD::subscribe(AsyncCall::Pointer &call) {
+AcceptFD::subscribe(AsyncCall::Pointer &call)
+{
/* make sure we're not pending! */
assert(!theCallback);
theCallback = call;
}
bool
-AcceptFD::acceptOne() {
+AcceptFD::acceptOne()
+{
// If there is no callback and we accept, we will leak the accepted FD.
// When we are running out of FDs, there is often no callback.
if (!theCallback) {
}
void
-AcceptFD::acceptNext() {
+AcceptFD::acceptNext()
+{
mayAcceptMore = acceptOne();
}
void
-AcceptFD::notify(int newfd, comm_err_t errcode, int xerrno, const ConnectionDetail &connDetails) {
+AcceptFD::notify(int newfd, comm_err_t errcode, int xerrno, const ConnectionDetail &connDetails)
+{
if (theCallback != NULL) {
typedef CommAcceptCbParams Params;
Params ¶ms = GetCommParams<Params>(theCallback);
* to dupe itself and fob off an accept()ed connection
*/
static void
-comm_accept_try(int fd, void *) {
+comm_accept_try(int fd, void *)
+{
assert(isOpen(fd));
fdc_table[fd].acceptNext();
}
-void CommIO::Initialise() {
+void CommIO::Initialise()
+{
/* Initialize done pipe signal */
int DonePipe[2];
if (pipe(DonePipe)) {}
Initialised = true;
}
-void CommIO::NotifyIOClose() {
+void CommIO::NotifyIOClose()
+{
/* Close done pipe signal */
FlushPipe();
close(DoneFD);
int CommIO::DoneReadFD = -1;
void
-CommIO::FlushPipe() {
+CommIO::FlushPipe()
+{
char buf[256];
FD_READ_METHOD(DoneReadFD, buf, sizeof(buf));
}
void
-CommIO::NULLFDHandler(int fd, void *data) {
+CommIO::NULLFDHandler(int fd, void *data)
+{
FlushPipe();
commSetSelect(fd, COMM_SELECT_READ, NULLFDHandler, NULL, 0);
}
void
-CommIO::ResetNotifications() {
+CommIO::ResetNotifications()
+{
if (DoneSignalled) {
FlushPipe();
DoneSignalled = false;
AcceptLimiter AcceptLimiter::Instance_;
-AcceptLimiter &AcceptLimiter::Instance() {
+AcceptLimiter &AcceptLimiter::Instance()
+{
return Instance_;
}
bool
-AcceptLimiter::deferring() const {
+AcceptLimiter::deferring() const
+{
return deferred.size() > 0;
}
void
-AcceptLimiter::defer (int fd, Acceptor::AcceptorFunction *aFunc, void *data) {
+AcceptLimiter::defer (int fd, Acceptor::AcceptorFunction *aFunc, void *data)
+{
debugs(5, 5, "AcceptLimiter::defer: FD " << fd << " handler: " << (void*)aFunc);
Acceptor temp;
temp.theFunction = aFunc;
}
void
-AcceptLimiter::kick() {
+AcceptLimiter::kick()
+{
if (!deferring())
return;
// by scheduling a read callback to a monitoring handler that
// will close the connection on read errors.
void
-commStartHalfClosedMonitor(int fd) {
+commStartHalfClosedMonitor(int fd)
+{
debugs(5, 5, HERE << "adding FD " << fd << " to " << *TheHalfClosed);
assert(isOpen(fd));
assert(!commHasHalfClosedMonitor(fd));
static
void
-commPlanHalfClosedCheck() {
+commPlanHalfClosedCheck()
+{
if (!WillCheckHalfClosed && !TheHalfClosed->empty()) {
eventAdd("commHalfClosedCheck", &commHalfClosedCheck, NULL, 1.0, 1);
WillCheckHalfClosed = true;
/// calls comm_read for those that do; re-schedules the check if needed
static
void
-commHalfClosedCheck(void *) {
+commHalfClosedCheck(void *)
+{
debugs(5, 5, HERE << "checking " << *TheHalfClosed);
typedef DescriptorSet::const_iterator DSCI;
/// checks whether we are waiting for possibly half-closed connection to close
// We are monitoring if the read handler for the fd is the monitoring handler.
bool
-commHasHalfClosedMonitor(int fd) {
+commHasHalfClosedMonitor(int fd)
+{
return TheHalfClosed->has(fd);
}
/// stop waiting for possibly half-closed connection to close
static void
-commStopHalfClosedMonitor(int const fd) {
+commStopHalfClosedMonitor(int const fd)
+{
debugs(5, 5, HERE << "removing FD " << fd << " from " << *TheHalfClosed);
// cancel the read if one was scheduled
/// I/O handler for the possibly half-closed connection monitoring code
static void
-commHalfClosedReader(int fd, char *, size_t size, comm_err_t flag, int, void *) {
+commHalfClosedReader(int fd, char *, size_t size, comm_err_t flag, int, void *)
+{
// there cannot be more data coming in on half-closed connections
assert(size == 0);
assert(commHasHalfClosedMonitor(fd)); // or we would have canceled the read
DeferredRead::DeferredRead (DeferrableRead *aReader, void *data, CommRead const &aRead) : theReader(aReader), theContext (data), theRead(aRead), cancelled(false) {}
-DeferredReadManager::~DeferredReadManager() {
+DeferredReadManager::~DeferredReadManager()
+{
flushReads();
assert (deferredReads.empty());
}
/// \endcond
void
-DeferredReadManager::delayRead(DeferredRead const &aRead) {
+DeferredReadManager::delayRead(DeferredRead const &aRead)
+{
debugs(5, 3, "Adding deferred read on FD " << aRead.theRead.fd);
CbDataList<DeferredRead> *temp = deferredReads.push_back(aRead);
}
void
-DeferredReadManager::CloseHandler(int fd, void *thecbdata) {
+DeferredReadManager::CloseHandler(int fd, void *thecbdata)
+{
if (!cbdataReferenceValid (thecbdata))
return;
}
DeferredRead
-DeferredReadManager::popHead(CbDataListContainer<DeferredRead> &deferredReads) {
+DeferredReadManager::popHead(CbDataListContainer<DeferredRead> &deferredReads)
+{
assert (!deferredReads.empty());
DeferredRead &read = deferredReads.head->element;
}
void
-DeferredReadManager::kickReads(int const count) {
+DeferredReadManager::kickReads(int const count)
+{
/* if we had CbDataList::size() we could consolidate this and flushReads */
if (count < 1) {
}
void
-DeferredReadManager::flushReads() {
+DeferredReadManager::flushReads()
+{
CbDataListContainer<DeferredRead> reads;
reads = deferredReads;
deferredReads = CbDataListContainer<DeferredRead>();
}
void
-DeferredReadManager::kickARead(DeferredRead const &aRead) {
+DeferredReadManager::kickARead(DeferredRead const &aRead)
+{
if (aRead.cancelled)
return;
}
void
-DeferredRead::markCancelled() {
+DeferredRead::markCancelled()
+{
cancelled = true;
}
-ConnectionDetail::ConnectionDetail() : me(), peer() {
+ConnectionDetail::ConnectionDetail() : me(), peer()
+{
}
int
-CommSelectEngine::checkEvents(int timeout) {
+CommSelectEngine::checkEvents(int timeout)
+{
static time_t last_timeout = 0;
/* No, this shouldn't be here. But it shouldn't be in each comm handler. -adrian */