Hi,
I am adapting the nRF9160 coap_client sample, and have 2 questions:
- If I do not care about responses what is the ideal / cleanest way of configuring the app or underlying socket to ignore / drop them?
- On the other hand, if I choose to consume the responses, is it ok to have this handled in a one thread while coap requests are periodically dispatched in via a work_q that leverages a different thread? Could any concurrency issues or race conditions arise in the underlying socket or accompanying polling data structures? A draft of what I have in mind is as follows (note that the handler for send_telemetry_work recursively enqueues the work for subsequent coap requests):
k_delayed_work_submit_to_queue(&application_work_q, &send_telemetry_work, K_SECONDS(0)); int err, received; while (1) { err = wait(POLL_TIMEOUT_S); if (err < 0) { if (err == -EAGAIN) { continue; } printk("Poll error, exit...\n"); break; } received = recv(sock, coap_buf, sizeof(coap_buf), MSG_DONTWAIT); if (received < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { printk("socket EAGAIN\n"); continue; } else { printk("Socket error, exit...\n"); break; } } if (received == 0) { printk("Empty datagram\n"); continue; } err = client_handle_telemetry_send_response(coap_buf, received); if (err < 0) { printk("Invalid response, exit...\n"); break; } }
Thanks.