mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 09:17:35 +00:00
LibCore: Make it possible to cancel pending CNetworkJobs
Subclasses of CNetworkJob handle this by overriding shutdown(). This patch implements it for CHttpJob by simply tearing down the underlying socket. We also automatically call shutdown() after the job finishes, regardless of success or failure. :^)
This commit is contained in:
parent
ff6ce422dd
commit
bdf23a3d23
7 changed files with 31 additions and 2 deletions
|
@ -13,17 +13,26 @@ public:
|
|||
ConnectionFailed,
|
||||
TransmissionFailed,
|
||||
ProtocolFailed,
|
||||
Cancelled,
|
||||
};
|
||||
virtual ~CNetworkJob() override;
|
||||
|
||||
Function<void(bool success)> on_finish;
|
||||
|
||||
bool is_cancelled() const { return m_error == Error::Cancelled; }
|
||||
bool has_error() const { return m_error != Error::None; }
|
||||
Error error() const { return m_error; }
|
||||
CNetworkResponse* response() { return m_response.ptr(); }
|
||||
const CNetworkResponse* response() const { return m_response.ptr(); }
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void shutdown() = 0;
|
||||
|
||||
void cancel()
|
||||
{
|
||||
shutdown();
|
||||
m_error = Error::Cancelled;
|
||||
}
|
||||
|
||||
protected:
|
||||
CNetworkJob();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue