...
This commit is contained in:
68
tests/adc_asio_netserver_test.cpp
Normal file
68
tests/adc_asio_netserver_test.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <cxxopts.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#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<std::vector<std::string>>()->default_value("local://stream/tmp/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;
|
||||
adc::impl::AdcDeviceNetServerASIO server("TEST SRV", io_ctx);
|
||||
server.setupSignals();
|
||||
|
||||
auto epnt = opt_result["endpoints"].as<std::vector<std::string>>();
|
||||
|
||||
for (auto& ep : epnt) {
|
||||
adc::AdcEndpointParser epn(ep);
|
||||
if (epn.isValid()) {
|
||||
if (epn.isLocalSeqpacket() || epn.isLocalStream()) {
|
||||
if (opt_result["abstract"].as<bool>()) {
|
||||
auto s = epn.path<std::span<char>>();
|
||||
if (s[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace)
|
||||
s[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "try to start listenning at '" << ep << "' ...";
|
||||
server.start<adc::AdcStopSeqSessionProto<>>(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";
|
||||
return 128;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user