/*
- * DEBUG: section 05 Socket Functions
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+
+/* DEBUG: section 05 Socket Functions */
+
#include "squid.h"
#include "comm.h"
#include "comm/IoCallback.h"
#include "Debug.h"
#include "fd.h"
#include "fde.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.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
bool
Comm::MonitorsRead(int fd)
{
- assert(isOpen(fd) && COMMIO_FD_READCB(fd));
+ assert(isOpen(fd) && COMMIO_FD_READCB(fd) != NULL);
// Being active is usually the same as monitoring because we always
// start monitoring the FD when we configure Comm::IoCallback for I/O
// and we usually configure Comm::IoCallback for I/O when we starting
{
/* Attempt a read */
++ statCounter.syscalls.sock.reads;
- const SBuf::size_type sz = buf.spaceSize();
+ SBuf::size_type sz = buf.spaceSize();
+ if (params.size > 0 && params.size < sz)
+ sz = params.size;
char *inbuf = buf.rawSpace(sz);
errno = 0;
const int retval = FD_READ_METHOD(params.conn->fd, inbuf, sz);
/* 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;
};
/* And the IO event */
Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0);
}
+