diff --git a/README.md b/README.md index 4fe43d7..e249605 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ _Note: all edges of the vertex are removing._ ### Add edge or update weight #### Request ```Json -{"action": "SetEdge", "from": , "to": , "weight": } +{"action": "AddEdge", "from": , "to": , "weight": } ``` #### Response diff --git a/main.cpp b/main.cpp index cafa4a7..f7ac4e3 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,8 @@ -#include #include #include +#include #include +#include #include #include @@ -13,6 +14,7 @@ namespace net = boost::asio; using tcp = net::ip::tcp; namespace beast = boost::beast; namespace ws = beast::websocket; +namespace po = boost::program_options; void fail(beast::error_code ec, char const* what) { std::cerr << what << ": " << ec.message() << '\n'; @@ -32,9 +34,8 @@ void process(ws::stream& wsock, net::yield_context yield) { std::cout << "request=" << request << '\n'; auto response = p.serve(request); std::cout << "response=" << response << '\n'; - net::const_buffer obuf(response.data(), response.size()); wsock.text(wsock.got_text()); - wsock.async_write(obuf, yield[ec]); + wsock.async_write(net::buffer(response), yield[ec]); if (ec) return fail(ec, "write"); } } @@ -56,9 +57,25 @@ void wait(net::io_context& ioc, } } -int main() { +int main(int argc, char* argv[]) { + unsigned short port{8080}; + + po::options_description args("Using"); + args.add_options() + ("help", "produce help message") + ("port", po::value(&port)->default_value(8080), "port to listen"); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, args), vm); + po::notify(vm); + + if (vm.count("help")) { + std::cout << args << "\n"; + return 1; + } + net::io_context ioc; - tcp::endpoint point{tcp::v6(), 8080}; + tcp::endpoint point{tcp::v6(), port}; net::spawn(ioc, [&ioc, point](auto yield) { wait(ioc, point, yield); });