diff --git a/src/manager.cpp b/src/manager.cpp index 9955fd71ab2df9b1b02287cab44ac6db94ac1638..09f86950992b80de876e5cef46535d677d07006b 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -81,6 +81,11 @@ using random_device = dht::crypto::random_device; #include "data_transfer.h" +#ifndef WIN32 +#include <sys/time.h> +#include <sys/resource.h> +#endif + #include <cerrno> #include <ctime> #include <cstdlib> @@ -670,6 +675,17 @@ Manager::init(const std::string &config_file) // FIXME: this is no good initialized = true; +#ifndef WIN32 + // Set the max number of open files. + struct rlimit nofiles; + if (getrlimit(RLIMIT_NOFILE, &nofiles) == 0) { + if (nofiles.rlim_cur < nofiles.rlim_max && nofiles.rlim_cur < 1024u) { + nofiles.rlim_cur = std::min<rlim_t>(nofiles.rlim_max, 8192u); + setrlimit(RLIMIT_NOFILE, &nofiles); + } + } +#endif + #define PJSIP_TRY(ret) do { \ if (ret != PJ_SUCCESS) \ throw std::runtime_error(#ret " failed"); \