Unbreak test

This commit is contained in:
cpq committed 2022-10-28 15:35:40 +01:00
1 parent 610e32714c
commit bbc0c0df94
8 files changed
+64 -63

No files matched your search

+30 -29
View File
@@ -1349,6 +1349,7 @@ struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close, p_read,
// Chunk deletion marker is the MSB in the "processed" counter
#define MG_DMARK ((size_t) 1 << (sizeof(size_t) * 8 - 1))
@@ -2237,7 +2238,7 @@ static void deliver_chunked_chunks(struct mg_connection *c, size_t hlen,
ofs += pl + dl + 2, del += pl + 2; // 2 is for \r\n suffix
processed += dl;
if (c->recv.len != saved) processed -= dl, buf -= dl;
//mg_hexdump(c->recv.buf, hlen + processed);
// mg_hexdump(c->recv.buf, hlen + processed);
last = (dl == 0);
}
mg_iobuf_del(&c->recv, hlen + processed, del);
@@ -2310,6 +2311,34 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
(void) evd, (void) fnd;
}
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/quit")) {
mg_http_reply(c, 200, "", "ok\n");
c->is_draining = 1;
c->label[0] = 'X';
} else if (mg_http_match_uri(hm, "/debug")) {
int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
} else {
mg_http_reply(c, 200, "", "hi\n");
}
} else if (ev == MG_EV_CLOSE) {
if (c->label[0] == 'X') *(bool *) fnd = true;
}
}
void mg_hello(const char *url) {
struct mg_mgr mgr;
bool done = false;
mg_mgr_init(&mgr);
if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true;
while (done == false) mg_mgr_poll(&mgr, 100);
mg_mgr_free(&mgr);
}
struct mg_connection *mg_http_connect(struct mg_mgr *mgr, const char *url,
mg_event_handler_t fn, void *fn_data) {
struct mg_connection *c = mg_connect(mgr, url, fn, fn_data);
@@ -3488,34 +3517,6 @@ struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
return t;
}
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/quit")) {
mg_http_reply(c, 200, "", "ok\n");
c->is_draining = 1;
c->label[0] = 'X';
} else if (mg_http_match_uri(hm, "/debug")) {
int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
} else {
mg_http_reply(c, 200, "", "hi\n");
}
} else if (ev == MG_EV_CLOSE) {
if (c->label[0] == 'X') *(bool *) fnd = true;
}
}
void mg_hello(const char *url) {
struct mg_mgr mgr;
bool done = false;
mg_mgr_init(&mgr);
if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true;
while (done == false) mg_mgr_poll(&mgr, 100);
mg_mgr_free(&mgr);
}
void mg_mgr_free(struct mg_mgr *mgr) {
struct mg_connection *c;
struct mg_timer *tmp, *t = mgr->timers;