diff --git a/skynet-src/skynet_server.c b/skynet-src/skynet_server.c index 0bac4631..5d7210c9 100644 --- a/skynet-src/skynet_server.c +++ b/skynet-src/skynet_server.c @@ -356,6 +356,12 @@ skynet_command(struct skynet_context * context, const char * cmd , const char * return NULL; } + if (strcmp(cmd,"STARTTIME") == 0) { + uint32_t sec = skynet_gettime_fixsec(); + sprintf(context->result,"%u",sec); + return context->result; + } + return NULL; } diff --git a/skynet-src/skynet_timer.c b/skynet-src/skynet_timer.c index 4ab635a2..72e0fd8c 100644 --- a/skynet-src/skynet_timer.c +++ b/skynet-src/skynet_timer.c @@ -38,6 +38,7 @@ struct timer { int lock; int time; uint32_t current; + uint32_t starttime; }; static struct timer * TI = NULL; @@ -217,6 +218,11 @@ skynet_updatetime(void) { } } +uint32_t +skynet_gettime_fixsec(void) { + return TI->starttime; +} + uint32_t skynet_gettime(void) { return TI->current; @@ -226,4 +232,8 @@ void skynet_timer_init(void) { TI = timer_create_timer(); TI->current = _gettime(); + + struct timespec ti; + clock_gettime(CLOCK_MONOTONIC, &ti); + TI->starttime = (uint32_t)(ti.tv_sec & 0xff000000); } diff --git a/skynet-src/skynet_timer.h b/skynet-src/skynet_timer.h index b9f085c8..3df0328b 100644 --- a/skynet-src/skynet_timer.h +++ b/skynet-src/skynet_timer.h @@ -8,6 +8,7 @@ int skynet_timeout(uint32_t handle, int time, int session); void skynet_updatetime(void); uint32_t skynet_gettime(void); +uint32_t skynet_gettime_fixsec(void); void skynet_timer_init(void);