netutils/libcoap : patch to add timeout on accept socket
This commit is patch to add timeout on accept socket
- to prevent holding socket on libcoap-server, added timeout on socket
@@ -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) {
