diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-05-03 09:25:38 +0200 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-05-03 09:25:38 +0200 | 
| commit | f49cd79ed8cdb1cb8988aad2cfa3f22d4866fb27 (patch) | |
| tree | afc33b8232ba9e0bf8871657c0e8bdd968e3aedc | |
| parent | 5f39c4bcd3ea85ce6a30446d23ccae0542bfbdaf (diff) | |
FCGI: Fix multithreading for m_socket
| -rw-r--r-- | plugins/fcgi/fcgi.cpp | 14 | ||||
| -rw-r--r-- | plugins/fcgi/fcgi.h | 5 | 
2 files changed, 17 insertions, 2 deletions
diff --git a/plugins/fcgi/fcgi.cpp b/plugins/fcgi/fcgi.cpp index b9e279f..416ca24 100644 --- a/plugins/fcgi/fcgi.cpp +++ b/plugins/fcgi/fcgi.cpp @@ -347,6 +347,9 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context)   if (pos != app_addr.npos) { // host:port    auto endpoints{m_resolver.resolve(app_addr.substr(0, pos), app_addr.substr(pos + 1))};    bool opening{false}; +   +  std::lock_guard<std::mutex> socket_lock{m_socket_mutex}; +    if (!m_socket.is_open()) {     std::cout << "FCGI: Opening new socket" << std::endl;     boost::asio::connect(m_socket, endpoints); @@ -434,8 +437,17 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context)      }     }    } - } else { // Unix domain socket, or file to start + } else if (fs::is_socket(fs::path{app_addr})) { // Unix domain socket +  // TODO +  std::cerr << "FCGI Error: Unix domain sockets not yet implemented." << std::endl; +  return HttpStatus("500", "FCGI configuration", context.SetResponseHeader); + } else if (fs::is_regular_file(fs::path{app_addr})) { // Executable to start    // TODO +  std::cerr << "FCGI Error: Executable FCGI not yet implemented." << std::endl; +  return HttpStatus("500", "FCGI configuration", context.SetResponseHeader); + } else { +  std::cerr << "FCGI Error: Invalid app_addr type." << std::endl; +  return HttpStatus("500", "FCGI configuration", context.SetResponseHeader);   }   std::istringstream is_out{output_data}; diff --git a/plugins/fcgi/fcgi.h b/plugins/fcgi/fcgi.h index 22d7fba..b881aec 100644 --- a/plugins/fcgi/fcgi.h +++ b/plugins/fcgi/fcgi.h @@ -4,8 +4,9 @@  #include <boost/asio.hpp> -#include <set>  #include <cstdint> +#include <mutex> +#include <set>  // TODO: multithreading  class FCGI_ID @@ -59,6 +60,8 @@ class fcgi_plugin: public webserver_plugin_interface   FCGI_ID m_fcgi_id;   boost::asio::io_context m_io_context;   boost::asio::ip::tcp::resolver m_resolver; + + std::mutex m_socket_mutex; // guard m_socket use in different threads   boost::asio::ip::tcp::socket m_socket;  public:  | 
