Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
#-----------------------------------------------------------------
# The project
#-----------------------------------------------------------------
project (SolidFrame VERSION 12.1)
project (SolidFrame VERSION 12.2)

message("SolidFrame version: ${PROJECT_VERSION} - ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
#-----------------------------------------------------------------
Expand Down Expand Up @@ -58,9 +58,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
#-----------------------------------------------------------------

set(EXTERNAL_DIR "" CACHE PATH "External dependencies directory")
set(FORTIFY "ON" CACHE BOOL "Fortify C++")

message("Install directory: \"${CMAKE_INSTALL_PREFIX}\"")
message("External directory: \"${EXTERNAL_DIR}\"")
message("Fortify: \"${FORTIFY}\"")

list(APPEND CMAKE_PREFIX_PATH ${EXTERNAL_PATH})

Expand Down Expand Up @@ -278,6 +280,37 @@ if(NOT ON_FOUND)
message(FATAL_ERROR "\r\n === Unsupported system - please contact project owner ===\r\n")
endif(NOT ON_FOUND)


if(FORTIFY AND (SOLID_ON_LINUX OR SOLID_ON_FREEBSD OR SOLID_ON_DARWIN))
message("Fortifying C++")
include(CheckCXXSymbolExists)
if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(header version)
else()
set(header ciso646)
endif()

check_cxx_symbol_exists(_LIBCPP_VERSION ${header} LIBCPP)
if(LIBCPP)
# Logic for libc++
endif()

check_cxx_symbol_exists(__GLIBCXX__ ${header} GLIBCXX)
if(GLIBCXX)
# Logic for libstdc++

add_compile_options(
#-fpie -Wl,-pie
#-fpic -shared
"$<$<CONFIG:MAINTAIN>:SHELL: -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:DEBUG>:SHELL: -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:RELEASE>:SHELL: -Wall -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:CUSTOM>:>"
)

endif()
endif()

#-----------------------------------------------------------------
# Find external libraries
#-----------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions JOURNAL.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 20250119
* release 12.2

## 20250109
* improvements and fixes on reflection

## 20250106
* use std::variant in example_threadpool
* TypeToType -> std::type_identity

## 20241214
* mprpc: add support for ConnectionContext::pauseRead and Connection::Context::resumeRead

## 20241210
* aio: stream fix not call doTrySend or doTryRecv after disconnect
* mprpc: do not reset timer on onSend with error if connection already stopping
* mprpc: add support for ConnectionContext::stop() for stopping the connection

## 20241116
* mprpc::Connection fix too many keep alive messages
Expand Down
9 changes: 9 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# SolidFrame Releases

## Version 12.2
* improvements and fixes on reflection
* use std::variant in example_threadpool
* TypeToType -> std::type_identity
* mprpc: add support for ConnectionContext::pauseRead and Connection::Context::resumeRead
* aio: stream fix not call doTrySend or doTryRecv after disconnect
* mprpc: do not reset timer on onSend with error if connection already stopping
* mprpc: add support for ConnectionContext::stop() for stopping the connection

## Version 12.1
* Coverity fixes

Expand Down
4 changes: 4 additions & 0 deletions cmake/check.config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ file (READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/check/pthread_spinlock.cpp" source

CHECK_CXX_SOURCE_COMPILES("${source_code}" SOLID_USE_PTHREAD_SPINLOCK)

file (READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/check/stringstream_view.cpp" source_code)

CHECK_CXX_SOURCE_COMPILES("${source_code}" SOLID_USE_STRINGSTREAM_VIEW)

#TODO:
#set(SOLID_FRAME_AIO_REACTOR_USE_SPINLOCK TRUE)
11 changes: 11 additions & 0 deletions cmake/check/stringstream_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include <sstream>
using namespace std;

int main()
{
ostringstream oss;
oss << "test";
cout << oss.view() << endl;
return 0;
}
8 changes: 6 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ INSTALL_PREFIX=
EXTRA_COMPILE_OPTIONS=
EXTRA_LINK_OPTIONS=
ARCHITECTURE=
FORTIFY="OFF"

#echo "$@"
pass_arg_count=0
Expand Down Expand Up @@ -175,6 +176,9 @@ do
shift
TEST_SITE="$1"
;;
--fortify)
FORTIFY="ON"
;;
*)
HELP="yes"
;;
Expand Down Expand Up @@ -256,7 +260,7 @@ for param in "$@"; do
done
echo

echo -ne "./configure -f $FOLDER_NAME -F \"$FOLDER_PATH\" -b \"$BUILD_TYPE\" -g \"$GENERATOR\" -e \"$EXTERNAL_DIR\" \"$@\" \"$SRC_PATH\"\r\n" > configure.txt
echo -ne "./configure -f $FOLDER_NAME -F \"$FOLDER_PATH\" -b \"$BUILD_TYPE\" -g \"$GENERATOR\" -e \"$EXTERNAL_DIR\" \"$@\" \"$SRC_PATH\" \"$FORTIFY\" \r\n" > configure.txt

if [ "$GENERATOR" = "" ]; then
echo "Using cmake's default generator"
Expand All @@ -272,7 +276,7 @@ else
echo "Using architecture $ARCHITECTURE - ${ARC[@]}"
fi

exec cmake "${GEN[@]}" "${ARC[@]}" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DEXTERNAL_DIR:PATH="$EXTERNAL_DIR" -DEXTRA_COMPILE_OPTIONS:STRING="$EXTRA_COMPILE_OPTIONS" -DEXTRA_LINK_OPTIONS:STRING="$EXTRA_LINK_OPTIONS" -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" "$@" "$SRC_PATH"
exec cmake "${GEN[@]}" "${ARC[@]}" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DEXTERNAL_DIR:PATH="$EXTERNAL_DIR" -DEXTRA_COMPILE_OPTIONS:STRING="$EXTRA_COMPILE_OPTIONS" -DEXTRA_LINK_OPTIONS:STRING="$EXTRA_LINK_OPTIONS" -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" -DFORTIFY:BOOL=$FORTIFY "$@" "$SRC_PATH"

echo "Done!"

Expand Down
128 changes: 114 additions & 14 deletions examples/utility/threadpool/example_threadpool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// example_ThreadPool.cpp
// example_threadpool.cpp
//
// Copyright (c) 2007, 2008, 2018 Valentin Palade (vipalade @ gmail . com)
// Copyright (c) 2007, 2008, 2018, 2025 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
Expand All @@ -9,26 +9,126 @@
//
#include "solid/system/log.hpp"
#include "solid/utility/threadpool.hpp"
#include <cassert>
#include <iostream>
#include <thread>

#include <mutex>
#include <string>
#include <variant>
using namespace std;
using namespace solid;

namespace {
Logger logger{"test"};
} // namespace

struct First {
uint64_t v1_;

First(uint64_t _v)
: v1_(_v)
{
}
};

struct Second {
uint64_t v1_;
uint64_t v2_;

Second(uint64_t _v)
: v1_(_v)
, v2_(_v)
{
}
};

struct Third {
uint64_t v1_;
uint64_t v2_;
uint64_t v3_;

Third(uint64_t _v)
: v1_(_v)
, v2_(_v)
, v3_(_v)
{
}
};

using VariantT = std::variant<string, First, Second, Third, unique_ptr<Third>>;

using ThreadPoolT = ThreadPool<VariantT, size_t>;

struct Context {
mutex mtx_;
};

void handle(First& _rv, Context& _rctx)
{
lock_guard<mutex> lock(_rctx.mtx_);
solid_log(logger, Info, "Handle First");
}

void handle(Second& _rv, Context& _rctx)
{
lock_guard<mutex> lock(_rctx.mtx_);
solid_log(logger, Info, "Handle Second");
}

void handle(Third& _rv, Context& _rctx)
{
lock_guard<mutex> lock(_rctx.mtx_);
solid_log(logger, Info, "Handle Third");
}

void handle(string& _rv, Context& _rctx)
{
lock_guard<mutex> lock(_rctx.mtx_);
solid_log(logger, Info, "Handle string " << _rv);
}

void handle(unique_ptr<Third>& _rv, Context& _rctx)
{
lock_guard<mutex> lock(_rctx.mtx_);
solid_log(logger, Info, "Handle unique_ptr<Third>");
}

int main(int argc, char* argv[])
{
solid::log_start(std::cerr, {".*:VIEW"});
solid::log_start(std::cerr, {".*:EW", "test:VIEW"});

Context ctx;

ThreadPoolT tp{
{4},
[](size_t, Context&) {},
[](size_t, Context&) {},
[](VariantT& _var, Context& _rctx) {
std::visit([&_rctx](auto& _rv) { handle(_rv, _rctx); }, _var);
},
[](size_t, Context&) {

ThreadPool<int, size_t> wp{
{1, 100, 0}, [](const size_t) {}, [](const size_t) {},
[](int _v) {
solid_log(generic_logger, Info, "v = " << _v);
std::this_thread::sleep_for(std::chrono::milliseconds(_v * 10));
},
[](const size_t) {}};
ref(ctx)};

for (int i(0); i < 100; ++i) {
wp.pushOne(i);
for (size_t i = 0; i < 100; ++i) {
switch (i % variant_size_v<VariantT>) {
case 0:
tp.pushOne(to_string(i));
break;
case 1:
tp.pushOne(First(i));
break;
case 2:
tp.pushOne(Second(i));
break;
case 3:
tp.pushOne(Third(i));
break;
case 4:
tp.pushOne(make_unique<Third>(i));
break;
default:
assert(false);
}
}
return 0;
}
2 changes: 1 addition & 1 deletion prerequisites/build
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ printUsage()
echo
}

OPENSSL_ADDR="https://www.openssl.org/source/openssl-3.1.2.tar.gz"
OPENSSL_ADDR="https://github.com/openssl/openssl/releases/download/openssl-3.4.0/openssl-3.4.0.tar.gz"

SYSTEM=
BIT64=
Expand Down
19 changes: 9 additions & 10 deletions solid/frame/aio/aiolistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class Listener : public CompletionHandler {
static void on_posted_accept(ReactorContext& _rctx, EventBase&&);
static void on_dummy(ReactorContext&, SocketDevice&);

typedef solid_function_t(void(ReactorContext&, SocketDevice&)) FunctionT;
FunctionT f_;
SocketBase s_;

public:
Listener(
ActorProxy const& _ract,
SocketDevice&& _rsd)
: CompletionHandler(_ract, Listener::on_init_completion)
, s(std::move(_rsd))
, s_(std::move(_rsd))
{
}

Expand All @@ -55,8 +59,8 @@ class Listener : public CompletionHandler {
template <typename F>
bool postAccept(ReactorContext& _rctx, F&& _f)
{
if (solid_function_empty(f)) {
f = std::forward<F>(_f);
if (solid_function_empty(f_)) {
f_ = std::forward<F>(_f);
doPostAccept(_rctx);
return false;
} else {
Expand All @@ -70,13 +74,13 @@ class Listener : public CompletionHandler {
template <typename F>
bool accept(ReactorContext& _rctx, F&& _f, SocketDevice& _rsd)
{
if (solid_function_empty(f)) {
if (solid_function_empty(f_)) {
contextBind(_rctx);

if (this->doTryAccept(_rctx, _rsd)) {
return true;
}
f = std::forward<F>(_f);
f_ = std::forward<F>(_f);
return false;
} else {
error(_rctx, error_already);
Expand All @@ -89,11 +93,6 @@ class Listener : public CompletionHandler {
bool doTryAccept(ReactorContext& _rctx, SocketDevice& _rsd);
void doAccept(ReactorContext& _rctx, solid::SocketDevice& _rsd);
void doClear(ReactorContext& _rctx);

private:
typedef solid_function_t(void(ReactorContext&, SocketDevice&)) FunctionT;
FunctionT f;
SocketBase s;
};

} // namespace aio
Expand Down
9 changes: 7 additions & 2 deletions solid/frame/aio/aiostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Stream : public CompletionHandler {

void operator()(ThisT& _rthis, ReactorContext& _rctx)
{
if (_rthis.doTryRecv(_rctx)) {
if (_rctx.systemError() || _rthis.doTryRecv(_rctx)) {
const size_t recv_sz = _rthis.recv_buf_sz;
F tmp{std::forward<F>(f)};
_rthis.doClearRecv(_rctx);
Expand All @@ -123,7 +123,7 @@ class Stream : public CompletionHandler {

void operator()(ThisT& _rthis, ReactorContext& _rctx)
{
while (_rthis.doTrySend(_rctx)) {
while (_rctx.systemError() || _rthis.doTrySend(_rctx)) {
if (_rthis.send_buf_sz == _rthis.send_buf_cp) {
F tmp{std::forward<F>(f)};
_rthis.doClearSend(_rctx);
Expand Down Expand Up @@ -412,6 +412,11 @@ class Stream : public CompletionHandler {
return true;
}

void cancelRecv(ReactorContext& _rctx)
{
doClearRecv(_rctx);
}

template <typename F>
bool postSendAll(ReactorContext& _rctx, const char* _buf, size_t _bufcp, F&& _f)
{
Expand Down
Loading
Loading