This commit is contained in:
Timur A. Fatkhullin
2024-09-24 21:51:05 +03:00
parent 02dee70db9
commit 2cf0b1f94c
3 changed files with 60 additions and 32 deletions

View File

@@ -4,6 +4,21 @@
#include "../net/adc_netproto.h"
#include "../net/asio/adc_netservice_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(srv);
} else {
std::cout << "Received: " << ec.message() << "\n";
}
},
std::chrono::minutes(1));
}
int main()
{
asio::ip::tcp::endpoint ept_s(asio::ip::tcp::v4(), 9999);
@@ -17,10 +32,10 @@ int main()
adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>> srv(ctx);
adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>::asio_async_ctx_t srv_ctx;
srv_ctx.accept_comp_token = [](std::error_code ec) {
// adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>::asio_async_ctx_t srv_ctx;
// srv_ctx.accept_comp_token = [](std::error_code ec) {
};
// };
// srv.asyncAccept(ept_s, srv_ctx, std::chrono::seconds(120));
// srv.asyncConnect(ept_c, [](std::error_code ec) {
@@ -38,13 +53,16 @@ int main()
if (!ec) {
std::cout << "New connection\n";
srv.asyncReceive(
[](std::error_code ec, std::string msg) {
if (!ec) {
std::cout << "Received: [" << msg << "]\n";
}
},
std::chrono::minutes(3));
// srv.asyncReceive(
// [](std::error_code ec, std::string msg) {
// if (!ec) {
// std::cout << "Received: [" << msg << "]\n";
// } else {
// std::cout << "Received: " << ec.message() << "\n";
// }
// },
// std::chrono::minutes(1));
receive(srv);
} else {
std::cout << "ACCEPT ERR: " << ec.message() << "\n";
}