Commit e62dc8f3 authored by Alexander Alashkin's avatar Alexander Alashkin Committed by Cesanta Bot

Handle MG_EV_CLOSE in examples

PUBLISHED_FROM=57c62a4123a54ecb455dbf91f3fe562fb0cf2ec2
parent e9908834
...@@ -39,6 +39,13 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -39,6 +39,13 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
s_time_to_exit = 1; s_time_to_exit = 1;
break; break;
} }
case MG_EV_CLOSE: {
if (s_time_to_exit == 0) {
printf("Server closed connection\n");
s_time_to_exit = 1;
}
break;
}
} }
} }
......
...@@ -22,7 +22,9 @@ static void ev_handler(struct mg_connection *c, int ev, void *p) { ...@@ -22,7 +22,9 @@ static void ev_handler(struct mg_connection *c, int ev, void *p) {
fwrite(hm->message.p, 1, hm->message.len, stdout); fwrite(hm->message.p, 1, hm->message.len, stdout);
putchar('\n'); putchar('\n');
exit_flag = 1; exit_flag = 1;
} } else if (ev == MG_EV_CLOSE) {
exit_flag = 1;
};
} }
int main(void) { int main(void) {
......
...@@ -34,9 +34,17 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -34,9 +34,17 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
case MG_EV_COAP_RST: { case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *) p; struct mg_coap_message *cm = (struct mg_coap_message *) p;
printf("ACK/RST for message with msg_id = %d received\n", cm->msg_id); printf("ACK/RST for message with msg_id = %d received\n", cm->msg_id);
nc->flags |= MG_F_SEND_AND_CLOSE;
s_time_to_exit = 1; s_time_to_exit = 1;
break; break;
} }
case MG_EV_CLOSE: {
if (s_time_to_exit == 0) {
printf("Server closed connection\n");
s_time_to_exit = 1;
}
break;
}
} }
} }
......
...@@ -31,6 +31,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -31,6 +31,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
putchar('\n'); putchar('\n');
s_exit_flag = 1; s_exit_flag = 1;
break; break;
case MG_EV_CLOSE:
if(s_exit_flag == 0) {
printf("Server closed connection\n");
s_exit_flag = 1;
}
break;
default: default:
break; break;
} }
......
...@@ -28,6 +28,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -28,6 +28,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
nc->flags |= MG_F_SEND_AND_CLOSE; nc->flags |= MG_F_SEND_AND_CLOSE;
s_exit_flag = 1; s_exit_flag = 1;
break; break;
case MG_EV_CLOSE:
if (s_exit_flag == 0) {
printf("Server closed connection\n");
s_exit_flag = 1;
};
break;
default: default:
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment