-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (49 loc) · 1.58 KB
/
main.cpp
File metadata and controls
60 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <stdexcept>
#include <boost/program_options.hpp>
#include "server.h"
namespace po = boost::program_options;
using namespace std;
void parse_command_line(int argc, char **argv, po::variables_map& vm)
{
po::options_description desc("Command line");
desc.add_options()
("help", "Print usage information.")
("lp", po::value<unsigned short>(), "The port on which to listen.")
("ra", po::value<string>(), "Address to redirect to.")
("rp", po::value<unsigned short>(), "Port to redirect to.")
("us", po::value<unsigned long>(), "The number of µs to delay each full buffer of data. The network latency will be twice this value.");
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help") || !vm.count("lp") || !vm.count("ra")
|| !vm.count("rp") || !vm.count("us"))
{
cout << desc << "\n";
throw invalid_argument("Missing parameters!");
}
server srv();
}
int main(int argc, char **argv)
{
po::variables_map vm;
try
{
parse_command_line(argc, argv, vm);
}
catch (const exception& e)
{
cout << "Error: " << e.what() << "\n";
return 1;
}
try
{
boost::asio::io_service io_service;
server server(io_service, tcp::endpoint(tcp::v4(), vm["lp"].as<unsigned short>()), vm["ra"].as<string>(), vm["rp"].as<unsigned short>(), vm["us"].as<unsigned long>());
io_service.run();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}