diff --git a/src/FwdState.cc b/src/FwdState.cc index 509127fc525..abae1d6a5ac 100644 --- a/src/FwdState.cc +++ b/src/FwdState.cc @@ -240,11 +240,7 @@ FwdState::updateAleWithFinalError() if (!err || !al) return; - LogTagsErrors lte; - if (err->xerrno == ETIMEDOUT || err->type == ERR_READ_TIMEOUT) - lte.timedout = true; - else if (err->type != ERR_NONE) - lte.aborted = true; + const auto lte = LogTagsErrors::FromErrno(err->type == ERR_READ_TIMEOUT ? ETIMEDOUT : err->xerrno); al->cache.code.err.update(lte); if (!err->detail) { static const auto d = MakeNamedErrorDetail("WITH_SERVER"); diff --git a/src/LogTags.cc b/src/LogTags.cc index 36402056735..548023fb746 100644 --- a/src/LogTags.cc +++ b/src/LogTags.cc @@ -18,6 +18,15 @@ LogTagsErrors::update(const LogTagsErrors &other) aborted = aborted || other.aborted; } +LogTagsErrors +LogTagsErrors::FromErrno(const int errNo) +{ + LogTagsErrors lte; + lte.timedout = (errNo == ETIMEDOUT); + lte.aborted = !lte.timedout; // intentionally true for zero errNo + return lte; +} + /* LogTags */ // old deprecated tag strings diff --git a/src/LogTags.h b/src/LogTags.h index d101c81a993..fe6f658b354 100644 --- a/src/LogTags.h +++ b/src/LogTags.h @@ -17,6 +17,9 @@ class LogTagsErrors { public: + /// constructs an object matching errno(3) of a failed I/O call + static LogTagsErrors FromErrno(int errNo); + /// Update each of this object flags to "set" if the corresponding /// flag of the given object is set void update(const LogTagsErrors &other); diff --git a/src/servers/Server.cc b/src/servers/Server.cc index 1dc20e56af4..eba0fca3e7c 100644 --- a/src/servers/Server.cc +++ b/src/servers/Server.cc @@ -173,10 +173,7 @@ Server::doClientRead(const CommIoCbParams &io) // case Comm::COMM_ERROR: default: // no other flags should ever occur debugs(33, 2, io.conn << ": got flag " << rd.flag << "; " << xstrerr(rd.xerrno)); - LogTagsErrors lte; - lte.timedout = rd.xerrno == ETIMEDOUT; - lte.aborted = !lte.timedout; // intentionally true for zero rd.xerrno - terminateAll(Error(ERR_READ_ERROR, SysErrorDetail::NewIfAny(rd.xerrno)), lte); + terminateAll(Error(ERR_READ_ERROR, SysErrorDetail::NewIfAny(rd.xerrno)), LogTagsErrors::FromErrno(rd.xerrno)); return; } @@ -206,10 +203,7 @@ Server::clientWriteDone(const CommIoCbParams &io) if (io.flag) { debugs(33, 2, "bailing after a write failure: " << xstrerr(io.xerrno)); - LogTagsErrors lte; - lte.timedout = io.xerrno == ETIMEDOUT; - lte.aborted = !lte.timedout; // intentionally true for zero io.xerrno - terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), lte); + terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), LogTagsErrors::FromErrno(io.xerrno)); return; }