samples: net: Check the return value of nats_publish

Check and handle the return value of nats_publish() in main.c

Fixes #6258.

Signed-off-by: Satya Bhattacharya <satyacube@gmail.com>
This commit is contained in:
Satya Bhattacharya 2018-06-06 02:11:54 -07:00 committed by Maureen Helm
commit fd561dd596

View file

@ -194,6 +194,7 @@ static void write_led(const struct nats *nats,
bool state)
{
char *pubstate;
int ret;
if (!led0) {
fake_led = state;
@ -202,10 +203,13 @@ static void write_led(const struct nats *nats,
}
pubstate = state ? "on" : "off";
nats_publish(nats, "led0", 0, msg->reply_to, 0,
pubstate, strlen(pubstate));
printk("*** Turning LED %s\n", pubstate);
ret = nats_publish(nats, "led0", 0, msg->reply_to, 0,
pubstate, strlen(pubstate));
if (ret < 0) {
printk("Failed to publish: %d\n", ret);
} else {
printk("*** Turning LED %s\n", pubstate);
}
}
static int on_msg_received(const struct nats *nats,