examples/libcoap : minor patch on select timeout
authorJin-Seong Kim <jseong82.kim@samsung.com>
Wed, 9 Aug 2017 00:19:08 +0000 (09:19 +0900)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:16:45 +0000 (21:16 -0700)
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 <jseong82.kim@samsung.com>
apps/examples/libcoap_client/libcoap-client.c
apps/examples/libcoap_server/libcoap-server.c

index 90b4fe3..e92d120 100644 (file)
@@ -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);
        }
 
index f065537..c14e311 100644 (file)
@@ -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