From a74f7aa745853a555c100dcd7b826444f0468af6 Mon Sep 17 00:00:00 2001 From: Jin-Seong Kim Date: Wed, 9 Aug 2017 09:19:08 +0900 Subject: [PATCH] examples/libcoap : minor patch on select timeout This commit is minor patch on select timeout - set timeout to wait_seconds when timeout exceeds it - clear readfds when application exits Change-Id: Ie477b6dc868bbc4d69941579059b0d587300b4ab Signed-off-by: Jin-Seong Kim --- apps/examples/libcoap_client/libcoap-client.c | 11 ++++++++++- apps/examples/libcoap_server/libcoap-server.c | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/examples/libcoap_client/libcoap-client.c b/apps/examples/libcoap_client/libcoap-client.c index 90b4fe3..e92d120 100644 --- a/apps/examples/libcoap_client/libcoap-client.c +++ b/apps/examples/libcoap_client/libcoap-client.c @@ -1366,7 +1366,13 @@ int main(int argc, char **argv) } } - info("coap-client : timeout info, tv %lu sec. %ld usec, now %lu, obs_wait %lu\n", + /* To prevent abnormal waiting on select */ + if (tv.tv_sec > (time_t)wait_seconds) { + tv.tv_sec = (time_t)wait_seconds; + tv.tv_usec = 0; + } + + debug("coap-client : timeout info, tv %lu sec. %ld usec, now %lu, obs_wait %lu\n", (unsigned long)tv.tv_sec, tv.tv_usec, (unsigned long)now, (unsigned long)obs_wait); result = select(ctx->sockfd + 1, &readfds, 0, 0, &tv); @@ -1407,6 +1413,9 @@ error_exit: } #endif if (ctx->sockfd > 0) { + if (FD_ISSET(ctx->sockfd, &readfds)) { + FD_CLR(ctx->sockfd, &readfds); + } close(ctx->sockfd); } diff --git a/apps/examples/libcoap_server/libcoap-server.c b/apps/examples/libcoap_server/libcoap-server.c index f065537..c14e311 100644 --- a/apps/examples/libcoap_server/libcoap-server.c +++ b/apps/examples/libcoap_server/libcoap-server.c @@ -646,6 +646,9 @@ exit: } #endif if (ctx->sockfd > 0) { + if (FD_ISSET(ctx->sockfd, &readfds)) { + FD_CLR(ctx->sockfd, &readfds); + } close(ctx->sockfd); } #ifdef WITH_TCP -- 2.7.4