Skip to content

Commit

Permalink
内部异常时不退出进程自动重连
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Jan 22, 2024
1 parent 9100436 commit 7cd25d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "core/client.h"
#include "core/server.h"
#include "utility/random.h"
#include "utility/time.h"
#include <bit>
#include <condition_variable>
#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion src/utility/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/utility/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7cd25d2

Please sign in to comment.