Handle MG_EV_CLOSE in examples

PUBLISHED_FROM=57c62a4123a54ecb455dbf91f3fe562fb0cf2ec2
This commit is contained in:
Alexander Alashkin authored and Cesanta Bot committed 2016-11-01 08:58:38 +00:00
1 parent e99088348d
commit e62dc8f3b2
5 files changed
+34 -5

No files matched your search

+11 -4
View File
@@ -7,10 +7,10 @@ To create a CoAP client, follow this pattern:
1. Create an outbound connection by calling `mg_connect`
2. Call `mg_set_protocol_coap` for created connection
3. Create an event handler function that handles the following events:
- `MG_EV_COAP_CON`
- `MG_EV_COAP_NOC`
- `MG_EV_COAP_ACK`
- `MG_EV_COAP_RST`
- `MG_EV_COAP_CON`
- `MG_EV_COAP_NOC`
- `MG_EV_COAP_ACK`
- `MG_EV_COAP_RST`
Here's an example of the simplest CoAP client.
Error checking is omitted for the sake of clarity:
@@ -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;
}
}
}