// Standard C++ #include #include #include #include // FastCGI #include using namespace std; namespace { static atomic_bool quit; static atomic_bool reload; static void handler(int signal) { if ( signal == SIGINT || signal == SIGTERM ) { quit = true; } else if ( signal == SIGHUP ) { reload = true; } } static void init_signal_handler() { struct sigaction sa; memset(&sa, 0, sizeof sa); sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); } static void load_configuration() { cerr << "Load configuration ...\n"; } static void handle_request(const FCGX_Request& request) { FCGX_FPrintF(request.out, "Content-type: text/html\r\n\r\n"); FCGX_FPrintF(request.out, "

Verbindung erfolgreich verarbeitet!

"); } } // namespace int main() { FCGX_Init(); auto socket = FCGX_OpenSocket(":5000", 20); if ( socket == -1 ) { cerr << "Fehler beim Erstellen des Listen-Sockets...\n"; return EXIT_FAILURE; } FCGX_Request request; if ( FCGX_InitRequest(&request, socket, FCGI_FAIL_ACCEPT_ON_INTR) != 0 ) { cerr << "Fehler beim Initialisieren...\n"; return EXIT_FAILURE; } init_signal_handler(); load_configuration(); quit = false; reload = false; cout << "Handle Requests...\n"; while ( !quit ) { if ( reload ) { load_configuration(); reload = false; } if ( FCGX_Accept_r(&request) < 0 ) { continue; } handle_request(request); FCGX_Finish_r(&request); } cout << "shutdown...\n"; }