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:
parent
b0abf365af
commit
fd561dd596
1 changed files with 8 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue