]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
De-duplicate I/O error-detailing code (#1723)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Fri, 8 Mar 2024 06:03:20 +0000 (06:03 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 8 Mar 2024 14:14:02 +0000 (14:14 +0000)
This improvement eliminates code duplication introduced
in recent commit b850f8b.

src/FwdState.cc
src/LogTags.cc
src/LogTags.h
src/servers/Server.cc

index 509127fc52567ece65d677db4925df1588d769bf..abae1d6a5ac471e31abe31018534cdadc7194f3d 100644 (file)
@@ -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");
index 36402056735e5086f0fc2e961b694a4fc99aaf9c..548023fb7466230bc6ce09e0863f6e4ec6b99b98 100644 (file)
@@ -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
index d101c81a9937e4592ab5901829d58a6235413dd6..fe6f658b354b58b482ab58f48e65371f9d7256f6 100644 (file)
@@ -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);
index 1dc20e56af4e966685bf0f5d700b7f1ac65fe11f..eba0fca3e7c1ee912a12b3f305438b7758e4aa34 100644 (file)
@@ -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;
     }