From fac04eec8cfb0697456908250fb1ce8bf9414f4f Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 31 May 2020 18:34:56 +0200 Subject: FCGI: Speed up data reading --- plugins/fcgi/fcgi.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'plugins/fcgi') diff --git a/plugins/fcgi/fcgi.cpp b/plugins/fcgi/fcgi.cpp index 0d845a6..2ba8ba3 100644 --- a/plugins/fcgi/fcgi.cpp +++ b/plugins/fcgi/fcgi.cpp @@ -179,21 +179,21 @@ namespace { } // parse record - FCGI_Record(std::vector& v) + FCGI_Record(std::vector& v, size_t& start_at) { - if (v.size() < sizeof(FCGI_Header)) + if (v.size() - start_at < sizeof(FCGI_Header)) throw std::length_error("No full FCGI header available"); - FCGI_Header& r{*reinterpret_cast(v.data())}; + FCGI_Header& r{*reinterpret_cast(v.data() + start_at)}; size_t content_length {((size_t)r.contentLengthB1) << 8 | r.contentLengthB0}; size_t record_size {sizeof(FCGI_Header) + content_length + r.paddingLength}; - if (v.size() < record_size) + if (v.size() - start_at < record_size) throw std::length_error("No full FCGI record available"); - m_data = std::vector(v.begin(), v.begin() + record_size - r.paddingLength); + m_data = std::vector(v.begin() + start_at, v.begin() + start_at + record_size - r.paddingLength); - v.erase(v.begin(), v.begin() + record_size); + start_at += record_size; } std::vector& getBuffer() @@ -417,6 +417,7 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) #endif std::vector inbuf; + size_t processed{0}; bool ended{false}; while (!ended) { @@ -429,10 +430,11 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) //return HttpStatus("500", "FCGI connection: EOF on read", context.SetResponseHeader); } - while (inbuf.size() > 0) { + while (inbuf.size() - processed > 0) { + std::cout << "DEBUG: inbuf.size() == " << inbuf.size() << ", output_data.size() == " << output_data.size() << std::endl; try { - FCGI_Record r{inbuf}; + FCGI_Record r{inbuf, processed}; if (r.getType() == FCGI_END_REQUEST) { ended = true; } else if (r.getType() == FCGI_STDOUT) { -- cgit v1.2.3