From 7fcca0ce4b776637100f5dc1da8fda4e91668730 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Apr 2019 02:24:34 +0200 Subject: [PATCH] GHttp: Rename GHttpNetworkJob => GHttpJob. And tidy up a little bit. --- LibGUI/{GHttpNetworkJob.cpp => GHttpJob.cpp} | 17 ++++++++--------- LibGUI/{GHttpNetworkJob.h => GHttpJob.h} | 8 ++++---- LibGUI/GHttpRequest.cpp | 4 ++-- LibGUI/Makefile | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) rename LibGUI/{GHttpNetworkJob.cpp => GHttpJob.cpp} (89%) rename LibGUI/{GHttpNetworkJob.h => GHttpJob.h} (76%) diff --git a/LibGUI/GHttpNetworkJob.cpp b/LibGUI/GHttpJob.cpp similarity index 89% rename from LibGUI/GHttpNetworkJob.cpp rename to LibGUI/GHttpJob.cpp index e87bdbfa670..3c278f09712 100644 --- a/LibGUI/GHttpNetworkJob.cpp +++ b/LibGUI/GHttpJob.cpp @@ -1,19 +1,19 @@ -#include +#include #include #include #include #include -GHttpNetworkJob::GHttpNetworkJob(const GHttpRequest& request) +GHttpJob::GHttpJob(const GHttpRequest& request) : m_request(request) { } -GHttpNetworkJob::~GHttpNetworkJob() +GHttpJob::~GHttpJob() { } -void GHttpNetworkJob::start() +void GHttpJob::start() { ASSERT(!m_socket); m_socket = new GTCPSocket(this); @@ -35,7 +35,7 @@ void GHttpNetworkJob::start() while (!m_socket->can_read_line()) usleep(1); ASSERT(m_socket->can_read_line()); - auto line = m_socket->read_line(1024); + auto line = m_socket->read_line(PAGE_SIZE); if (line.is_null()) { printf("Expected HTTP status\n"); return deferred_invoke([this](auto&){ did_fail(GNetworkJob::Error::TransmissionFailed); }); @@ -57,7 +57,7 @@ void GHttpNetworkJob::start() if (m_state == State::InHeaders) { while (!m_socket->can_read_line()) usleep(1); - auto line = m_socket->read_line(1024); + auto line = m_socket->read_line(PAGE_SIZE); if (line.is_null()) { printf("Expected HTTP header\n"); return did_fail(GNetworkJob::Error::ProtocolFailed); @@ -83,7 +83,7 @@ void GHttpNetworkJob::start() continue; } ASSERT(m_state == State::InBody); - auto payload = m_socket->receive(100000); + auto payload = m_socket->receive(PAGE_SIZE); if (!payload) { if (m_socket->eof()) { m_state = State::Finished; @@ -95,8 +95,7 @@ void GHttpNetworkJob::start() } auto response = GHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size())); - deferred_invoke([this, response] (GObject&) { - printf("in the deferred invoke lambda\n"); + deferred_invoke([this, response] (auto&) { did_finish(move(response)); }); } diff --git a/LibGUI/GHttpNetworkJob.h b/LibGUI/GHttpJob.h similarity index 76% rename from LibGUI/GHttpNetworkJob.h rename to LibGUI/GHttpJob.h index 8abf7dff496..35ea33f2430 100644 --- a/LibGUI/GHttpNetworkJob.h +++ b/LibGUI/GHttpJob.h @@ -6,14 +6,14 @@ class GTCPSocket; -class GHttpNetworkJob final : public GNetworkJob { +class GHttpJob final : public GNetworkJob { public: - explicit GHttpNetworkJob(const GHttpRequest&); - virtual ~GHttpNetworkJob() override; + explicit GHttpJob(const GHttpRequest&); + virtual ~GHttpJob() override; virtual void start() override; - virtual const char* class_name() const override { return "GHttpNetworkJob"; } + virtual const char* class_name() const override { return "GHttpJob"; } private: enum class State { diff --git a/LibGUI/GHttpRequest.cpp b/LibGUI/GHttpRequest.cpp index 96e867eb111..529e340be2c 100644 --- a/LibGUI/GHttpRequest.cpp +++ b/LibGUI/GHttpRequest.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -13,7 +13,7 @@ GHttpRequest::~GHttpRequest() GNetworkJob* GHttpRequest::schedule() { - auto* job = new GHttpNetworkJob(*this); + auto* job = new GHttpJob(*this); job->start(); return job; } diff --git a/LibGUI/Makefile b/LibGUI/Makefile index 627b06965af..4053ecf04f5 100644 --- a/LibGUI/Makefile +++ b/LibGUI/Makefile @@ -62,7 +62,7 @@ LIBGUI_OBJS = \ GNetworkResponse.o \ GHttpRequest.o \ GHttpResponse.o \ - GHttpNetworkJob.o \ + GHttpJob.o \ GWindow.o OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)