From 828de975876f9ad444efda2a36c02922cda3afa6 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Fri, 18 Sep 2026 11:19:21 +0200 Subject: Erster Import --- .clang-format | 45 ++++++++++++++++++++++++++++ makefile | 4 +++ server.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 .clang-format create mode 100644 makefile create mode 100644 server.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f045884 --- /dev/null +++ b/.clang-format @@ -0,0 +1,45 @@ +--- +AccessModifierOffset: -4 +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: Left +AlignTrailingComments: 'true' +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBraces: Stroustrup +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +ColumnLimit: '0' +CompactNamespaces: 'false' +Cpp11BracedListStyle: 'false' +FixNamespaceComments: 'true' +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^.*(precomp|pch|stdafx)' + Priority: -1 + - Regex: '^<.*>' + Priority: 1 + - Regex: '^".*"' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: 'false' +IndentPPDirectives: AfterHash +IndentWidth: '4' +IndentWrappedFunctionNames: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +PointerAlignment: Left +SortIncludes: 'true' +SpaceAfterCStyleCast: 'true' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'false' +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInConditionalStatement: 'true' +SpacesInParentheses: 'false' +Standard: Auto +TabWidth: '4' +UseTab: ForIndentation +... diff --git a/makefile b/makefile new file mode 100644 index 0000000..9fee06a --- /dev/null +++ b/makefile @@ -0,0 +1,4 @@ +all: server + +server: server.cpp + 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 @@ +// 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"; +} -- cgit v1.3