summaryrefslogtreecommitdiff
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
downloaduse-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.gz
use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.bz2
use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.zip
Erster Import
-rw-r--r--.clang-format45
-rw-r--r--makefile4
-rw-r--r--server.cpp95
3 files changed, 144 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..f045884
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,45 @@
1---
2AccessModifierOffset: -4
3AlignConsecutiveAssignments: 'true'
4AlignConsecutiveDeclarations: 'true'
5AlignEscapedNewlines: Left
6AlignTrailingComments: 'true'
7AlwaysBreakAfterReturnType: TopLevelDefinitions
8BreakBeforeBraces: Stroustrup
9BreakConstructorInitializers: BeforeComma
10BreakInheritanceList: BeforeComma
11ColumnLimit: '0'
12CompactNamespaces: 'false'
13Cpp11BracedListStyle: 'false'
14FixNamespaceComments: 'true'
15IncludeBlocks: Regroup
16IncludeCategories:
17 - Regex: '^.*(precomp|pch|stdafx)'
18 Priority: -1
19 - Regex: '^<.*>'
20 Priority: 1
21 - Regex: '^".*"'
22 Priority: 2
23 - Regex: '.*'
24 Priority: 3
25IndentCaseLabels: 'false'
26IndentPPDirectives: AfterHash
27IndentWidth: '4'
28IndentWrappedFunctionNames: 'false'
29KeepEmptyLinesAtTheStartOfBlocks: 'false'
30PointerAlignment: Left
31SortIncludes: 'true'
32SpaceAfterCStyleCast: 'true'
33SpaceAfterTemplateKeyword: 'false'
34SpaceBeforeAssignmentOperators: 'true'
35SpaceBeforeParens: ControlStatements
36SpaceBeforeRangeBasedForLoopColon: 'false'
37SpaceInEmptyParentheses: 'false'
38SpacesInAngles: 'false'
39SpacesInCStyleCastParentheses: 'false'
40SpacesInConditionalStatement: 'true'
41SpacesInParentheses: 'false'
42Standard: Auto
43TabWidth: '4'
44UseTab: ForIndentation
45...
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..9fee06a
--- /dev/null
+++ b/makefile
@@ -0,0 +1,4 @@
1all: server
2
3server: server.cpp
4 c++ -Wall -std=c++20 -pedantic -O2 -lfcgi -o $@ $<
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}