]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/JobWait.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "base/AsyncJobCalls.h"
11 #include "base/JobWait.h"
16 JobWaitBase::JobWaitBase() = default;
18 JobWaitBase::~JobWaitBase()
24 JobWaitBase::start_(const AsyncJob::Pointer aJob
, const AsyncCall::Pointer aCall
)
26 // Invariant: The wait will be over. We cannot guarantee that the job will
27 // call the callback, of course, but we can check these prerequisites.
31 // "Double" waiting state leads to conflicting/mismatching callbacks
32 // detailed in finish(). Detect that bug ASAP.
40 AsyncJob::Start(job_
.get());
46 // Unexpected callbacks might result in disasters like secrets exposure,
47 // data corruption, or expensive message routing mistakes when the callback
48 // info is applied to the wrong message part or acted upon prematurely.
54 JobWaitBase::cancel(const char *reason
)
57 callback_
->cancel(reason
);
59 // Instead of AsyncJob, the class parameter could be Job. That would
60 // avoid runtime child-to-parent CbcPointer conversion overheads, but
61 // complicate support for Jobs with virtual AsyncJob bases (GCC error:
62 // "pointer to member conversion via virtual base AsyncJob") and also
63 // cache-log "Job::handleStopRequest()" with a non-existent class name.
64 CallJobHere(callback_
->debugSection
, callback_
->debugLevel
, job_
, AsyncJob
, handleStopRequest
);
71 JobWaitBase::print(std::ostream
&os
) const
73 // use a backarrow to emphasize that this is a callback: call24<-job6
75 os
<< callback_
->id
<< "<-";
76 if (const auto rawJob
= job_
.get())
79 os
<< job_
; // raw pointer of a gone job may still be useful for triage