-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (65 loc) · 2.48 KB
/
main.cpp
File metadata and controls
80 lines (65 loc) · 2.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "server.hpp"
#include <launchdarkly/logging/console_backend.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/beast.hpp>
#include <boost/lexical_cast.hpp>
#include <memory>
namespace net = boost::asio;
namespace beast = boost::beast;
using launchdarkly::logging::ConsoleBackend;
using launchdarkly::LogLevel;
int main(int argc, char* argv[]) {
launchdarkly::Logger logger{
std::make_unique<ConsoleBackend>("server-contract-tests")};
std::string const default_port = "8123";
std::string port = default_port;
if (argc == 2) {
port =
argv[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
try {
net::io_context ioc{1};
auto const p = boost::lexical_cast<unsigned short>(port);
server srv{ioc, "0.0.0.0", p, logger};
srv.add_capability("server-side");
srv.add_capability("strongly-typed");
srv.add_capability("context-type");
srv.add_capability("service-endpoints");
srv.add_capability("tags");
srv.add_capability("server-side-polling");
srv.add_capability("inline-context-all");
srv.add_capability("anonymous-redaction");
srv.add_capability("tls:verify-peer");
srv.add_capability("tls:skip-verify-peer");
srv.add_capability("tls:custom-ca");
srv.add_capability("filtering");
srv.add_capability("filtering-strict");
srv.add_capability("client-prereq-events");
srv.add_capability("evaluation-hooks");
srv.add_capability("track-hooks");
srv.add_capability("wrapper");
#ifdef LD_REDIS_SUPPORT_ENABLED
srv.add_capability("persistent-data-store-redis");
#endif
net::signal_set signals{ioc, SIGINT, SIGTERM};
boost::asio::spawn(ioc.get_executor(), [&](auto yield) mutable {
signals.async_wait(yield);
LD_LOG(logger, LogLevel::kInfo) << "shutting down..";
srv.shutdown();
});
ioc.run();
LD_LOG(logger, LogLevel::kInfo) << "bye!";
} catch (boost::bad_lexical_cast&) {
LD_LOG(logger, LogLevel::kError)
<< "invalid port (" << port
<< "), provide a number (no arguments defaults "
"to port "
<< default_port << ")";
return EXIT_FAILURE;
} catch (std::exception const& e) {
LD_LOG(logger, LogLevel::kError) << e.what();
return EXIT_FAILURE;
}
}