#include #include #include "../net/adc_endpoint.h" #include "../net/adc_netproto.h" #include "../net/asio/adc_device_netserver_asio.h" int main(int argc, char* argv[]) { /* COMMANDLINE OPTS */ cxxopts::Options options(argv[0], "ADC-library test device network server (ASIO implementation)\n"); options.allow_unrecognised_options(); options.add_options()("h,help", "Print usage"); options.add_options()( "endpoints", "endpoints server will be listening for", cxxopts::value>()->default_value("local://stream/ADC_ASIO_TEST_SERVER")); // cxxopts::value>()->default_value("local://stream/@ADC_ASIO_TEST_SERVER")); options.parse_positional({"endpoints"}); try { auto opt_result = options.parse(argc, argv); if (opt_result["help"].count()) { std::cout << options.help(); return 0; } 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); server.setupSignals(); auto epnt = opt_result["endpoints"].as>(); for (auto& ep : epnt) { adc::AdcEndpointParser epn(ep); if (epn.isValid()) { if (epn.isLocalSeqpacket() || epn.isLocalStream()) { if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace) auto it = std::ranges::find(ep, '@'); *it = '\0'; epn = adc::AdcEndpointParser(ep); } } std::cout << "try to start listenning at '" << ep << "' ..."; server.start>(epn); std::cout << "\tOK\n"; } else { std::cerr << "Unrecognized endpoint: '" << ep << "'! Ignore!\n"; } } io_ctx.run(); } catch (const cxxopts::exceptions::exception& ex) { std::cerr << "\nAn error occured while parsing input options: " << ex.what() << "\n"; return 127; } catch (const std::system_error& ex) { std::cerr << "\nAn error ocured: " << ex.what() << "\n"; std::cerr << "Category: " << ex.code().category().name() << "; message: " << ex.code().message() << "\n"; return 128; } return 0; }