netutils/libcoap : patch to add timeout on accept socket
authorJin-Seong Kim <jseong82.kim@samsung.com>
Tue, 1 Aug 2017 08:38:55 +0000 (17:38 +0900)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:15:48 +0000 (21:15 -0700)
This commit is patch to add timeout on accept socket
 - to prevent holding socket on libcoap-server, added timeout on socket

Change-Id: Ibd40f9ba9c69f272f10af91bed900a0b8faa40b8
Signed-off-by: Jin-Seong Kim <jseong82.kim@samsung.com>
apps/netutils/libcoap/net.c

index 4f59600..171ee65 100644 (file)
@@ -1993,6 +1993,8 @@ int coap_net_bind(coap_context_t *ctx, const char *host, const char *port, void
        struct sockaddr caddr;
        socklen_t caddrlen;
 
+       struct timeval timeout = {10, 0}; /* Timeout for TCP accept */
+
 #ifdef WITH_MBEDTLS
        tls_session *session = NULL;
 #endif
@@ -2057,6 +2059,10 @@ int coap_net_bind(coap_context_t *ctx, const char *host, const char *port, void
                                        break;
                                }
 
+                               if (setsockopt(ctx->sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) {
+                                       printf("coap_net_bind : failed to set socket option, errno %d\n", errno);
+                               }
+
                                newsock = accept(ctx->sockfd, &caddr, &caddrlen);
 
                                if (newsock < 0) {