/*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "Debug.h"
#include "fd.h"
#include "fde.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
+#include "SquidConfig.h"
#include "StatCounters.h"
-//#include "tools.h"
// Does comm check this fd for read readiness?
// Note that when comm is not monitoring, there can be a pending callback
SBuf::size_type sz = buf.spaceSize();
if (params.size > 0 && params.size < sz)
sz = params.size;
- char *inbuf = buf.rawSpace(sz);
+ char *inbuf = buf.rawAppendStart(sz);
errno = 0;
const int retval = FD_READ_METHOD(params.conn->fd, inbuf, sz);
params.xerrno = errno;
debugs(5, 3, params.conn << ", size " << sz << ", retval " << retval << ", errno " << params.xerrno);
if (retval > 0) { // data read most common case
- buf.append(inbuf, retval);
+ buf.rawAppendFinish(inbuf, retval);
fd_bytes(params.conn->fd, retval, FD_READ);
params.flag = Comm::OK;
params.size = retval;
} else if (retval == 0) { // remote closure (somewhat less) common
// Note - read 0 == socket EOF, which is a valid read.
params.flag = Comm::ENDFILE;
+ params.size = 0;
} else if (retval < 0) { // connection errors are worst-case
debugs(5, 3, params.conn << " Comm::COMM_ERROR: " << xstrerr(params.xerrno));
params.flag = Comm::INPROGRESS;
else
params.flag = Comm::COMM_ERROR;
+ params.size = 0;
}
return params.flag;
/* For legacy callers : Attempt a read */
// Keep in sync with Comm::ReadNow()!
++ statCounter.syscalls.sock.reads;
- errno = 0;
+ int xerrno = errno = 0;
int retval = FD_READ_METHOD(fd, ccb->buf, ccb->size);
- debugs(5, 3, "FD " << fd << ", size " << ccb->size << ", retval " << retval << ", errno " << errno);
+ xerrno = errno;
+ debugs(5, 3, "FD " << fd << ", size " << ccb->size << ", retval " << retval << ", errno " << xerrno);
/* See if we read anything */
/* Note - read 0 == socket EOF, which is a valid read */
if (retval >= 0) {
fd_bytes(fd, retval, FD_READ);
ccb->offset = retval;
- ccb->finish(Comm::OK, errno);
+ ccb->finish(Comm::OK, 0);
return;
-
- } else if (retval < 0 && !ignoreErrno(errno)) {
+ } else if (retval < 0 && !ignoreErrno(xerrno)) {
debugs(5, 3, "comm_read_try: scheduling Comm::COMM_ERROR");
ccb->offset = 0;
- ccb->finish(Comm::COMM_ERROR, errno);
+ ccb->finish(Comm::COMM_ERROR, xerrno);
return;
};
Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0);
}
+time_t
+Comm::MortalReadTimeout(const time_t startTime, const time_t lifetimeLimit)
+{
+ if (lifetimeLimit > 0) {
+ const time_t timeUsed = (squid_curtime > startTime) ? (squid_curtime - startTime) : 0;
+ const time_t timeLeft = (lifetimeLimit > timeUsed) ? (lifetimeLimit - timeUsed) : 0;
+ return min(::Config.Timeout.read, timeLeft);
+ } else
+ return ::Config.Timeout.read;
+}
+