From: Jin-Seong Kim Date: Wed, 9 Aug 2017 00:19:08 +0000 (+0900) Subject: examples/libcoap : minor patch on select timeout X-Git-Tag: 1.1_Public_Release~318^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a74f7aa745853a555c100dcd7b826444f0468af6;p=rtos%2Ftinyara.git 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 --- 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