examples/tls_server: fix unclosed socket problem.
If tls server would be executed double at the same time,
bind or listen socket can't be released properly.
Change the client_fd and listned_fd values from global
to local variable.
@@ -785,6 +785,7 @@ int psk_callback(void *p_info, mbedtls_ssl_context *ssl, const unsigned char *na
}
#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
+#if 0
static mbedtls_net_context listen_fd, client_fd;
/* Interruption handler to ensure clean exit (for valgrind testing) */
@@ -798,6 +799,7 @@ void term_handler(int sig)
mbedtls_net_free(&client_fd); /* causes net_read() to abort */
}
#endif
+#endif
/****************************************************************************
* tls_server_main
@@ -877,6 +879,9 @@ int tls_server_cb(void *args)
mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
#endif
+ mbedtls_net_context listen_fd;
+ mbedtls_net_context client_fd;
+
/*
* Make sure memory references are valid in case we exit early.
*/
@@ -1754,12 +1759,14 @@ reset:
if (!(opt.retry--)) {
goto exit;
}
+#if 0
#if !defined(_WIN32)
if (received_sigterm) {
mbedtls_printf(" interrupted by SIGTERM\n");
ret = 0;
goto exit;
}
+#endif
#endif
if (ret == MBEDTLS_ERR_SSL_CLIENT_RECONNECT) {
@@ -1788,6 +1795,7 @@ reset:
goto exit;
}
if ((ret = mbedtls_net_accept(&listen_fd, &client_fd, client_ip, sizeof(client_ip), &cliip_len)) != 0) {
+#if 0
#if !defined(_WIN32)
if (received_sigterm) {
mbedtls_printf(" interrupted by signal\n");
@@ -1795,7 +1803,7 @@ reset:
goto exit;
}
#endif
-
+#endif
mbedtls_printf(" failed\n ! mbedtls_net_accept returned -0x%x\n\n", -ret);
goto exit;
}
