1
Fork 0
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:
Andreas Kling 2019-09-21 17:32:26 +02:00
parent ff6ce422dd
commit bdf23a3d23
7 changed files with 31 additions and 2 deletions

View file

@ -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();