WIP: Set max possible file limit on all platforms #7781
7 changed files with 53 additions and 17 deletions
|
@ -22,7 +22,8 @@ using namespace std;
|
|||
|
||||
Platform::Platform()
|
||||
{
|
||||
/// @see initialization routine in android/app/src/main/cpp/com/.../Platform.hpp
|
||||
/// @see initialization routine in android/app/src/main/cpp/app/organicmaps/platform/AndroidPlatform.hpp
|
||||
pl::SetMaxOpenFileLimit();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
Platform::Platform()
|
||||
{
|
||||
pl::SetMaxOpenFileLimit();
|
||||
|
||||
m_isTablet = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
|
||||
|
||||
NSBundle * bundle = NSBundle.mainBundle;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "private.h"
|
||||
#include "platform/platform.hpp"
|
||||
#include "platform/platform_unix_impl.hpp"
|
||||
|
||||
#include "platform/socket.hpp"
|
||||
|
||||
|
@ -76,6 +77,8 @@ std::unique_ptr<Socket> CreateSocket()
|
|||
|
||||
Platform::Platform()
|
||||
{
|
||||
pl::SetMaxOpenFileLimit();
|
||||
|
||||
using base::JoinPath;
|
||||
// Current executable's path with a trailing slash.
|
||||
auto const execDir = GetExecutableDir();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "platform/platform.hpp"
|
||||
#include "platform/platform_unix_impl.hpp"
|
||||
|
||||
#include "base/file_name_utils.hpp"
|
||||
#include "base/logging.hpp"
|
||||
|
@ -26,6 +27,8 @@
|
|||
|
||||
Platform::Platform()
|
||||
{
|
||||
pl::SetMaxOpenFileLimit();
|
||||
|
||||
// OMaps.app/Content/Resources or omim-build-debug for tests.
|
||||
std::string const resourcesPath = NSBundle.mainBundle.resourcePath.UTF8String;
|
||||
// Omaps.app or omim-build-debug for tests.
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
#include <regex>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(OMIM_OS_MAC) || defined(OMIM_OS_IPHONE)
|
||||
|
@ -157,4 +158,20 @@ void EnumerateFilesByRegExp(string const & directory, string const & regexp, vec
|
|||
});
|
||||
}
|
||||
|
||||
void SetMaxOpenFileLimit()
|
||||
{
|
||||
struct rlimit rlim;
|
||||
if (getrlimit(RLIMIT_NOFILE, &rlim))
|
||||
LOG(LERROR, ("getrlimit failed with errno", errno));
|
||||
else
|
||||
{
|
||||
LOG(LINFO, ("NOFILE soft limit", rlim.rlim_cur, "hard limit", rlim.rlim_max));
|
||||
rlim.rlim_cur = rlim.rlim_max;
|
||||
if (setrlimit(RLIMIT_NOFILE, &rlim))
|
||||
LOG(LERROR, ("setrlimit failed with errno", errno));
|
||||
else
|
||||
LOG(LINFO, ("NOFILE is set to", rlim.rlim_cur));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pl
|
||||
|
|
|
@ -10,4 +10,6 @@ void EnumerateFiles(std::string const & directory, std::function<void(char const
|
|||
|
||||
void EnumerateFilesByRegExp(std::string const & directory, std::string const & regexp,
|
||||
std::vector<std::string> & res);
|
||||
|
||||
void SetMaxOpenFileLimit();
|
||||
} // namespace pl
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static bool GetUserWritableDir(string & outDir)
|
||||
static bool GetUserWritableDir(std::string & outDir)
|
||||
{
|
||||
char pathBuf[MAX_PATH] = {0};
|
||||
if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf)))
|
||||
|
@ -33,7 +31,7 @@ static bool GetUserWritableDir(string & outDir)
|
|||
}
|
||||
|
||||
/// @return Full path to the executable file
|
||||
static bool GetPathToBinary(string & outPath)
|
||||
static bool GetPathToBinary(std::string & outPath)
|
||||
{
|
||||
// get path to executable
|
||||
char pathBuf[MAX_PATH] = {0};
|
||||
|
@ -47,7 +45,17 @@ static bool GetPathToBinary(string & outPath)
|
|||
|
||||
Platform::Platform()
|
||||
{
|
||||
string path;
|
||||
int const oldOpenFilesLimit = _getmaxstdio();
|
||||
int constexpr kMaxHardOpenFileLimit = 8192;
|
||||
if (kMaxHardOpenFileLimit > oldOpenFilesLimit)
|
||||
{
|
||||
if (kMaxHardOpenFileLimit == _setmaxstdio(kMaxHardOpenFileLimit))
|
||||
LOG(LINFO, ("Increased max open files limit from", oldOpenFilesLimit, "to", kMaxHardOpenFileLimit));
|
||||
else
|
||||
LOG(LERROR, ("Failed to increase max open files limit from", oldOpenFilesLimit, "to", kMaxHardOpenFileLimit, "with error", errno));
|
||||
}
|
||||
|
||||
std::string path;
|
||||
CHECK(GetPathToBinary(path), ("Can't get path to binary"));
|
||||
|
||||
// resources path:
|
||||
|
@ -71,7 +79,7 @@ Platform::Platform()
|
|||
// writable path:
|
||||
// 1. the same as resources if we have write access to this folder
|
||||
// 2. otherwise, use system-specific folder
|
||||
string const tmpFilePath = base::JoinPath(m_resourcesDir, "mapswithmetmptestfile");
|
||||
std::string const tmpFilePath = base::JoinPath(m_resourcesDir, "mapswithmetmptestfile");
|
||||
try
|
||||
{
|
||||
FileWriter tmpfile(tmpFilePath);
|
||||
|
@ -95,16 +103,16 @@ Platform::Platform()
|
|||
LOG(LINFO, ("Settings Directory:", m_settingsDir));
|
||||
}
|
||||
|
||||
bool Platform::IsFileExistsByFullPath(string const & filePath)
|
||||
bool Platform::IsFileExistsByFullPath(std::string const & filePath)
|
||||
{
|
||||
return ::GetFileAttributesA(filePath.c_str()) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
//static
|
||||
void Platform::DisableBackupForFile(string const & filePath) {}
|
||||
void Platform::DisableBackupForFile(std::string const & filePath) {}
|
||||
|
||||
// static
|
||||
string Platform::GetCurrentWorkingDirectory() noexcept
|
||||
std::string Platform::GetCurrentWorkingDirectory() noexcept
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
char const * const dir = getcwd(path, PATH_MAX);
|
||||
|
@ -114,7 +122,7 @@ string Platform::GetCurrentWorkingDirectory() noexcept
|
|||
}
|
||||
|
||||
// static
|
||||
Platform::EError Platform::RmDir(string const & dirName)
|
||||
Platform::EError Platform::RmDir(std::string const & dirName)
|
||||
{
|
||||
if (_rmdir(dirName.c_str()) != 0)
|
||||
return ErrnoToError();
|
||||
|
@ -122,7 +130,7 @@ Platform::EError Platform::RmDir(string const & dirName)
|
|||
}
|
||||
|
||||
// static
|
||||
Platform::EError Platform::GetFileType(string const & path, EFileType & type)
|
||||
Platform::EError Platform::GetFileType(std::string const & path, EFileType & type)
|
||||
{
|
||||
struct _stat32 stats;
|
||||
if (_stat32(path.c_str(), &stats) != 0)
|
||||
|
@ -136,12 +144,12 @@ Platform::EError Platform::GetFileType(string const & path, EFileType & type)
|
|||
return ERR_OK;
|
||||
}
|
||||
|
||||
string Platform::DeviceName() const
|
||||
std::string Platform::DeviceName() const
|
||||
{
|
||||
return OMIM_OS_NAME;
|
||||
}
|
||||
|
||||
string Platform::DeviceModel() const
|
||||
std::string Platform::DeviceModel() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -172,12 +180,12 @@ Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize)
|
|||
return STORAGE_OK;
|
||||
}
|
||||
|
||||
bool Platform::IsDirectoryEmpty(string const & directory)
|
||||
bool Platform::IsDirectoryEmpty(std::string const & directory)
|
||||
{
|
||||
return PathIsDirectoryEmptyA(directory.c_str());
|
||||
}
|
||||
|
||||
bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size)
|
||||
bool Platform::GetFileSizeByFullPath(std::string const & filePath, uint64_t & size)
|
||||
{
|
||||
HANDLE hFile = CreateFileA(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
|
|
Reference in a new issue