diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-19 20:16:36 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-19 20:16:36 +0200 |
commit | 2eaadcf4e7f4a3a9c246f32090d03fbb61209677 (patch) | |
tree | de4c18b9351e6bc69bb3ef7c35e9ab91c03f8761 | |
parent | 85a630f36edc098f312ca2049917018210061258 (diff) |
Bugfix: Keep FCGI connections really open
-rw-r--r-- | plugins/fcgi/fcgi.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/plugins/fcgi/fcgi.cpp b/plugins/fcgi/fcgi.cpp index a1529bc..5a7ce65 100644 --- a/plugins/fcgi/fcgi.cpp +++ b/plugins/fcgi/fcgi.cpp @@ -356,8 +356,6 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) std::lock_guard<std::mutex> socket_lock{socket->getMutex()}; - socket->close(); // TODO: Bug workaround: Keeping socket open doesn't work for now. Subsequent requests are cancelled because connection is already closed by server. - if (!socket->is_open()) { //std::cout << "FCGI: Opening new socket" << std::endl; @@ -373,36 +371,35 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) uint16_t id {id_guard.getID()}; try { + std::vector<char> buffer; + if (opening) { FCGI_Record get_values{FCGI_GET_VALUES, 0, system_config_bytes}; - if (socket->write(get_values.getBuffer()) != get_values.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 1" << std::endl; + buffer.insert(buffer.end(), get_values.getBuffer().begin(), get_values.getBuffer().end()); } FCGI_Record begin_request{FCGI_BEGIN_REQUEST, id, FCGI_RESPONDER, FCGI_KEEP_CONN}; - if (socket->write(begin_request.getBuffer()) != begin_request.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 2" << std::endl; + buffer.insert(buffer.end(), begin_request.getBuffer().begin(), begin_request.getBuffer().end()); FCGI_Record params{FCGI_PARAMS, id, env_bytes}; - if (socket->write(params.getBuffer()) != params.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 3" << std::endl; + buffer.insert(buffer.end(), params.getBuffer().begin(), params.getBuffer().end()); if (env_bytes.size()) { FCGI_Record params_end{FCGI_PARAMS, id, std::string{}}; - if (socket->write(params_end.getBuffer()) != params_end.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 4" << std::endl; + buffer.insert(buffer.end(), params_end.getBuffer().begin(), params_end.getBuffer().end()); } std::string body {context.GetRequestParam("body")}; FCGI_Record stdin_{FCGI_STDIN, id, body}; - if (socket->write(stdin_.getBuffer()) != stdin_.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 5" << std::endl; + buffer.insert(buffer.end(), stdin_.getBuffer().begin(), stdin_.getBuffer().end()); if (body.size()) { FCGI_Record stdin_end{FCGI_STDIN, id, std::string{}}; - if (socket->write(stdin_end.getBuffer()) != stdin_end.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 6" << std::endl; + buffer.insert(buffer.end(), stdin_end.getBuffer().begin(), stdin_end.getBuffer().end()); } + + if (socket->write(buffer) != buffer.size()) + std::cerr << "Warning: Not all bytes written" << std::endl; } catch (const fcgi_eof_error&) { std::cerr << "FCGI Error: EOF on write" << std::endl; // seems to be ok here return HttpStatus("500", "FCGI connection: EOF on write", context.SetResponseHeader); |