Handle MG_EV_CLOSE in examples

PUBLISHED_FROM=57c62a4123a54ecb455dbf91f3fe562fb0cf2ec2
This commit is contained in:
Alexander Alashkin 2016-11-01 09:46:09 +01:00 committed by Cesanta Bot
parent e99088348d
commit e62dc8f3b2
5 changed files with 34 additions and 5 deletions

View File

@ -39,6 +39,13 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
s_time_to_exit = 1;
break;
}
case MG_EV_CLOSE: {
if (s_time_to_exit == 0) {
printf("Server closed connection\n");
s_time_to_exit = 1;
}
break;
}
}
}

View File

@ -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);
putchar('\n');
exit_flag = 1;
}
} else if (ev == MG_EV_CLOSE) {
exit_flag = 1;
};
}
int main(void) {

View File

@ -34,9 +34,17 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *) p;
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;
break;
}
case MG_EV_CLOSE: {
if (s_time_to_exit == 0) {
printf("Server closed connection\n");
s_time_to_exit = 1;
}
break;
}
}
}

View File

@ -31,6 +31,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
putchar('\n');
s_exit_flag = 1;
break;
case MG_EV_CLOSE:
if(s_exit_flag == 0) {
printf("Server closed connection\n");
s_exit_flag = 1;
}
break;
default:
break;
}

View File

@ -28,6 +28,12 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
nc->flags |= MG_F_SEND_AND_CLOSE;
s_exit_flag = 1;
break;
case MG_EV_CLOSE:
if (s_exit_flag == 0) {
printf("Server closed connection\n");
s_exit_flag = 1;
};
break;
default:
break;
}