mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-31 01:13:01 +08:00
Merge pull request #2349 from cesanta/isclosing
is_closing -> is_draining
This commit is contained in:
commit
16bf9101aa
@ -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) {
|
} else if (ev == MG_EV_HTTP_MSG) {
|
||||||
struct mg_http_message *hm = ev_data; // Print HTTP response
|
struct mg_http_message *hm = ev_data; // Print HTTP response
|
||||||
MG_INFO(("Fetched:\n%.*s", (int) hm->message.len, hm->message.ptr));
|
MG_INFO(("Fetched:\n%.*s", (int) hm->message.len, hm->message.ptr));
|
||||||
c->is_closing = 1;
|
c->is_draining = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
// Response is received. Print it
|
// Response is received. Print it
|
||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
printf("%.*s", (int) hm->message.len, hm->message.ptr);
|
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
|
*(bool *) fn_data = true; // Tell event loop to stop
|
||||||
} else if (ev == MG_EV_ERROR) {
|
} else if (ev == MG_EV_ERROR) {
|
||||||
*(bool *) fn_data = true; // Error, tell event loop to stop
|
*(bool *) fn_data = true; // Error, tell event loop to stop
|
||||||
|
@ -39,7 +39,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
// Response is received. Print it
|
// Response is received. Print it
|
||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
fwrite(hm->body.ptr, 1, hm->body.len, stdout);
|
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
|
*(bool *) fn_data = true; // Tell event loop to stop
|
||||||
} else if (ev == MG_EV_ERROR) {
|
} else if (ev == MG_EV_ERROR) {
|
||||||
*(bool *) fn_data = true; // Error, tell event loop to stop
|
*(bool *) fn_data = true; // Error, tell event loop to stop
|
||||||
|
@ -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;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
MG_DEBUG(("Got response (%d) %.*s...", (int) hm->message.len, 12,
|
MG_DEBUG(("Got response (%d) %.*s...", (int) hm->message.len, 12,
|
||||||
hm->message.ptr));
|
hm->message.ptr));
|
||||||
c->is_closing = 1;
|
c->is_draining = 1;
|
||||||
} else if (ev == MG_EV_CONNECT) {
|
} else if (ev == MG_EV_CONNECT) {
|
||||||
mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) fn_data));
|
mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) fn_data));
|
||||||
} else if (ev == MG_EV_CLOSE) {
|
} else if (ev == MG_EV_CLOSE) {
|
||||||
|
@ -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);
|
len = mg_ws_wrap(c, c->send.len - len, WEBSOCKET_OP_BINARY);
|
||||||
} else {
|
} else {
|
||||||
MG_ERROR(("%lu MQTT auth failed, code %d", c->id, mm.ack));
|
MG_ERROR(("%lu MQTT auth failed, code %d", c->id, mm.ack));
|
||||||
c->is_closing = 1;
|
c->is_draining = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MQTT_CMD_PUBLISH: {
|
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));
|
mm.topic.ptr, (int) mm.data.len, mm.data.ptr));
|
||||||
MG_INFO(("RECEIVED %.*s <- %.*s", (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));
|
(int) mm.topic.len, mm.topic.ptr));
|
||||||
c->is_closing = 1;
|
c->is_draining = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ enum {
|
|||||||
static void handshake(struct mg_connection *c) {
|
static void handshake(struct mg_connection *c) {
|
||||||
struct mg_iobuf *r = &c->recv;
|
struct mg_iobuf *r = &c->recv;
|
||||||
if (r->buf[0] != VERSION) {
|
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) {
|
} else if (r->len > 2 && (size_t) r->buf[1] + 2 <= r->len) {
|
||||||
/* https://www.ietf.org/rfc/rfc1928.txt paragraph 3 */
|
/* https://www.ietf.org/rfc/rfc1928.txt paragraph 3 */
|
||||||
uint8_t reply[2] = {VERSION, HANDSHAKE_FAILURE};
|
uint8_t reply[2] = {VERSION, HANDSHAKE_FAILURE};
|
||||||
|
@ -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, "$.tx", &v)) s_state.tx = (int) v;
|
||||||
if (mg_json_get_num(s, "$.baud", &v)) s_state.baud = (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.mqtt.c) s_state.mqtt.c->is_draining = 1;
|
||||||
if (s_state.tcp.c) s_state.tcp.c->is_closing = 1;
|
if (s_state.tcp.c) s_state.tcp.c->is_draining = 1;
|
||||||
if (s_state.websocket.c) s_state.websocket.c->is_closing = 1;
|
if (s_state.websocket.c) s_state.websocket.c->is_draining = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP request handler function
|
// HTTP request handler function
|
||||||
|
@ -48,7 +48,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
// Response is received. Print it
|
// Response is received. Print it
|
||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||||
MG_INFO(("%.*s", (int) hm->message.len, hm->message.ptr));
|
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
|
*(bool *) fn_data = true; // Tell event loop to stop
|
||||||
} else if (ev == MG_EV_ERROR) {
|
} else if (ev == MG_EV_ERROR) {
|
||||||
*(bool *) fn_data = true; // Error, tell event loop to stop
|
*(bool *) fn_data = true; // Error, tell event loop to stop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user