...
This commit is contained in:
parent
285f8de1f7
commit
221f595bcb
@ -53,6 +53,7 @@ set(ADC_NETWORK_HEADERS
|
|||||||
# net/adc_netservice.h
|
# net/adc_netservice.h
|
||||||
net/adc_endpoint.h
|
net/adc_endpoint.h
|
||||||
net/adc_netserver.h
|
net/adc_netserver.h
|
||||||
|
net/adc_netclient.h
|
||||||
net/adc_net_concepts.h
|
net/adc_net_concepts.h
|
||||||
net/adc_device_netmsg.h
|
net/adc_device_netmsg.h
|
||||||
net/adc_device_netserver.h
|
net/adc_device_netserver.h
|
||||||
@ -199,8 +200,12 @@ if (BUILD_TESTS)
|
|||||||
# add_test(VALUE_HOLDER ${VALUEHOLDER_TEST_APP})
|
# add_test(VALUE_HOLDER ${VALUEHOLDER_TEST_APP})
|
||||||
add_test(VALUE_HOLDER ${DEVATTR_TEST_APP})
|
add_test(VALUE_HOLDER ${DEVATTR_TEST_APP})
|
||||||
add_test(NETMSG_TEST ${NETMSG_TEST_APP})
|
add_test(NETMSG_TEST ${NETMSG_TEST_APP})
|
||||||
|
|
||||||
add_test(ASIO_NETSRV_TEST ${ASIO_NETSERVER_TEST_APP})
|
add_test(ASIO_NETSRV_TEST ${ASIO_NETSERVER_TEST_APP})
|
||||||
target_link_libraries(${ASIO_NETSERVER_TEST_APP} PRIVATE fmt::fmt)
|
if (SPDLOG_LIBRARY)
|
||||||
|
target_link_libraries(${ASIO_NETSERVER_TEST_APP} PRIVATE fmt::fmt)
|
||||||
|
endif()
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
endif(BUILD_TESTS)
|
endif(BUILD_TESTS)
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace adc
|
|||||||
|
|
||||||
/* SPDLOG-library based advanced single/multithreaded logger */
|
/* SPDLOG-library based advanced single/multithreaded logger */
|
||||||
|
|
||||||
class AdcSPDLOGLogger
|
class AdcSpdlogLogger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// [year-month-day time.millisecs][log-level]: log-message
|
// [year-month-day time.millisecs][log-level]: log-message
|
||||||
@ -25,7 +25,7 @@ public:
|
|||||||
typedef spdlog::level::level_enum loglevel_t;
|
typedef spdlog::level::level_enum loglevel_t;
|
||||||
|
|
||||||
template <traits::adc_input_char_range R = decltype(LOGGER_DEFAULT_FORMAT)>
|
template <traits::adc_input_char_range R = decltype(LOGGER_DEFAULT_FORMAT)>
|
||||||
AdcSPDLOGLogger(std::shared_ptr<spdlog::logger> logger, const R& pattern = LOGGER_DEFAULT_FORMAT)
|
AdcSpdlogLogger(std::shared_ptr<spdlog::logger> logger, const R& pattern = LOGGER_DEFAULT_FORMAT)
|
||||||
: _loggerSPtr(logger), _currentLogPattern()
|
: _loggerSPtr(logger), _currentLogPattern()
|
||||||
{
|
{
|
||||||
std::ranges::copy(pattern, std::back_inserter(_currentLogPattern));
|
std::ranges::copy(pattern, std::back_inserter(_currentLogPattern));
|
||||||
@ -33,7 +33,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~AdcSPDLOGLogger() = default;
|
virtual ~AdcSpdlogLogger() = default;
|
||||||
|
|
||||||
|
|
||||||
void setLogLevel(loglevel_t log_level)
|
void setLogLevel(loglevel_t log_level)
|
||||||
@ -144,6 +144,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
template <typename BaseT>
|
template <typename BaseT>
|
||||||
class AdcSpdlogGenericDecorator : public BaseT
|
class AdcSpdlogGenericDecorator : public BaseT
|
||||||
@ -285,7 +286,6 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename BaseT>
|
template <typename BaseT>
|
||||||
class AdcSpdlogGenericMarkDecorator : public AdcSpdlogGenericDecorator<BaseT>
|
class AdcSpdlogGenericMarkDecorator : public AdcSpdlogGenericDecorator<BaseT>
|
||||||
{
|
{
|
||||||
@ -317,7 +317,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
} // namespace adc
|
} // namespace adc
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,7 +10,6 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <thread>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#if __has_include(<unistd.h>) // POSIX
|
#if __has_include(<unistd.h>) // POSIX
|
||||||
@ -52,8 +51,6 @@ public:
|
|||||||
tmp_path = std::filesystem::current_path().root_path();
|
tmp_path = std::filesystem::current_path().root_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ioContext.notify_fork(asio::execution_context::fork_prepare);
|
|
||||||
|
|
||||||
if (pid_t pid = fork()) {
|
if (pid_t pid = fork()) {
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -82,7 +79,6 @@ public:
|
|||||||
close(1);
|
close(1);
|
||||||
close(2);
|
close(2);
|
||||||
|
|
||||||
// _ioContext.notify_fork(asio::io_context::fork_child);
|
|
||||||
#endif
|
#endif
|
||||||
daemonizeFinalize();
|
daemonizeFinalize();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,7 +106,7 @@ public:
|
|||||||
std::vector<std::string> vsg;
|
std::vector<std::string> vsg;
|
||||||
|
|
||||||
std::ranges::transform(sig_range, std::back_inserter(vsg),
|
std::ranges::transform(sig_range, std::back_inserter(vsg),
|
||||||
[](auto s) { return std::format("'{}'", sigdescr_np(s)); });
|
[](auto s) { return std::format("'{}' (No = {})", sigdescr_np(s), s); });
|
||||||
|
|
||||||
utils::AdcJoinRange(vsg, std::string_view(", "), sgs);
|
utils::AdcJoinRange(vsg, std::string_view(", "), sgs);
|
||||||
#else
|
#else
|
||||||
@ -184,7 +184,8 @@ protected:
|
|||||||
virtual void signalReceived(std::error_code ec, int signo)
|
virtual void signalReceived(std::error_code ec, int signo)
|
||||||
{
|
{
|
||||||
#ifdef _GNU_SOURCE
|
#ifdef _GNU_SOURCE
|
||||||
this->logInfo("The server received the signal: '{}' (ec = {})", sigdescr_np(signo), ec.message());
|
this->logInfo("The server received the signal: '{}' (No = {}, ec = {})", sigdescr_np(signo), signo,
|
||||||
|
ec.message());
|
||||||
#else
|
#else
|
||||||
this->logInfo("The server received the signal: {} (ec = {})", signo, ec.message());
|
this->logInfo("The server received the signal: {} (ec = {})", signo, ec.message());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -259,6 +259,8 @@ public:
|
|||||||
timer->cancel();
|
timer->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srv->_socket.set_option(asio::socket_base::keep_alive(true));
|
||||||
|
|
||||||
self.complete(ec, std::move(*srv));
|
self.complete(ec, std::move(*srv));
|
||||||
|
|
||||||
srv.reset();
|
srv.reset();
|
||||||
@ -574,7 +576,7 @@ public:
|
|||||||
|
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
if (do_read) {
|
if (do_read) {
|
||||||
do_read = false;
|
// do_read = false;
|
||||||
if (_receiveQueue.size()) { // return message from queue
|
if (_receiveQueue.size()) { // return message from queue
|
||||||
timer->cancel();
|
timer->cancel();
|
||||||
auto imsg = _receiveQueue.front();
|
auto imsg = _receiveQueue.front();
|
||||||
@ -593,6 +595,8 @@ public:
|
|||||||
}
|
}
|
||||||
auto buff = _streamBuffer.prepare(n_avail ? n_avail : 1);
|
auto buff = _streamBuffer.prepare(n_avail ? n_avail : 1);
|
||||||
|
|
||||||
|
do_read = false;
|
||||||
|
|
||||||
if constexpr (isTLS) {
|
if constexpr (isTLS) {
|
||||||
return asio::async_read(_sessSocket, std::move(buff), asio::transfer_at_least(1),
|
return asio::async_read(_sessSocket, std::move(buff), asio::transfer_at_least(1),
|
||||||
std::move(self));
|
std::move(self));
|
||||||
@ -638,8 +642,9 @@ public:
|
|||||||
auto net_pack = this->search(std::span(start_ptr, _streamBuffer.size()));
|
auto net_pack = this->search(std::span(start_ptr, _streamBuffer.size()));
|
||||||
if (net_pack.empty()) {
|
if (net_pack.empty()) {
|
||||||
do_read = true;
|
do_read = true;
|
||||||
asio::post(std::move(self)); // initiate consequence socket's read operation
|
return _socket.async_wait(asio::ip::tcp::socket::wait_read, std::move(self));
|
||||||
return;
|
// asio::post(std::move(self)); // initiate consequence socket's read operation
|
||||||
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
timer->cancel(); // there were no errors in the asynchronous read-operation, so stop timer
|
timer->cancel(); // there were no errors in the asynchronous read-operation, so stop timer
|
||||||
|
|||||||
@ -137,7 +137,7 @@ int main(int argc, char* argv[])
|
|||||||
asio::signal_set signals(io_ctx, SIGINT, SIGTERM);
|
asio::signal_set signals(io_ctx, SIGINT, SIGTERM);
|
||||||
signals.async_wait([&](std::error_code, int) { io_ctx.stop(); });
|
signals.async_wait([&](std::error_code, int) { io_ctx.stop(); });
|
||||||
|
|
||||||
using server_t = adc::impl::AdcDeviceNetServerASIO<std::string, adc::AdcSPDLOGLogger>;
|
using server_t = adc::impl::AdcDeviceNetServerASIO<std::string, adc::AdcSpdlogLogger>;
|
||||||
std::shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("console");
|
std::shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("console");
|
||||||
logger->set_level(spdlog::level::debug);
|
logger->set_level(spdlog::level::debug);
|
||||||
// server_t server("TEST SRV", io_ctx, logger, "[%Y-%m-%d %T.%e][%l]: %v");
|
// server_t server("TEST SRV", io_ctx, logger, "[%Y-%m-%d %T.%e][%l]: %v");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user