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

@ -26,6 +26,8 @@ void CHttpJob::on_socket_connected()
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
m_socket->on_ready_to_read = [&] {
if (is_cancelled())
return;
if (m_state == State::InStatus) {
if (!m_socket->can_read_line())
return;
@ -125,3 +127,12 @@ void CHttpJob::start()
if (!success)
return did_fail(CNetworkJob::Error::ConnectionFailed);
}
void CHttpJob::shutdown()
{
if (!m_socket)
return;
m_socket->on_ready_to_read = nullptr;
m_socket->on_connected = nullptr;
m_socket = nullptr;
}