1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:38:10 +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

@ -16,7 +16,7 @@ void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
dbg() << *this << " job did_finish!";
ASSERT(on_finish);
on_finish(true);
delete_later();
shutdown();
}
void CNetworkJob::did_fail(Error error)
@ -25,7 +25,7 @@ void CNetworkJob::did_fail(Error error)
dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));
ASSERT(on_finish);
on_finish(false);
delete_later();
shutdown();
}
const char* to_string(CNetworkJob::Error error)
@ -37,6 +37,8 @@ const char* to_string(CNetworkJob::Error error)
return "ConnectionFailed";
case CNetworkJob::Error::TransmissionFailed:
return "TransmissionFailed";
case CNetworkJob::Error::Cancelled:
return "Cancelled";
default:
return "(Unknown error)";
}