mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 17:32:32 +00:00
20 lines
475 B
C++
20 lines
475 B
C++
#include <Common/getMaxFileDescriptorCount.h>
|
|
#include <sys/resource.h>
|
|
|
|
std::optional<size_t> getMaxFileDescriptorCount()
|
|
{
|
|
#if defined(OS_LINUX) || defined(OS_DARWIN)
|
|
/// We want to calculate it only once.
|
|
static auto result = []() -> std::optional<size_t>
|
|
{
|
|
rlimit rlim;
|
|
if (0 != getrlimit(RLIMIT_NOFILE, &rlim))
|
|
return std::nullopt;
|
|
return rlim.rlim_max;
|
|
}();
|
|
return result;
|
|
#else
|
|
return std::nullopt;
|
|
#endif
|
|
}
|