mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
threadsafe accept on windows, linux
* Windows has WSAAccept() which will create sockets inheriting flags from the server socket * Linux has accept4() which has a flags argument supporting SOCK_CLOEXEC
This commit is contained in:
parent
50fce538c6
commit
fb739dbaec
1 changed files with 8 additions and 0 deletions
|
@ -6484,7 +6484,15 @@ inline bool Server::listen_internal() {
|
|||
#ifndef _WIN32
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
// sockets conneced via WASAccept inherit flags NO_HANDLE_INHERIT, OVERLAPPED
|
||||
socket_t sock = WSAAccept(svr_sock_, nullptr, nullptr, nullptr, 0);
|
||||
#elif defined __linux__
|
||||
socket_t sock = accept4(svr_sock_, nullptr, nullptr, SOCK_CLOEXEC);
|
||||
#else
|
||||
socket_t sock = accept(svr_sock_, nullptr, nullptr);
|
||||
#endif
|
||||
|
||||
if (sock == INVALID_SOCKET) {
|
||||
if (errno == EMFILE) {
|
||||
|
|
Loading…
Reference in a new issue