diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-09-18 11:19:21 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-09-18 11:19:21 +0200 |
| commit | 828de975876f9ad444efda2a36c02922cda3afa6 (patch) | |
| tree | 3b076331dd440ef16365047245b29277f6c146aa | |
| download | use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.gz use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.tar.bz2 use-fastcgi-828de975876f9ad444efda2a36c02922cda3afa6.zip | |
Erster Import
| -rw-r--r-- | .clang-format | 45 | ||||
| -rw-r--r-- | makefile | 4 | ||||
| -rw-r--r-- | server.cpp | 95 |
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 | --- | ||
| 2 | AccessModifierOffset: -4 | ||
| 3 | AlignConsecutiveAssignments: 'true' | ||
| 4 | AlignConsecutiveDeclarations: 'true' | ||
| 5 | AlignEscapedNewlines: Left | ||
| 6 | AlignTrailingComments: 'true' | ||
| 7 | AlwaysBreakAfterReturnType: TopLevelDefinitions | ||
| 8 | BreakBeforeBraces: Stroustrup | ||
| 9 | BreakConstructorInitializers: BeforeComma | ||
| 10 | BreakInheritanceList: BeforeComma | ||
| 11 | ColumnLimit: '0' | ||
| 12 | CompactNamespaces: 'false' | ||
| 13 | Cpp11BracedListStyle: 'false' | ||
| 14 | FixNamespaceComments: 'true' | ||
| 15 | IncludeBlocks: Regroup | ||
| 16 | IncludeCategories: | ||
| 17 | - Regex: '^.*(precomp|pch|stdafx)' | ||
| 18 | Priority: -1 | ||
| 19 | - Regex: '^<.*>' | ||
| 20 | Priority: 1 | ||
| 21 | - Regex: '^".*"' | ||
| 22 | Priority: 2 | ||
| 23 | - Regex: '.*' | ||
| 24 | Priority: 3 | ||
| 25 | IndentCaseLabels: 'false' | ||
| 26 | IndentPPDirectives: AfterHash | ||
| 27 | IndentWidth: '4' | ||
| 28 | IndentWrappedFunctionNames: 'false' | ||
| 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' | ||
| 30 | PointerAlignment: Left | ||
| 31 | SortIncludes: 'true' | ||
| 32 | SpaceAfterCStyleCast: 'true' | ||
| 33 | SpaceAfterTemplateKeyword: 'false' | ||
| 34 | SpaceBeforeAssignmentOperators: 'true' | ||
| 35 | SpaceBeforeParens: ControlStatements | ||
| 36 | SpaceBeforeRangeBasedForLoopColon: 'false' | ||
| 37 | SpaceInEmptyParentheses: 'false' | ||
| 38 | SpacesInAngles: 'false' | ||
| 39 | SpacesInCStyleCastParentheses: 'false' | ||
| 40 | SpacesInConditionalStatement: 'true' | ||
| 41 | SpacesInParentheses: 'false' | ||
| 42 | Standard: Auto | ||
| 43 | TabWidth: '4' | ||
| 44 | UseTab: ForIndentation | ||
| 45 | ... | ||
diff --git a/makefile b/makefile new file mode 100644 index 0000000..9fee06a --- /dev/null +++ b/makefile | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | all: server | ||
| 2 | |||
| 3 | server: 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 | |||
| 10 | using namespace std; | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | static atomic_bool quit; | ||
| 14 | static atomic_bool reload; | ||
| 15 | |||
| 16 | static void | ||
| 17 | handler(int signal) | ||
| 18 | { | ||
| 19 | if ( signal == SIGINT || signal == SIGTERM ) { | ||
| 20 | quit = true; | ||
| 21 | } | ||
| 22 | else if ( signal == SIGHUP ) { | ||
| 23 | reload = true; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | static void | ||
| 28 | init_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 | |||
| 41 | static void | ||
| 42 | load_configuration() | ||
| 43 | { | ||
| 44 | cerr << "Load configuration ...\n"; | ||
| 45 | } | ||
| 46 | |||
| 47 | static void | ||
| 48 | handle_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 | |||
| 55 | int | ||
| 56 | main() | ||
| 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 | } | ||
