mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Retry in case of too many sockets opened instead of stopping the server.
This commit is contained in:
parent
c02849e269
commit
224119a60a
1 changed files with 7 additions and 0 deletions
|
@ -98,6 +98,7 @@ typedef int socket_t;
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -2550,6 +2551,12 @@ inline bool Server::listen_internal() {
|
||||||
socket_t sock = accept(svr_sock_, nullptr, nullptr);
|
socket_t sock = accept(svr_sock_, nullptr, nullptr);
|
||||||
|
|
||||||
if (sock == INVALID_SOCKET) {
|
if (sock == INVALID_SOCKET) {
|
||||||
|
if (errno == EMFILE) {
|
||||||
|
// The per-process limit of open file descriptors has been reached.
|
||||||
|
// Try to accept new connections after a short sleep.
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (svr_sock_ != INVALID_SOCKET) {
|
if (svr_sock_ != INVALID_SOCKET) {
|
||||||
detail::close_socket(svr_sock_);
|
detail::close_socket(svr_sock_);
|
||||||
ret = false;
|
ret = false;
|
||||||
|
|
Loading…
Reference in a new issue