summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CHttpJob.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-21 17:32:26 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-21 17:32:26 +0200
commitbdf23a3d23042e558183932585d49c9513393a06 (patch)
treefea9a721c42a6bf2a6f0e65fad20c168332fa39b /Libraries/LibCore/CHttpJob.cpp
parentff6ce422ddecb7dcb7fd9f67d3ea0cfdec7e74ea (diff)
downloadserenity-bdf23a3d23042e558183932585d49c9513393a06.zip
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. :^)
Diffstat (limited to 'Libraries/LibCore/CHttpJob.cpp')
-rw-r--r--Libraries/LibCore/CHttpJob.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibCore/CHttpJob.cpp b/Libraries/LibCore/CHttpJob.cpp
index 472aae01d9..6ddde0475a 100644
--- a/Libraries/LibCore/CHttpJob.cpp
+++ b/Libraries/LibCore/CHttpJob.cpp
@@ -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;
+}