2021-11-12 12:48:42 +00:00
|
|
|
#include <Common/getMaxFileDescriptorCount.h>
|
2024-01-18 09:11:50 +00:00
|
|
|
#include <sys/resource.h>
|
2021-10-27 12:26:42 +00:00
|
|
|
|
2024-01-18 09:11:50 +00:00
|
|
|
std::optional<size_t> getMaxFileDescriptorCount()
|
2021-10-27 12:26:42 +00:00
|
|
|
{
|
2024-01-19 17:07:38 +00:00
|
|
|
#if defined(OS_LINUX) || defined(OS_DARWIN)
|
|
|
|
/// We want to calculate it only once.
|
2024-01-18 09:11:50 +00:00
|
|
|
static auto result = []() -> std::optional<size_t>
|
2021-11-12 12:48:42 +00:00
|
|
|
{
|
2024-01-18 09:11:50 +00:00
|
|
|
rlimit rlim;
|
2024-01-19 17:07:38 +00:00
|
|
|
if (0 != getrlimit(RLIMIT_NOFILE, &rlim))
|
2024-01-18 09:11:50 +00:00
|
|
|
return std::nullopt;
|
|
|
|
return rlim.rlim_max;
|
|
|
|
}();
|
2021-11-17 12:44:07 +00:00
|
|
|
return result;
|
2024-01-19 17:07:38 +00:00
|
|
|
#else
|
|
|
|
return std::nullopt;
|
|
|
|
#endif
|
2021-10-27 12:26:42 +00:00
|
|
|
}
|