Fix FD_CLOEXEC setting

This commit is contained in:
Sergey Lyubka 2021-11-05 13:30:12 +00:00
parent 975db86306
commit 093cd6a6a3
2 changed files with 4 additions and 2 deletions

View File

@ -2976,7 +2976,8 @@ static void mg_set_non_blocking_mode(SOCKET fd) {
#elif MG_ARCH == MG_ARCH_AZURERTOS
fcntl(fd, F_SETFL, O_NONBLOCK);
#else
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | FD_CLOEXEC);
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); // Set non-blocking mode
fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec
#endif
}

View File

@ -134,7 +134,8 @@ static void mg_set_non_blocking_mode(SOCKET fd) {
#elif MG_ARCH == MG_ARCH_AZURERTOS
fcntl(fd, F_SETFL, O_NONBLOCK);
#else
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | FD_CLOEXEC);
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); // Set non-blocking mode
fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec
#endif
}