...
This commit is contained in:
parent
daa756d8c6
commit
f14b4fdc10
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
#include "adc_device_netmsg.h"
|
#include "adc_device_netmsg.h"
|
||||||
@ -219,7 +220,7 @@ public:
|
|||||||
: _ident(),
|
: _ident(),
|
||||||
_netService(std::move(srv)),
|
_netService(std::move(srv)),
|
||||||
_serverPtr(srv_ptr),
|
_serverPtr(srv_ptr),
|
||||||
_bindDevice(_serverPtr->_devices.size() ? _serverPtr->_devices[0] : AdcDeviceNetServer::nullDevice)
|
_bindDevice(srv_ptr->_devices.size() ? srv_ptr->_devices.begin()->second : AdcDeviceNetServer::nullDevice)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_array_v<std::remove_cvref_t<R>>) {
|
if constexpr (std::is_array_v<std::remove_cvref_t<R>>) {
|
||||||
_ident = id;
|
_ident = id;
|
||||||
@ -235,8 +236,10 @@ public:
|
|||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
|
auto self(this->shared_from_this());
|
||||||
|
|
||||||
_netService.asyncReceive(
|
_netService.asyncReceive(
|
||||||
[this](std::error_code ec, message_t msg) {
|
[self, this](std::error_code ec, message_t msg) {
|
||||||
if (ec) {
|
if (ec) {
|
||||||
stop();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
@ -248,7 +251,7 @@ public:
|
|||||||
|
|
||||||
_netService.asyncSend(
|
_netService.asyncSend(
|
||||||
*msg_sptr,
|
*msg_sptr,
|
||||||
[msg_sptr, this](std::error_code ec) {
|
[self, msg_sptr, this](std::error_code ec) {
|
||||||
if (ec) {
|
if (ec) {
|
||||||
stop();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
@ -360,7 +363,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using AdcGenericNetServer::AdcGenericNetServer;
|
// using AdcGenericNetServer::AdcGenericNetServer;
|
||||||
|
template <traits::adc_input_char_range R>
|
||||||
|
AdcDeviceNetServer(const R& id) : AdcGenericNetServer(id), _devices()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~AdcDeviceNetServer() = default;
|
||||||
|
|
||||||
template <interfaces::adc_device_c DeviceT,
|
template <interfaces::adc_device_c DeviceT,
|
||||||
typename IdSerialT = traits::adc_char_identity<typename DeviceT::ident_t>,
|
typename IdSerialT = traits::adc_char_identity<typename DeviceT::ident_t>,
|
||||||
|
|||||||
@ -29,6 +29,10 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
asio::io_context io_ctx;
|
asio::io_context io_ctx;
|
||||||
|
|
||||||
|
asio::signal_set signals(io_ctx, SIGINT, SIGTERM);
|
||||||
|
signals.async_wait([&](std::error_code, int) { io_ctx.stop(); });
|
||||||
|
|
||||||
adc::impl::AdcDeviceNetServerASIO server("TEST SRV", io_ctx);
|
adc::impl::AdcDeviceNetServerASIO server("TEST SRV", io_ctx);
|
||||||
server.setupSignals();
|
server.setupSignals();
|
||||||
|
|
||||||
@ -63,6 +67,7 @@ int main(int argc, char* argv[])
|
|||||||
return 127;
|
return 127;
|
||||||
} catch (const std::system_error& ex) {
|
} catch (const std::system_error& ex) {
|
||||||
std::cerr << "\nAn error ocured: " << ex.what() << "\n";
|
std::cerr << "\nAn error ocured: " << ex.what() << "\n";
|
||||||
|
std::cerr << "Category: " << ex.code().category().name() << "; message: " << ex.code().message() << "\n";
|
||||||
return 128;
|
return 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,14 +21,14 @@ void receive(T srv)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using tr_p_t = asio ::ip::tcp;
|
// using tr_p_t = asio ::ip::tcp;
|
||||||
// using tr_p_t = asio::local::stream_protocol;
|
using tr_p_t = asio::local::stream_protocol;
|
||||||
// using tr_p_t = asio::local::seq_packet_protocol;
|
// using tr_p_t = asio::local::seq_packet_protocol;
|
||||||
|
|
||||||
// tr_p_t::endpoint ept_c(std::string("/tmp/AAA").insert(0, 1, '\0'));
|
tr_p_t::endpoint ept_c(std::string("/tmp/AAA").insert(0, 1, '\0'));
|
||||||
// tr_p_t::endpoint ept_c("/tmp/AAA");
|
// tr_p_t::endpoint ept_c("/tmp/AAA");
|
||||||
|
// tr_p_t::endpoint ept_c(asio::ip::make_address_v4("0.0.0.0"), 9999);
|
||||||
|
|
||||||
tr_p_t::endpoint ept_c(asio::ip::make_address_v4("0.0.0.0"), 9999);
|
|
||||||
std::cout << "ADDR: " << ept_c << "\n";
|
std::cout << "ADDR: " << ept_c << "\n";
|
||||||
|
|
||||||
asio::io_context ctx;
|
asio::io_context ctx;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user