diff --git a/src/frontends/fcgi/fcgi.cpp b/src/frontends/fcgi/fcgi.cpp index 0793632..7b87268 100644 --- a/src/frontends/fcgi/fcgi.cpp +++ b/src/frontends/fcgi/fcgi.cpp @@ -19,11 +19,16 @@ #include #include #include +#include +#include +#include +#include #include #include "fcgi.h" #include "config/config_loader.h" #include "logger.h" +using namespace std::string_literals; constexpr int FCGI_LISTENSOCK_FILENO = STDIN_FILENO; HTTP::Response Route::fcgi_request(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg) @@ -53,9 +58,24 @@ void Frontend::init_fcgi(HTTP::Server* server) setup_routes(server); } -void Frontend::poll_data(std::array data) +void Frontend::poll_fcgi_pipes(std::array data) { - + fd_set rfds; + struct timeval tv = {0, 0}; + int rc; + + do + { + FD_ZERO(&rfds); + FD_SET(data[0], &rfds); + + rc = select(data[0]+1, &rfds, nullptr, nullptr, &tv); + if (rc == -1) + { + Logger::instance().log("select(): "s + std::strerror(errno), Logger::Level::ERROR); + } + } + while (rc); } std::array Frontend::fork_fcgi_process() diff --git a/src/frontends/fcgi/fcgi.h b/src/frontends/fcgi/fcgi.h index 5de040d..b0c87f7 100644 --- a/src/frontends/fcgi/fcgi.h +++ b/src/frontends/fcgi/fcgi.h @@ -29,7 +29,7 @@ namespace Route namespace Frontend { void init_fcgi(HTTP::Server* server); - void poll_data(std::array data); + void poll_fcgi_pipes(std::array data); std::array fork_fcgi_process(); } diff --git a/src/http/microhttpd_server.cpp b/src/http/microhttpd_server.cpp index e55ccec..ba7fc8d 100644 --- a/src/http/microhttpd_server.cpp +++ b/src/http/microhttpd_server.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "logger.h" #include "microhttpd_server.h" #include "http/mime.h" @@ -187,7 +188,7 @@ void MicroHttpdServer::start() { // MicroHTTPD seems to keep the errors in errno, but doesn't really have a good error system Logger::instance().log("Couldn't start MicroHTTPD daemon at port "s + std::to_string(get_port()) + - ": " + strerror(errno), + ": " + std::strerror(errno), Logger::Level::ERROR); exit(1); } diff --git a/src/main.cpp b/src/main.cpp index ae7427b..3d5cf58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,7 +149,7 @@ int start_wormhole() * Well, if we are building with FCGI, we can use this thread * to listen to our pipes */ #ifdef MODULE_FCGI - Frontend::poll_data(pipe_fds); + Frontend::poll_fcgi_pipes(pipe_fds); #endif Logger::instance() << "^D or enter 'q' to stop"; char c;