From: Alex Rousskov Date: Thu, 15 Jul 2021 21:58:50 +0000 (-0400) Subject: fixup: Moved JobWait classes to their own files X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d222cf69c0c5d7eba7fc1c29bfccdd72c66226b;p=thirdparty%2Fsquid.git fixup: Moved JobWait classes to their own files Technically, there may exist some code that uses JobWait but does not make any JobCalls itself. And the new classes are big/interesting enough to deserve their own files anyway. --- diff --git a/src/FwdState.h b/src/FwdState.h index c8e03500ec..b501ad66f6 100644 --- a/src/FwdState.h +++ b/src/FwdState.h @@ -10,6 +10,7 @@ #define SQUID_FORWARD_H #include "base/forward.h" +#include "base/JobWait.h" #include "base/RefCount.h" #include "clients/forward.h" #include "comm.h" diff --git a/src/PeerPoolMgr.h b/src/PeerPoolMgr.h index 4dd7e4bc5d..ae07c1fd1c 100644 --- a/src/PeerPoolMgr.h +++ b/src/PeerPoolMgr.h @@ -10,7 +10,7 @@ #define SQUID_PEERPOOLMGR_H #include "base/AsyncJob.h" -#include "base/forward.h" +#include "base/JobWait.h" #include "comm/forward.h" #include "security/forward.h" diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index cc9edffa90..6a27bb683f 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -13,7 +13,7 @@ #include "adaptation/icap/Config.h" #include "adaptation/icap/Launcher.h" #include "adaptation/icap/Xaction.h" -#include "base/AsyncJobCalls.h" +#include "base/JobWait.h" #include "base/TextException.h" #include "comm.h" #include "comm/Connection.h" diff --git a/src/adaptation/icap/Xaction.h b/src/adaptation/icap/Xaction.h index 9956d9ac1e..ad78e4e754 100644 --- a/src/adaptation/icap/Xaction.h +++ b/src/adaptation/icap/Xaction.h @@ -12,7 +12,7 @@ #include "AccessLogEntry.h" #include "adaptation/icap/ServiceRep.h" #include "adaptation/Initiate.h" -#include "base/forward.h" +#include "base/JobWait.h" #include "comm/ConnOpener.h" #include "HttpReply.h" #include "ipcache.h" diff --git a/src/base/AsyncJobCalls.h b/src/base/AsyncJobCalls.h index ec9a968ae7..811ac7414c 100644 --- a/src/base/AsyncJobCalls.h +++ b/src/base/AsyncJobCalls.h @@ -13,8 +13,6 @@ #include "base/CbcPointer.h" #include "Debug.h" -#include - /** \ingroup AsyncJobAPI * This is a base class for all job call dialers. It does all the job @@ -184,78 +182,5 @@ JobDialer::dial(AsyncCall &call) job->callEnd(); // may delete job } -/// Manages waiting for an AsyncJob callback. Use type-safe JobWait instead. -/// This base class does not contain code specific to the actual Job type. -class JobWaitBase -{ -public: - JobWaitBase(); - ~JobWaitBase(); - - /// no copying of any kind: each waiting context needs a dedicated AsyncCall - JobWaitBase(JobWaitBase &&) = delete; - - explicit operator bool() const { return waiting(); } - - /// whether we are currently waiting for the job to call us back - /// the job itself may be gone even if this returns true - bool waiting() const { return bool(callback_); } - - /// ends wait (after receiving the call back) - /// forgets the job which is likely to be gone by now - void finish(); - - /// aborts wait (if any) before receiving the call back - /// does nothing if we are not waiting - void cancel(const char *reason); - - /// summarizes what we are waiting for (for debugging) - void print(std::ostream &) const; - -protected: - /// starts waiting for the given job to call the given callback - void start_(AsyncJob::Pointer, AsyncCall::Pointer); - -private: - /// the common part of finish() and cancel() - void clear() { job_.clear(); callback_ = nullptr; } - - /// the job that we are waiting to call us back (or nil) - AsyncJob::Pointer job_; - - /// the call we are waiting for the job_ to make (or nil) - AsyncCall::Pointer callback_; -}; - -/// Manages waiting for an AsyncJob callback. -/// Completes JobWaitBase by providing Job type-specific members. -template -class JobWait: public JobWaitBase -{ -public: - typedef CbcPointer JobPointer; - - /// starts waiting for the given job to call the given callback - void start(const JobPointer &aJob, const AsyncCall::Pointer &aCallback) { - start_(aJob, aCallback); - typedJob_ = aJob; - } - - /// \returns a cbdata pointer to the job we are waiting for (or nil) - /// the returned pointer may be falsy, even if we are still waiting() - JobPointer job() const { return waiting() ? typedJob_ : nullptr; } - -private: - /// nearly duplicates JobWaitBase::typedJob_ but exposes the actual job type - JobPointer typedJob_; -}; - -inline -std::ostream &operator <<(std::ostream &os, const JobWaitBase &wait) -{ - wait.print(os); - return os; -} - #endif /* SQUID_ASYNCJOBCALLS_H */ diff --git a/src/base/AsyncJobCalls.cc b/src/base/JobWait.cc similarity index 98% rename from src/base/AsyncJobCalls.cc rename to src/base/JobWait.cc index 2e88a97521..cc6b0c5d5f 100644 --- a/src/base/AsyncJobCalls.cc +++ b/src/base/JobWait.cc @@ -8,7 +8,7 @@ #include "squid.h" #include "base/AsyncJobCalls.h" -#include "Debug.h" +#include "base/JobWait.h" #include #include diff --git a/src/base/JobWait.h b/src/base/JobWait.h new file mode 100644 index 0000000000..fff9accaf0 --- /dev/null +++ b/src/base/JobWait.h @@ -0,0 +1,91 @@ +/* + * 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. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#ifndef SQUID_BASE_JOBWAIT_H +#define SQUID_BASE_JOBWAIT_H + +#include "base/AsyncJob.h" +#include "base/CbcPointer.h" + +#include + +/// Manages waiting for an AsyncJob callback. Use type-safe JobWait instead. +/// This base class does not contain code specific to the actual Job type. +class JobWaitBase +{ +public: + JobWaitBase(); + ~JobWaitBase(); + + /// no copying of any kind: each waiting context needs a dedicated AsyncCall + JobWaitBase(JobWaitBase &&) = delete; + + explicit operator bool() const { return waiting(); } + + /// whether we are currently waiting for the job to call us back + /// the job itself may be gone even if this returns true + bool waiting() const { return bool(callback_); } + + /// ends wait (after receiving the call back) + /// forgets the job which is likely to be gone by now + void finish(); + + /// aborts wait (if any) before receiving the call back + /// does nothing if we are not waiting + void cancel(const char *reason); + + /// summarizes what we are waiting for (for debugging) + void print(std::ostream &) const; + +protected: + /// starts waiting for the given job to call the given callback + void start_(AsyncJob::Pointer, AsyncCall::Pointer); + +private: + /// the common part of finish() and cancel() + void clear() { job_.clear(); callback_ = nullptr; } + + /// the job that we are waiting to call us back (or nil) + AsyncJob::Pointer job_; + + /// the call we are waiting for the job_ to make (or nil) + AsyncCall::Pointer callback_; +}; + +/// Manages waiting for an AsyncJob callback. +/// Completes JobWaitBase by providing Job type-specific members. +template +class JobWait: public JobWaitBase +{ +public: + typedef CbcPointer JobPointer; + + /// starts waiting for the given job to call the given callback + void start(const JobPointer &aJob, const AsyncCall::Pointer &aCallback) { + start_(aJob, aCallback); + typedJob_ = aJob; + } + + /// \returns a cbdata pointer to the job we are waiting for (or nil) + /// the returned pointer may be falsy, even if we are still waiting() + JobPointer job() const { return waiting() ? typedJob_ : nullptr; } + +private: + /// nearly duplicates JobWaitBase::typedJob_ but exposes the actual job type + JobPointer typedJob_; +}; + +inline +std::ostream &operator <<(std::ostream &os, const JobWaitBase &wait) +{ + wait.print(os); + return os; +} + +#endif /* SQUID_BASE_JOBWAIT_H */ + diff --git a/src/base/Makefile.am b/src/base/Makefile.am index f1934d6b34..30e50257d7 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -18,7 +18,6 @@ libbase_la_SOURCES = \ AsyncCbdataCalls.h \ AsyncJob.cc \ AsyncJob.h \ - AsyncJobCalls.cc \ AsyncJobCalls.h \ ByteCounter.h \ CbDataList.h \ @@ -36,6 +35,8 @@ libbase_la_SOURCES = \ Here.h \ InstanceId.cc \ InstanceId.h \ + JobWait.cc \ + JobWait.h \ Lock.h \ LookupTable.h \ Optional.h \ diff --git a/src/comm/Connection.cc b/src/comm/Connection.cc index 3217d0b71e..1f1c706513 100644 --- a/src/comm/Connection.cc +++ b/src/comm/Connection.cc @@ -7,6 +7,7 @@ */ #include "squid.h" +#include "base/JobWait.h" #include "CachePeer.h" #include "cbdata.h" #include "comm.h" diff --git a/src/log/TcpLogger.h b/src/log/TcpLogger.h index 7a316729bd..b1ff6e16e5 100644 --- a/src/log/TcpLogger.h +++ b/src/log/TcpLogger.h @@ -10,7 +10,7 @@ #define _SQUID_SRC_LOG_TCPLOGGER_H #include "base/AsyncJob.h" -#include "base/forward.h" +#include "base/JobWait.h" #include "comm/forward.h" #include "ip/Address.h" diff --git a/src/security/PeerConnector.h b/src/security/PeerConnector.h index cb6cb0f642..4c81d55396 100644 --- a/src/security/PeerConnector.h +++ b/src/security/PeerConnector.h @@ -12,7 +12,7 @@ #include "acl/Acl.h" #include "base/AsyncCbdataCalls.h" #include "base/AsyncJob.h" -#include "base/forward.h" +#include "base/JobWait.h" #include "CommCalls.h" #include "http/forward.h" #include "security/EncryptorAnswer.h" diff --git a/src/servers/FtpServer.h b/src/servers/FtpServer.h index fc73accbc4..10f9d4ff9d 100644 --- a/src/servers/FtpServer.h +++ b/src/servers/FtpServer.h @@ -11,7 +11,7 @@ #ifndef SQUID_SERVERS_FTP_SERVER_H #define SQUID_SERVERS_FTP_SERVER_H -#include "base/forward.h" +#include "base/JobWait.h" #include "base/Lock.h" #include "client_side.h" #include "comm/forward.h" diff --git a/src/tunnel.cc b/src/tunnel.cc index da7c1b8c91..d1e3e402fb 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -11,6 +11,7 @@ #include "squid.h" #include "acl/FilledChecklist.h" #include "base/CbcPointer.h" +#include "base/JobWait.h" #include "CachePeer.h" #include "cbdata.h" #include "client_side.h"