Skip to content

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bonewell committed May 25, 2020
2 parents b58b439 + 1bfcac3 commit ebb1dba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ _Note: all edges of the vertex are removing._
### Add edge or update weight
#### Request
```Json
{"action": "SetEdge", "from": <Number>, "to": <Number>, "weight": <Number>}
{"action": "AddEdge", "from": <Number>, "to": <Number>, "weight": <Number>}
```

#### Response
Expand Down
27 changes: 22 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <boost/beast.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/beast.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/program_options.hpp>

#include <functional>
#include <iostream>
Expand All @@ -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';
Expand All @@ -32,9 +34,8 @@ void process(ws::stream<beast::tcp_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");
}
}
Expand All @@ -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<unsigned short>(&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);
});
Expand Down

0 comments on commit ebb1dba

Please sign in to comment.