/*
- * $Id: comm.cc,v 1.372 2003/03/10 04:56:37 robertc Exp $
+ * $Id: comm.cc,v 1.373 2003/04/20 05:28:58 robertc Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
if (port > (u_short) 0)
{
- commSetNoLinger(new_socket);
+#ifdef _SQUID_MSWIN_
+
+ if (sock_type != SOCK_DGRAM)
+#endif
+
+ commSetNoLinger(new_socket);
if (opt_reuseaddr)
commSetReuseAddr(new_socket);
int
commSetNonBlocking(int fd)
{
+#ifndef _SQUID_MSWIN_
int flags;
int dummy = 0;
-#ifdef _SQUID_CYGWIN_
+#endif
+#if defined (_SQUID_CYGWIN_) || defined (_SQUID_MSWIN_)
int nonblocking = TRUE;
if (fd_table[fd].type != FD_PIPE) {
if (ioctl(fd, FIONBIO, &nonblocking) < 0) {
- debug(50, 0) ("commSetNonBlocking: FD %d: %s %D\n", fd, xstrerror(), fd_table[fd].type);
+ debug(50, 0) ("commSetNonBlocking: FD %d: %s %d\n", fd, xstrerror(), fd_table[fd].type);
return COMM_ERROR;
}
} else {
#endif
+#ifndef _SQUID_MSWIN_
if ((flags = fcntl(fd, F_GETFL, dummy)) < 0) {
debug(50, 0) ("FD %d: fcntl F_GETFL: %s\n", fd, xstrerror());
return COMM_ERROR;
}
-#ifdef _SQUID_CYGWIN_
+#endif
+#if defined (_SQUID_CYGWIN_) || defined (_SQUID_MSWIN_)
}
int
commUnsetNonBlocking(int fd)
{
+#ifdef _SQUID_MSWIN_
+ int nonblocking = FALSE;
+
+ if (ioctlsocket(fd, FIONBIO, (unsigned long *) &nonblocking) < 0) {
+#else
int flags;
int dummy = 0;
}
if (fcntl(fd, F_SETFL, flags & (~SQUID_NONBLOCK)) < 0) {
+#endif
debug(50, 0) ("commUnsetNonBlocking: FD %d: %s\n", fd, xstrerror());
return COMM_ERROR;
}
}
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)
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));
fdc_table = new fdc_t[Squid_MaxFD];
/* Write to FD. */
static void
-commHandleWrite(int fd, void *data)
-{
+commHandleWrite(int fd, void *data) {
CommWriteStateData *state = (CommWriteStateData *)data;
int len = 0;
int nleft;
* free_func is used to free the passed buffer when the write has completed.
*/
void
-comm_old_write(int fd, const char *buf, int size, CWCB * handler, void *handler_data, FREE * free_func)
-{
+comm_old_write(int fd, const char *buf, int size, CWCB * handler, void *handler_data, FREE * free_func) {
CommWriteStateData *state = fd_table[fd].rwstate;
assert(!fd_table[fd].flags.closing);
/* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */
void
-comm_old_write_mbuf(int fd, MemBuf mb, CWCB * handler, void *handler_data)
-{
+comm_old_write_mbuf(int fd, MemBuf mb, CWCB * handler, void *handler_data) {
comm_old_write(fd, mb.buf, mb.size, handler, handler_data, memBufFreeFunc(&mb));
}
* 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;
PF *callback;
* accept()ed.
*/
int
-comm_listen(int sock)
-{
+comm_listen(int sock) {
int x;
if ((x = listen(sock, Squid_MaxFD >> 2)) < 0) {
}
void
-fdc_t::beginAccepting()
-{
+fdc_t::beginAccepting() {
accept.accept.beginAccepting();
}
int
-fdc_t::acceptCount() const
-{
+fdc_t::acceptCount() const {
return accept.accept.acceptCount();
}
void
-fdc_t::acceptOne(int fd)
-{
+fdc_t::acceptOne(int fd) {
/* If we're out of fds, register an event and return now */
if (fdNFree() < RESERVED_FD) {
}
bool
-AcceptFD::finished() const
-{
+AcceptFD::finished() const {
return finished_;
}
void
-AcceptFD::finished(bool newValue)
-{
+AcceptFD::finished(bool newValue) {
finished_ = newValue;
}
bool
-AcceptFD::finishedAccepting() const
-{
+AcceptFD::finishedAccepting() const {
return acceptCount() >= MAX_ACCEPT_PER_LOOP || finished();
}
* to dupe itself and fob off an accept()ed connection
*/
static void
-comm_accept_try(int fd, void *data)
-{
+comm_accept_try(int fd, void *data) {
assert(fdc_table[fd].active == 1);
fdc_table[fd].beginAccepting();
* this isn't very optimal and should be revisited at a later date.
*/
void
-comm_accept(int fd, IOACB *handler, void *handler_data)
-{
+comm_accept(int fd, IOACB *handler, void *handler_data) {
fdc_t *Fc;
assert(fd_table[fd].flags.open == 1);
#endif
}
-void CommIO::Initialise()
-{
+void CommIO::Initialise() {
/* Initialize done pipe signal */
int DonePipe[2];
pipe(DonePipe);
int CommIO::DoneReadFD = -1;
void
-CommIO::FlushPipe()
-{
+CommIO::FlushPipe() {
char buf[256];
read(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_;
}
void
-AcceptLimiter::defer (int fd, Acceptor::AcceptorFunction *aFunc, void *data)
-{
+AcceptLimiter::defer (int fd, Acceptor::AcceptorFunction *aFunc, void *data) {
Acceptor temp;
temp.theFunction = aFunc;
temp.acceptFD = fd;
}
void
-AcceptLimiter::kick()
-{
+AcceptLimiter::kick() {
if (!deferred.size())
return;
}
void
-commMarkHalfClosed(int fd)
-{
+commMarkHalfClosed(int fd) {
assert (fdc_table[fd].active && !fdc_table[fd].half_closed);
AbortChecker::Instance().monitor(fd);
fdc_table[fd].half_closed = true;
AbortChecker AbortChecker::Instance_;
void
-AbortChecker::AbortCheckReader(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data)
-{
+AbortChecker::AbortCheckReader(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data) {
assert (size == 0);
/* sketch:
* if the read is ok and 0, the conn is still open.
}
void
-AbortChecker::monitor(int fd)
-{
+AbortChecker::monitor(int fd) {
assert (!contains(fd));
add
}
void
-AbortChecker::stopMonitoring (int fd)
-{
+AbortChecker::stopMonitoring (int fd) {
assert (contains (fd));
remove
#include "splay.h"
void
-AbortChecker::doIOLoop()
-{
+AbortChecker::doIOLoop() {
if (checking) {
/*
fds->walk(RemoveCheck, this);
}
void
-AbortChecker::AddCheck (int const &fd, void *data)
-{
+AbortChecker::AddCheck (int const &fd, void *data) {
AbortChecker *me = (AbortChecker *)data;
me->addCheck(fd);
}
void
-AbortChecker::RemoveCheck (int const &fd, void *data)
-{
+AbortChecker::RemoveCheck (int const &fd, void *data) {
AbortChecker *me = (AbortChecker *)data;
me->removeCheck(fd);
}
int
-AbortChecker::IntCompare (int const &lhs, int const &rhs)
-{
+AbortChecker::IntCompare (int const &lhs, int const &rhs) {
return lhs - rhs;
}
bool
-AbortChecker::contains (int const fd) const
-{
+AbortChecker::contains (int const fd) const {
fds = fds->splay(fd, IntCompare);
if (splayLastResult != 0)
void
AbortChecker::remove
- (int const fd)
-{
+ (int const fd) {
fds = fds->remove
(fd, IntCompare);
void
AbortChecker::add
- (int const fd)
-{
+ (int const fd) {
fds = fds->insert (fd, IntCompare);
}
void
-AbortChecker::addCheck (int const fd)
-{
+AbortChecker::addCheck (int const fd) {
/* assert comm_is_open (fd); */
comm_read(fd, NULL, 0, AbortCheckReader, NULL);
}
void
-AbortChecker::removeCheck (int const fd)
-{
+AbortChecker::removeCheck (int const fd) {
/*
comm_read_cancel(fd, AbortCheckReader, NULL);
*/
}
-CommRead::CommRead() : fd(-1), buf(NULL), len(0)
-{}
+CommRead::CommRead() : fd(-1), buf(NULL), len(0) {}
CommRead::CommRead(int fd_, char *buf_, int len_, IOCB *handler_, void *data_)
- : fd(fd_), buf(buf_), len(len_), callback(handler_, data_)
-{}
+ : fd(fd_), buf(buf_), len(len_), callback(handler_, data_) {}
-DeferredRead::DeferredRead () : theReader(NULL), theContext(NULL), theRead(), cancelled(false)
-{}
+DeferredRead::DeferredRead () : theReader(NULL), theContext(NULL), theRead(), cancelled(false) {}
-DeferredRead::DeferredRead (DeferrableRead *aReader, void *data, CommRead const &aRead) : theReader(aReader), theContext (data), theRead(aRead), cancelled(false)
-{}
+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());
}
void
-DeferredReadManager::delayRead(DeferredRead const &aRead)
-{
+DeferredReadManager::delayRead(DeferredRead const &aRead) {
debug (5, 3)("Adding deferred read on fd %d\n", aRead.theRead.fd);
List<DeferredRead> *temp = deferredReads.push_back(aRead);
comm_add_close_handler (aRead.theRead.fd, CloseHandler, temp);
}
void
-DeferredReadManager::CloseHandler(int fd, void *thecbdata)
-{
+DeferredReadManager::CloseHandler(int fd, void *thecbdata) {
if (!cbdataReferenceValid (thecbdata))
return;
}
DeferredRead
-DeferredReadManager::popHead(ListContainer<DeferredRead> &deferredReads)
-{
+DeferredReadManager::popHead(ListContainer<DeferredRead> &deferredReads) {
assert (!deferredReads.empty());
if (!deferredReads.head->element.cancelled)
}
void
-DeferredReadManager::kickReads(int const count)
-{
+DeferredReadManager::kickReads(int const count) {
/* if we had List::size() we could consolidate this and flushReads */
if (count < 1) {
}
void
-DeferredReadManager::flushReads()
-{
+DeferredReadManager::flushReads() {
ListContainer<DeferredRead> reads;
reads = deferredReads;
deferredReads = ListContainer<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()
-{
+ConnectionDetail::ConnectionDetail() {
bzero(&me, sizeof(me));
bzero(&peer, sizeof(peer));
}