Commit f05733da authored by Marko Mikulicic's avatar Marko Mikulicic

Fix COAP example, reduce number of ctx switches

    PUBLISHED_FROM=7010fff404826c3dfc783d2cbdcbd0936a8a2b85
parent 3c53909e
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "mongoose.h" #include "mongoose.h"
static int s_time_to_exit = 0; 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) { static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) { switch (ev) {
...@@ -32,16 +32,15 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -32,16 +32,15 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
} }
case MG_EV_COAP_ACK: case MG_EV_COAP_ACK:
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", printf("ACK/RST for message with msg_id = %d received\n", cm->msg_id);
cm->msg_id);
s_time_to_exit = 1; s_time_to_exit = 1;
break; break;
} }
} }
} }
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
struct mg_mgr mgr; struct mg_mgr mgr;
struct mg_connection *nc; struct mg_connection *nc;
char *address = s_default_address; char *address = s_default_address;
...@@ -63,7 +62,7 @@ int main(int argc, char* argv[]) { ...@@ -63,7 +62,7 @@ int main(int argc, char* argv[]) {
mg_set_protocol_coap(nc); mg_set_protocol_coap(nc);
while (!s_time_to_exit) { while (!s_time_to_exit) {
mg_mgr_poll(&mgr, 1); mg_mgr_poll(&mgr, 1000000);
} }
mg_mgr_free(&mgr); mg_mgr_free(&mgr);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "mongoose.h" #include "mongoose.h"
static char* s_default_address = "udp://:5683"; static char *s_default_address = "udp://:5683";
static int s_sig_received = 0; static int s_sig_received = 0;
static void signal_handler(int sig_num) { static void signal_handler(int sig_num) {
...@@ -21,7 +21,7 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -21,7 +21,7 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) { switch (ev) {
case MG_EV_COAP_CON: { case MG_EV_COAP_CON: {
uint32_t res; uint32_t res;
struct mg_coap_message *cm = (struct mg_coap_message *)p; struct mg_coap_message *cm = (struct mg_coap_message *) p;
printf("CON with msg_id = %d received\n", cm->msg_id); printf("CON with msg_id = %d received\n", cm->msg_id);
res = mg_coap_send_ack(nc, cm->msg_id); res = mg_coap_send_ack(nc, cm->msg_id);
if (res == 0) { if (res == 0) {
...@@ -35,9 +35,8 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -35,9 +35,8 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
case MG_EV_COAP_NOC: case MG_EV_COAP_NOC:
case MG_EV_COAP_ACK: case MG_EV_COAP_ACK:
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/NOC with msg_id = %d received\n", printf("ACK/RST/NOC with msg_id = %d received\n", cm->msg_id);
cm->msg_id);
break; break;
} }
} }
...@@ -63,7 +62,7 @@ int main() { ...@@ -63,7 +62,7 @@ int main() {
mg_set_protocol_coap(nc); mg_set_protocol_coap(nc);
while (!s_sig_received) { while (!s_sig_received) {
mg_mgr_poll(&mgr, 1); mg_mgr_poll(&mgr, 1000000);
} }
printf("Exiting on signal %d\n", s_sig_received); printf("Exiting on signal %d\n", s_sig_received);
......
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