Poll FCGI pipe
FossilOrigin-Name: e6f1941104217eac4ac093595e99a084651e7284b1095bd2fd6ab79b21ac90b0
This commit is contained in:
parent
ecc0d91cb5
commit
117b55c51a
4 changed files with 26 additions and 5 deletions
|
@ -19,11 +19,16 @@
|
|||
#include <iostream>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
#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<int, 2> data)
|
||||
void Frontend::poll_fcgi_pipes(std::array<int, 2> 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<int, 2> Frontend::fork_fcgi_process()
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Route
|
|||
namespace Frontend
|
||||
{
|
||||
void init_fcgi(HTTP::Server* server);
|
||||
void poll_data(std::array<int, 2> data);
|
||||
void poll_fcgi_pipes(std::array<int, 2> data);
|
||||
|
||||
std::array<int, 2> fork_fcgi_process();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <microhttpd.h>
|
||||
#include <cerrno>
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue