Remove mg_time() and mg_usleep()

This commit is contained in:
Sergey Lyubka 2021-12-21 17:44:34 +00:00
parent 2ec7e5653e
commit 2a3492766f
5 changed files with 1 additions and 124 deletions

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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();

View File

@ -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)