ADC/tests/adc_netservice_test.cpp
Timur A. Fatkhullin 062c26537d ....
2024-10-23 23:55:40 +03:00

58 lines
1.6 KiB
C++

#include <asio/ip/tcp.hpp>
#include <iostream>
#include "../net/adc_netproto.h"
// #include "../net/asio/adc_netservice_asio.h"
#include "../net/asio/adc_netsrv_asio.h"
template <typename T>
void receive(T srv)
{
srv->asyncReceive(
[srv](std::error_code ec, std::string msg) {
if (!ec) {
std::cout << "Received: [" << msg << "]\n";
receive(std::move(srv));
} else {
std::cout << "Received: " << ec.message() << "\n";
}
},
std::chrono::minutes(1));
}
int main()
{
using tr_p_t = asio ::ip::tcp;
// using tr_p_t = asio::local::stream_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("/tmp/AAA");
tr_p_t::endpoint ept_c(asio::ip::make_address_v4("0.0.0.0"), 9999);
std::cout << "ADDR: " << ept_c << "\n";
asio::io_context ctx;
// using srv_t = adc::impl::AdcNetServiceASIOBase<tr_p_t, adc::AdcStopSeqSessionProto<>>;
using srv_t = adc::impl::AdcNetServiceASIOBase<tr_p_t, adc::AdcStopSeqSessionProto<>>;
typename srv_t::acceptor_t acc(ctx, ept_c);
acc.asyncAccept([](std::error_code ec, auto srv) {
if (!ec) {
auto sptr = std::make_shared<srv_t>(std::move(srv));
receive(sptr);
// receive(std::move(srv));
} else {
std::cout << "ACCEPT ERR: " << ec.message() << "\n";
}
});
ctx.run();
std::cout << "Exit!\n";
return 0;
}