diff --git a/src/main/main.cc b/src/main/main.cc index 626d25db..457b7f25 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -2,6 +2,8 @@ #include "core/client.h" #include "core/server.h" #include "utility/random.h" +#include "utility/time.h" +#include #include #include #include @@ -240,15 +242,13 @@ void shutdown() { } } // namespace Candy -int main(int argc, char *argv[]) { +namespace { +int run(struct arguments &arguments) { netStartup(); Candy::Server server; Candy::Client client; - struct arguments arguments; - argp_parse(&config, argc, argv, 0, 0, &arguments); - if (arguments.mode == "server") { server.setPassword(arguments.password); server.setWebSocketServer(arguments.websocket); @@ -282,10 +282,24 @@ int main(int argc, char *argv[]) { if (exitCode == 0) { spdlog::info("service exit: normal"); } else { - spdlog::warn("service exit: internal exception"); + spdlog::info("service exit: internal exception"); } netCleanup(); - return exitCode; } +} // namespace + +int main(int argc, char *argv[]) { + struct arguments arguments; + argp_parse(&config, argc, argv, 0, 0, &arguments); + + while (run(arguments)) { + exitCode = 0; + running = true; + Candy::Time::reset(); + std::this_thread::sleep_for(std::chrono::seconds(3)); + } + + return 0; +} diff --git a/src/utility/time.cc b/src/utility/time.cc index b63175a9..51d13c16 100644 --- a/src/utility/time.cc +++ b/src/utility/time.cc @@ -206,7 +206,11 @@ static int64_t ntpTime() { namespace Candy { -bool Time::useSystemTime = false; +bool Time::useSystemTime; + +void Time::reset() { + useSystemTime = false; +} int64_t Time::unixTime() { using namespace std::chrono; diff --git a/src/utility/time.h b/src/utility/time.h index 8913923e..6c0cb4a2 100644 --- a/src/utility/time.h +++ b/src/utility/time.h @@ -8,6 +8,7 @@ namespace Candy { class Time { public: + static void reset(); static int64_t unixTime(); static int64_t hostToNet(int64_t host); static int64_t netToHost(int64_t net);