summaryrefslogtreecommitdiff
path: root/server.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2026-09-18 11:19:21 +0200
committerThomas Schmucker <ts@its1.de>2026-09-18 11:19:21 +0200
commit828de975876f9ad444efda2a36c02922cda3afa6 (patch)
tree3b076331dd440ef16365047245b29277f6c146aa /server.cpp
downloaduse-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.gz
use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.bz2
use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.zip
Erster Import
Diffstat (limited to 'server.cpp')
-rw-r--r--server.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/server.cpp b/server.cpp
new file mode 100644
index 0000000..a454b68
--- /dev/null
+++ b/server.cpp
@@ -0,0 +1,95 @@
1// Standard C++
2#include <atomic>
3#include <csignal>
4#include <cstdlib>
5#include <iostream>
6
7// FastCGI
8#include <fcgiapp.h>
9
10using namespace std;
11
12namespace {
13static atomic_bool quit;
14static atomic_bool reload;
15
16static void
17handler(int signal)
18{
19 if ( signal == SIGINT || signal == SIGTERM ) {
20 quit = true;
21 }
22 else if ( signal == SIGHUP ) {
23 reload = true;
24 }
25}
26
27static void
28init_signal_handler()
29{
30 struct sigaction sa;
31 memset(&sa, 0, sizeof sa);
32 sa.sa_handler = handler;
33 sa.sa_flags = 0;
34 sigemptyset(&sa.sa_mask);
35
36 sigaction(SIGINT, &sa, NULL);
37 sigaction(SIGTERM, &sa, NULL);
38 sigaction(SIGHUP, &sa, NULL);
39}
40
41static void
42load_configuration()
43{
44 cerr << "Load configuration ...\n";
45}
46
47static void
48handle_request(const FCGX_Request& request)
49{
50 FCGX_FPrintF(request.out, "Content-type: text/html\r\n\r\n");
51 FCGX_FPrintF(request.out, "<h1>Verbindung erfolgreich verarbeitet!</h1>");
52}
53} // namespace
54
55int
56main()
57{
58 FCGX_Init();
59
60 auto socket = FCGX_OpenSocket(":5000", 20);
61 if ( socket == -1 ) {
62 cerr << "Fehler beim Erstellen des Listen-Sockets...\n";
63 return EXIT_FAILURE;
64 }
65
66 FCGX_Request request;
67 if ( FCGX_InitRequest(&request, socket, FCGI_FAIL_ACCEPT_ON_INTR) != 0 ) {
68 cerr << "Fehler beim Initialisieren...\n";
69 return EXIT_FAILURE;
70 }
71
72 init_signal_handler();
73 load_configuration();
74
75 quit = false;
76 reload = false;
77
78 cout << "Handle Requests...\n";
79
80 while ( !quit ) {
81 if ( reload ) {
82 load_configuration();
83 reload = false;
84 }
85
86 if ( FCGX_Accept_r(&request) < 0 ) {
87 continue;
88 }
89
90 handle_request(request);
91
92 FCGX_Finish_r(&request);
93 }
94 cout << "shutdown...\n";
95}