From 2a3492766f5132dafe6ecef417e2772357d66b48 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 21 Dec 2021 17:44:34 +0000 Subject: [PATCH] Remove mg_time() and mg_usleep() --- docs/README.md | 37 ------------------------------------- mongoose.c | 43 +------------------------------------------ mongoose.h | 2 -- src/util.c | 41 ----------------------------------------- src/util.h | 2 -- 5 files changed, 1 insertion(+), 124 deletions(-) diff --git a/docs/README.md b/docs/README.md index b4cd88a5..78b1a422 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1992,24 +1992,6 @@ mg_timer_poll(now); ## Time -### mg\_time() - -``` -double mg_time(void); -``` - -Return current time as UNIX epoch, using `double` value for sub-second accuracy. - -Parameters: None - -Return value: Current time - -Usage example: - -```c -double now = mg_time() -``` - ### mg\_millis() ```c @@ -2028,25 +2010,6 @@ Usage example: unsigned long uptime = mg_millis(); ``` -### mg\_usleep() - -```c -void mg_usleep(unsigned long usecs); -``` - -Block thread execution for a given number of microseconds. - -Parameters: -- `usecs` - number of microseconds to block thread - -Return value: None - -Usage example: - -```c -mg_usleep(1000000 /* 1 sec */) -``` - ## String ### struct mg\_str diff --git a/mongoose.c b/mongoose.c index 39a5b1f4..b5738d64 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4462,47 +4462,6 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) { return allowed == '+'; } -double mg_time(void) { -#if MG_ARCH == MG_ARCH_WIN32 - SYSTEMTIME sysnow; - FILETIME ftime; - GetLocalTime(&sysnow); - SystemTimeToFileTime(&sysnow, &ftime); - /* - * 1. VC 6.0 doesn't support conversion uint64 -> double, so, using int64 - * This should not cause a problems in this (21th) century - * 2. Windows FILETIME is a number of 100-nanosecond intervals since January - * 1, 1601 while time_t is a number of _seconds_ since January 1, 1970 UTC, - * thus, we need to convert to seconds and adjust amount (subtract 11644473600 - * seconds) - */ - return (double) (((int64_t) ftime.dwLowDateTime + - ((int64_t) ftime.dwHighDateTime << 32)) / - 10000000.0) - - 11644473600; -#elif MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS - return mg_millis() / 1000.0; -#else - struct timeval tv; - if (gettimeofday(&tv, NULL /* tz */) != 0) return 0; - return (double) tv.tv_sec + (((double) tv.tv_usec) / 1000000.0); -#endif /* _WIN32 */ -} - -void mg_usleep(unsigned long usecs) { -#if MG_ARCH == MG_ARCH_WIN32 - Sleep(usecs / 1000); -#elif MG_ARCH == MG_ARCH_ESP8266 - ets_delay_us(usecs); -#elif MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_FREERTOS_LWIP - vTaskDelay(pdMS_TO_TICKS(usecs / 1000)); -#elif MG_ARCH == MG_ARCH_AZURERTOS - tx_thread_sleep((usecs / 1000) * TX_TIMER_TICKS_PER_SECOND); -#else - usleep((useconds_t) usecs); -#endif -} - unsigned long mg_millis(void) { #if MG_ARCH == MG_ARCH_WIN32 return GetTickCount(); @@ -4715,7 +4674,7 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, if (final) mg_call(c, MG_EV_WS_MSG, &m); break; case WEBSOCKET_OP_CLOSE: - LOG(LL_ERROR, ("%lu Got WS CLOSE", c->id)); + LOG(LL_DEBUG, ("%lu Got WS CLOSE", c->id)); mg_call(c, MG_EV_WS_CTL, &m); c->is_closing = 1; break; diff --git a/mongoose.h b/mongoose.h index 4c9202eb..ea85e1fc 100644 --- a/mongoose.h +++ b/mongoose.h @@ -615,9 +615,7 @@ int mg_asprintf(char **buf, size_t size, const char *fmt, ...); int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap); int64_t mg_to64(struct mg_str str); int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip); -double mg_time(void); unsigned long mg_millis(void); -void mg_usleep(unsigned long usecs); #define mg_htons(x) mg_ntohs(x) #define mg_htonl(x) mg_ntohl(x) diff --git a/src/util.c b/src/util.c index 8576d987..b0d9fd62 100644 --- a/src/util.c +++ b/src/util.c @@ -301,47 +301,6 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) { return allowed == '+'; } -double mg_time(void) { -#if MG_ARCH == MG_ARCH_WIN32 - SYSTEMTIME sysnow; - FILETIME ftime; - GetLocalTime(&sysnow); - SystemTimeToFileTime(&sysnow, &ftime); - /* - * 1. VC 6.0 doesn't support conversion uint64 -> double, so, using int64 - * This should not cause a problems in this (21th) century - * 2. Windows FILETIME is a number of 100-nanosecond intervals since January - * 1, 1601 while time_t is a number of _seconds_ since January 1, 1970 UTC, - * thus, we need to convert to seconds and adjust amount (subtract 11644473600 - * seconds) - */ - return (double) (((int64_t) ftime.dwLowDateTime + - ((int64_t) ftime.dwHighDateTime << 32)) / - 10000000.0) - - 11644473600; -#elif MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS - return mg_millis() / 1000.0; -#else - struct timeval tv; - if (gettimeofday(&tv, NULL /* tz */) != 0) return 0; - return (double) tv.tv_sec + (((double) tv.tv_usec) / 1000000.0); -#endif /* _WIN32 */ -} - -void mg_usleep(unsigned long usecs) { -#if MG_ARCH == MG_ARCH_WIN32 - Sleep(usecs / 1000); -#elif MG_ARCH == MG_ARCH_ESP8266 - ets_delay_us(usecs); -#elif MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_FREERTOS_LWIP - vTaskDelay(pdMS_TO_TICKS(usecs / 1000)); -#elif MG_ARCH == MG_ARCH_AZURERTOS - tx_thread_sleep((usecs / 1000) * TX_TIMER_TICKS_PER_SECOND); -#else - usleep((useconds_t) usecs); -#endif -} - unsigned long mg_millis(void) { #if MG_ARCH == MG_ARCH_WIN32 return GetTickCount(); diff --git a/src/util.h b/src/util.h index bcd5dbd4..41394fd4 100644 --- a/src/util.h +++ b/src/util.h @@ -20,9 +20,7 @@ int mg_asprintf(char **buf, size_t size, const char *fmt, ...); int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap); int64_t mg_to64(struct mg_str str); int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip); -double mg_time(void); unsigned long mg_millis(void); -void mg_usleep(unsigned long usecs); #define mg_htons(x) mg_ntohs(x) #define mg_htonl(x) mg_ntohl(x)