diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-31 18:34:56 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-31 18:34:56 +0200 |
commit | fac04eec8cfb0697456908250fb1ce8bf9414f4f (patch) | |
tree | f1dc0da5b852362a8ed70e39251535c570b7496d /plugins/fcgi | |
parent | 789ee91484c0f6376f941e3b9b52189eb6cc52fd (diff) |
FCGI: Speed up data reading
Diffstat (limited to 'plugins/fcgi')
-rw-r--r-- | plugins/fcgi/fcgi.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
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<char>& v) + FCGI_Record(std::vector<char>& 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<FCGI_Header*>(v.data())}; + FCGI_Header& r{*reinterpret_cast<FCGI_Header*>(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<char>& getBuffer() @@ -417,6 +417,7 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) #endif std::vector<char> 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) { |