mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
Use int64_t for timers and mg_millis()
This commit is contained in:
1 parent
fb0a9bc7e3
commit
ae6767b1d2
15 files changed
+123
-118
No files matched your search
+2
-3
@@ -27,9 +27,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
mg_mqtt_parse(data, size, &mm);
|
||||
mg_mqtt_parse(NULL, 0, &mm);
|
||||
|
||||
struct timeval tv;
|
||||
mg_sntp_parse(data, size, &tv);
|
||||
mg_sntp_parse(NULL, 0, &tv);
|
||||
mg_sntp_parse(data, size);
|
||||
mg_sntp_parse(NULL, 0);
|
||||
|
||||
char buf[size * 4 / 3 + 5]; // At least 4 chars and nul termination
|
||||
mg_base64_decode((char *) data, (int) size, buf);
|
||||
|
||||
+17
-18
@@ -243,24 +243,24 @@ static void test_iobuf(void) {
|
||||
|
||||
static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
if (ev == MG_EV_SNTP_TIME) {
|
||||
*(struct timeval *) fnd = *(struct timeval *) evd;
|
||||
*(int64_t *) fnd = *(int64_t *) evd;
|
||||
}
|
||||
(void) c;
|
||||
}
|
||||
|
||||
static void test_sntp(void) {
|
||||
struct timeval tv = {0, 0};
|
||||
int64_t ms = 0;
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *c = NULL;
|
||||
int i;
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
c = mg_sntp_connect(&mgr, NULL, sntp_cb, &tv);
|
||||
c = mg_sntp_connect(&mgr, NULL, sntp_cb, &ms);
|
||||
ASSERT(c != NULL);
|
||||
ASSERT(c->is_udp == 1);
|
||||
mg_sntp_send(c, (unsigned long) time(NULL));
|
||||
for (i = 0; i < 300 && tv.tv_sec == 0; i++) mg_mgr_poll(&mgr, 10);
|
||||
ASSERT(tv.tv_sec > 0);
|
||||
for (i = 0; i < 300 && ms == 0; i++) mg_mgr_poll(&mgr, 10);
|
||||
ASSERT(ms > 0);
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
{
|
||||
@@ -274,22 +274,21 @@ static void test_sntp(void) {
|
||||
"\xc9\xd6\xa2\xdb\xde\xea\x30\x91\x86\xb7\x10\xdb\xde"
|
||||
"\xed\x98\x00\x00\x00\xde\xdb\xde\xed\x99\x0a\xe2\xc7"
|
||||
"\x96\xdb\xde\xed\x99\x0a\xe4\x6b\xda";
|
||||
struct timeval tv2 = {0, 0};
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
time_t t;
|
||||
ASSERT(mg_sntp_parse(sntp_good, sizeof(sntp_good), &tv2) == 0);
|
||||
t = tv2.tv_sec;
|
||||
tm = gmtime(&t);
|
||||
ASSERT(tm->tm_year == 116);
|
||||
ASSERT(tm->tm_mon == 10);
|
||||
ASSERT(tm->tm_mday == 22);
|
||||
ASSERT(tm->tm_hour == 16);
|
||||
ASSERT(tm->tm_min == 15);
|
||||
ASSERT(tm->tm_sec == 21);
|
||||
ASSERT(mg_sntp_parse(bad_good, sizeof(bad_good), &tv2) == -1);
|
||||
ASSERT((ms = mg_sntp_parse(sntp_good, sizeof(sntp_good))) > 0);
|
||||
t = (time_t) (ms / 1000);
|
||||
gmtime_r(&t, &tm);
|
||||
ASSERT(tm.tm_year == 116);
|
||||
ASSERT(tm.tm_mon == 10);
|
||||
ASSERT(tm.tm_mday == 22);
|
||||
ASSERT(tm.tm_hour == 16);
|
||||
ASSERT(tm.tm_min == 15);
|
||||
ASSERT(tm.tm_sec == 21);
|
||||
ASSERT(mg_sntp_parse(bad_good, sizeof(bad_good)) < 0);
|
||||
}
|
||||
|
||||
ASSERT(mg_sntp_parse(NULL, 0, &tv) == -1);
|
||||
ASSERT(mg_sntp_parse(NULL, 0) == -1);
|
||||
}
|
||||
|
||||
static void mqtt_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
|
||||
Reference in new issue
Block a user