Merge pull request #2349 from cesanta/isclosing

is_closing -> is_draining
This commit is contained in:
Sergio R. Caprile 2023-08-17 16:52:51 -03:00 committed by GitHub
commit 16bf9101aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 11 deletions

View File

@ -27,7 +27,7 @@ static void cb2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data; // Print HTTP response
MG_INFO(("Fetched:\n%.*s", (int) hm->message.len, hm->message.ptr));
c->is_closing = 1;
c->is_draining = 1;
}
}

View File

@ -43,7 +43,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
// Response is received. Print it
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
printf("%.*s", (int) hm->message.len, hm->message.ptr);
c->is_closing = 1; // Tell mongoose to close this connection
c->is_draining = 1; // Tell mongoose to close this connection
*(bool *) fn_data = true; // Tell event loop to stop
} else if (ev == MG_EV_ERROR) {
*(bool *) fn_data = true; // Error, tell event loop to stop

View File

@ -39,7 +39,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
// Response is received. Print it
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
fwrite(hm->body.ptr, 1, hm->body.len, stdout);
c->is_closing = 1; // Tell mongoose to close this connection
c->is_draining = 1; // Tell mongoose to close this connection
*(bool *) fn_data = true; // Tell event loop to stop
} else if (ev == MG_EV_ERROR) {
*(bool *) fn_data = true; // Error, tell event loop to stop

View File

@ -47,7 +47,7 @@ static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_DEBUG(("Got response (%d) %.*s...", (int) hm->message.len, 12,
hm->message.ptr));
c->is_closing = 1;
c->is_draining = 1;
} else if (ev == MG_EV_CONNECT) {
mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) fn_data));
} else if (ev == MG_EV_CLOSE) {

View File

@ -66,7 +66,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
len = mg_ws_wrap(c, c->send.len - len, WEBSOCKET_OP_BINARY);
} else {
MG_ERROR(("%lu MQTT auth failed, code %d", c->id, mm.ack));
c->is_closing = 1;
c->is_draining = 1;
}
break;
case MQTT_CMD_PUBLISH: {
@ -74,7 +74,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mm.topic.ptr, (int) mm.data.len, mm.data.ptr));
MG_INFO(("RECEIVED %.*s <- %.*s", (int) mm.data.len, mm.data.ptr,
(int) mm.topic.len, mm.topic.ptr));
c->is_closing = 1;
c->is_draining = 1;
break;
}
}

View File

@ -44,7 +44,7 @@ enum {
static void handshake(struct mg_connection *c) {
struct mg_iobuf *r = &c->recv;
if (r->buf[0] != VERSION) {
c->is_closing = 1;
c->is_draining = 1;
} else if (r->len > 2 && (size_t) r->buf[1] + 2 <= r->len) {
/* https://www.ietf.org/rfc/rfc1928.txt paragraph 3 */
uint8_t reply[2] = {VERSION, HANDSHAKE_FAILURE};

View File

@ -181,9 +181,9 @@ static void config_apply(struct mg_str s) {
if (mg_json_get_num(s, "$.tx", &v)) s_state.tx = (int) v;
if (mg_json_get_num(s, "$.baud", &v)) s_state.baud = (int) v;
if (s_state.mqtt.c) s_state.mqtt.c->is_closing = 1;
if (s_state.tcp.c) s_state.tcp.c->is_closing = 1;
if (s_state.websocket.c) s_state.websocket.c->is_closing = 1;
if (s_state.mqtt.c) s_state.mqtt.c->is_draining = 1;
if (s_state.tcp.c) s_state.tcp.c->is_draining = 1;
if (s_state.websocket.c) s_state.websocket.c->is_draining = 1;
}
// HTTP request handler function

View File

@ -48,7 +48,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
// Response is received. Print it
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("%.*s", (int) hm->message.len, hm->message.ptr));
c->is_closing = 1; // Tell mongoose to close this connection
c->is_draining = 1; // Tell mongoose to close this connection
*(bool *) fn_data = true; // Tell event loop to stop
} else if (ev == MG_EV_ERROR) {
*(bool *) fn_data = true; // Error, tell event loop to stop