mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
new db
new database fift/func bugfixes
This commit is contained in:
parent
950e292264
commit
e30d98eb30
110 changed files with 6102 additions and 2075 deletions
|
@ -301,6 +301,20 @@ typename std::enable_if<std::is_unsigned<T>::value, T>::type hex_to_integer(Slic
|
|||
return integer_value;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Result<typename std::enable_if<std::is_unsigned<T>::value, T>::type> hex_to_integer_safe(Slice str) {
|
||||
T integer_value = 0;
|
||||
auto begin = str.begin();
|
||||
auto end = str.end();
|
||||
while (begin != end) {
|
||||
if (!is_hex_digit(*begin)) {
|
||||
return Status::Error("not a hex digit");
|
||||
}
|
||||
integer_value = static_cast<T>(integer_value * 16 + hex_to_int(*begin++));
|
||||
}
|
||||
return integer_value;
|
||||
}
|
||||
|
||||
double to_double(Slice str);
|
||||
|
||||
template <class T>
|
||||
|
|
84
tdutils/td/utils/port/rlimit.cpp
Normal file
84
tdutils/td/utils/port/rlimit.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include "rlimit.h"
|
||||
#if TD_LINUX
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
namespace td {
|
||||
|
||||
#if TD_PORT_POSIX
|
||||
|
||||
namespace {
|
||||
|
||||
int get_rlimit_type(RlimitType rlim_type) {
|
||||
switch (rlim_type) {
|
||||
case RlimitType::nofile:
|
||||
return RLIMIT_NOFILE;
|
||||
case RlimitType::rss:
|
||||
return RLIMIT_RSS;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
td::Status change_rlimit(RlimitType rlim_type, td::uint64 value, td::uint64 cap) {
|
||||
if (cap && value > cap) {
|
||||
return td::Status::Error("setrlimit(): bad argument");
|
||||
}
|
||||
int resource = get_rlimit_type(rlim_type);
|
||||
|
||||
struct rlimit r;
|
||||
if (getrlimit(resource, &r) < 0) {
|
||||
return td::Status::PosixError(errno, "failed getrlimit()");
|
||||
}
|
||||
|
||||
if (cap) {
|
||||
r.rlim_max = cap;
|
||||
} else if (r.rlim_max < value) {
|
||||
r.rlim_max = value;
|
||||
}
|
||||
r.rlim_cur = value;
|
||||
if (setrlimit(resource, &r) < 0) {
|
||||
return td::Status::PosixError(errno, "failed setrlimit()");
|
||||
}
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
td::Status change_maximize_rlimit(RlimitType rlim_type, td::uint64 value) {
|
||||
int resource = get_rlimit_type(rlim_type);
|
||||
|
||||
struct rlimit r;
|
||||
if (getrlimit(resource, &r) < 0) {
|
||||
return td::Status::PosixError(errno, "failed getrlimit()");
|
||||
}
|
||||
|
||||
if (r.rlim_max < value) {
|
||||
auto t = r;
|
||||
t.rlim_cur = value;
|
||||
t.rlim_max = value;
|
||||
if (setrlimit(resource, &t) >= 0) {
|
||||
return td::Status::OK();
|
||||
}
|
||||
}
|
||||
|
||||
r.rlim_cur = value < r.rlim_max ? value : r.rlim_max;
|
||||
if (setrlimit(resource, &r) < 0) {
|
||||
return td::Status::PosixError(errno, "failed setrlimit()");
|
||||
}
|
||||
return td::Status::OK();
|
||||
}
|
||||
#else
|
||||
td::Status change_rlimit(RlimitType rlim, td::uint64 value) {
|
||||
return td::Status::Error("setrlimit not implemented on WINDOWS");
|
||||
}
|
||||
td::Status change_maximize_rlimit(RlimitType rlim, td::uint64 value) {
|
||||
return td::Status::OK();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace td
|
||||
|
14
tdutils/td/utils/port/rlimit.h
Normal file
14
tdutils/td/utils/port/rlimit.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "td/utils/port/config.h"
|
||||
#include "td/utils/port/platform.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
enum class RlimitType { nofile, rss };
|
||||
|
||||
td::Status change_rlimit(RlimitType rlim_type, td::uint64 value, td::uint64 cap = 0);
|
||||
td::Status change_maximize_rlimit(RlimitType rlim, td::uint64 value);
|
||||
|
||||
} // namespace td
|
Loading…
Add table
Add a link
Reference in a new issue