diff --git a/tests/udp_server.cc b/tests/udp_server.cc index 82585a17f9..410e3e3d42 100644 --- a/tests/udp_server.cc +++ b/tests/udp_server.cc @@ -2,24 +2,23 @@ * Copyright (C) 2014 Cloudius Systems, Ltd. */ +#include "core/smp.hh" #include "core/app-template.hh" #include "core/future-util.hh" using namespace net; using namespace std::chrono_literals; -class server { +class udp_server { private: udp_channel _chan; timer _stats_timer; uint64_t _n_sent {}; public: - void start() { - ipv4_addr listen_addr{10000}; + void start(uint16_t port) { + ipv4_addr listen_addr{port}; _chan = engine.net().make_udp_channel(listen_addr); - std::cout << "Listening on " << listen_addr << std::endl; - _stats_timer.set_callback([this] { std::cout << "Out: " << _n_sent << " pps" << std::endl; _n_sent = 0; @@ -36,8 +35,20 @@ public: } }; +namespace bpo = boost::program_options; + int main(int ac, char ** av) { - server s; app_template app; - return app.run(ac, av, [&s] { s.start(); }); + app.add_options() + ("port", bpo::value()->default_value(10000), "UDP server port") ; + return app.run(ac, av, [&] { + auto&& config = app.configuration(); + uint16_t port = config["port"].as(); + auto server = new distributed; + server->start().then([server = std::move(server), port] () mutable { + server->invoke_on_all(&udp_server::start, port); + }).then([port] { + std::cout << "Seastar UDP server listening on port " << port << " ...\n"; + }); + }); }