From ff472233014168a03e9daefee7ea05603aaebc58 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 9 Feb 2023 19:07:11 -0500 Subject: [PATCH] LibCore: Make `NetworkJob::start()` take a `Stream::BufferedSocketBase&` It used to take a plain `Socket` and cast it to a `BufferedSocketBase`, which can lead to unpleasant result when used with a non-buffered `Socket`. --- Userland/Libraries/LibCore/NetworkJob.h | 2 +- Userland/Libraries/LibGemini/Job.cpp | 4 ++-- Userland/Libraries/LibGemini/Job.h | 2 +- Userland/Libraries/LibHTTP/Job.cpp | 4 ++-- Userland/Libraries/LibHTTP/Job.h | 2 +- Userland/Services/RequestServer/ConnectionCache.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibCore/NetworkJob.h b/Userland/Libraries/LibCore/NetworkJob.h index 529201f97b1..cdf66cc04d1 100644 --- a/Userland/Libraries/LibCore/NetworkJob.h +++ b/Userland/Libraries/LibCore/NetworkJob.h @@ -41,7 +41,7 @@ public: DetachFromSocket, CloseSocket, }; - virtual void start(Core::Socket&) = 0; + virtual void start(Core::BufferedSocketBase&) = 0; virtual void shutdown(ShutdownMode) = 0; virtual void fail(Error error) { did_fail(error); } diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp index 6e8f9b013f6..4281fb9d928 100644 --- a/Userland/Libraries/LibGemini/Job.cpp +++ b/Userland/Libraries/LibGemini/Job.cpp @@ -20,10 +20,10 @@ Job::Job(GeminiRequest const& request, Stream& output_stream) { } -void Job::start(Core::Socket& socket) +void Job::start(Core::BufferedSocketBase& socket) { VERIFY(!m_socket); - m_socket = verify_cast(&socket); + m_socket = &socket; on_socket_connected(); } diff --git a/Userland/Libraries/LibGemini/Job.h b/Userland/Libraries/LibGemini/Job.h index e2f53df2adc..9df185ee385 100644 --- a/Userland/Libraries/LibGemini/Job.h +++ b/Userland/Libraries/LibGemini/Job.h @@ -21,7 +21,7 @@ public: explicit Job(GeminiRequest const&, Stream&); virtual ~Job() override = default; - virtual void start(Core::Socket&) override; + virtual void start(Core::BufferedSocketBase&) override; virtual void shutdown(ShutdownMode) override; GeminiResponse* response() { return static_cast(Core::NetworkJob::response()); } diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index a66fe7a7813..e8f9458b0dc 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -92,10 +92,10 @@ Job::Job(HttpRequest&& request, Stream& output_stream) { } -void Job::start(Core::Socket& socket) +void Job::start(Core::BufferedSocketBase& socket) { VERIFY(!m_socket); - m_socket = static_cast(&socket); + m_socket = &socket; dbgln_if(HTTPJOB_DEBUG, "Reusing previous connection for {}", url()); deferred_invoke([this] { dbgln_if(HTTPJOB_DEBUG, "HttpJob: on_connected callback"); diff --git a/Userland/Libraries/LibHTTP/Job.h b/Userland/Libraries/LibHTTP/Job.h index 4eff55567d6..771f3cee4f2 100644 --- a/Userland/Libraries/LibHTTP/Job.h +++ b/Userland/Libraries/LibHTTP/Job.h @@ -22,7 +22,7 @@ public: explicit Job(HttpRequest&&, Stream&); virtual ~Job() override = default; - virtual void start(Core::Socket&) override; + virtual void start(Core::BufferedSocketBase&) override; virtual void shutdown(ShutdownMode) override; Core::Socket const* socket() const { return m_socket; } diff --git a/Userland/Services/RequestServer/ConnectionCache.h b/Userland/Services/RequestServer/ConnectionCache.h index 24bd516bb76..9f270a8c387 100644 --- a/Userland/Services/RequestServer/ConnectionCache.h +++ b/Userland/Services/RequestServer/ConnectionCache.h @@ -56,7 +56,7 @@ struct Proxy { template struct Connection { struct JobData { - Function start {}; + Function start {}; Function fail {}; Function()> provide_client_certificates {};