Fix COAP example, reduce number of ctx switches

PUBLISHED_FROM=7010fff404826c3dfc783d2cbdcbd0936a8a2b85
This commit is contained in:
Marko Mikulicic committed 2015-12-15 11:36:34 +01:00
1 parent 3c53909e82
commit f05733da69
2 files changed
+18 -20

No files matched your search

+9 -10
View File
@@ -2,14 +2,14 @@
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
*
* This program sends CoAP CON-message to server (coap.me by default)
* This program sends CoAP CON-message to server (coap.me by default)
* and waits for answer.
*/
#include "mongoose.h"
static int s_time_to_exit = 0;
static char* s_default_address = "udp://coap.me:5683";
static char *s_default_address = "udp://coap.me:5683";
static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) {
@@ -31,17 +31,16 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
break;
}
case MG_EV_COAP_ACK:
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);
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);
s_time_to_exit = 1;
break;
}
}
}
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
struct mg_mgr mgr;
struct mg_connection *nc;
char *address = s_default_address;
@@ -50,7 +49,7 @@ int main(int argc, char* argv[]) {
address = argv[1];
}
printf("Using %s as CoAP server\n", address);
printf("Using %s as CoAP server\n", address);
mg_mgr_init(&mgr, 0);
@@ -63,10 +62,10 @@ int main(int argc, char* argv[]) {
mg_set_protocol_coap(nc);
while (!s_time_to_exit) {
mg_mgr_poll(&mgr, 1);
mg_mgr_poll(&mgr, 1000000);
}
mg_mgr_free(&mgr);
return 0;
}