Skip to content

Commit fd561dd

Browse files
satyacubeMaureenHelm
authored andcommitted
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 <[email protected]>
1 parent b0abf36 commit fd561dd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

samples/net/nats/src/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static void write_led(const struct nats *nats,
194194
bool state)
195195
{
196196
char *pubstate;
197+
int ret;
197198

198199
if (!led0) {
199200
fake_led = state;
@@ -202,10 +203,13 @@ static void write_led(const struct nats *nats,
202203
}
203204

204205
pubstate = state ? "on" : "off";
205-
nats_publish(nats, "led0", 0, msg->reply_to, 0,
206-
pubstate, strlen(pubstate));
207-
208-
printk("*** Turning LED %s\n", pubstate);
206+
ret = nats_publish(nats, "led0", 0, msg->reply_to, 0,
207+
pubstate, strlen(pubstate));
208+
if (ret < 0) {
209+
printk("Failed to publish: %d\n", ret);
210+
} else {
211+
printk("*** Turning LED %s\n", pubstate);
212+
}
209213
}
210214

211215
static int on_msg_received(const struct nats *nats,

0 commit comments

Comments
 (0)