Don't use min/max as variable names.
This commit is contained in:
parent
fe6c61f2ea
commit
1a98ac8004
@ -7347,7 +7347,7 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
|
|||||||
|
|
||||||
LOG(INFO) << "Set option " << request.name_;
|
LOG(INFO) << "Set option " << request.name_;
|
||||||
|
|
||||||
auto set_integer_option = [&](Slice name, int64 min = 0, int64 max = std::numeric_limits<int32>::max()) {
|
auto set_integer_option = [&](Slice name, int64 min_value = 0, int64 max_value = std::numeric_limits<int32>::max()) {
|
||||||
if (request.name_ != name) {
|
if (request.name_ != name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -7360,13 +7360,13 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
|
|||||||
G()->shared_config().set_option_empty(name);
|
G()->shared_config().set_option_empty(name);
|
||||||
} else {
|
} else {
|
||||||
int64 value = static_cast<td_api::optionValueInteger *>(request.value_.get())->value_;
|
int64 value = static_cast<td_api::optionValueInteger *>(request.value_.get())->value_;
|
||||||
if (value < min || value > max) {
|
if (value < min_value || value > max_value) {
|
||||||
send_error_raw(id, 400,
|
send_error_raw(id, 400,
|
||||||
PSLICE() << "Option's \"" << name << "\" value " << value << " is outside of a valid range ["
|
PSLICE() << "Option's \"" << name << "\" value " << value << " is outside of a valid range ["
|
||||||
<< min << ", " << max << "]");
|
<< min_value << ", " << max_value << "]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
G()->shared_config().set_option_integer(name, clamp(value, min, max));
|
G()->shared_config().set_option_integer(name, clamp(value, min_value, max_value));
|
||||||
}
|
}
|
||||||
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
|
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
|
||||||
return true;
|
return true;
|
||||||
|
@ -134,18 +134,18 @@ uint64 Random::fast_uint64() {
|
|||||||
return static_cast<uint64>((*gen)());
|
return static_cast<uint64>((*gen)());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Random::fast(int min, int max) {
|
int Random::fast(int min_value, int max_value) {
|
||||||
if (min == std::numeric_limits<int>::min() && max == std::numeric_limits<int>::max()) {
|
if (min_value == std::numeric_limits<int>::min() && max_value == std::numeric_limits<int>::max()) {
|
||||||
// to prevent integer overflow and division by zero
|
// to prevent integer overflow and division by zero
|
||||||
min++;
|
min_value++;
|
||||||
}
|
}
|
||||||
DCHECK(min <= max);
|
DCHECK(min_value <= max_value);
|
||||||
return static_cast<int>(min + fast_uint32() % (max - min + 1)); // TODO signed_cast
|
return static_cast<int>(min_value + fast_uint32() % (max_value - min_value + 1)); // TODO signed_cast
|
||||||
}
|
}
|
||||||
|
|
||||||
double Random::fast(double min, double max) {
|
double Random::fast(double min_value, double max_value) {
|
||||||
DCHECK(min <= max);
|
DCHECK(min_value <= max_value);
|
||||||
return min + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max - min);
|
return min_value + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max_value - min_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Random::fast_bool() {
|
bool Random::fast_bool() {
|
||||||
@ -179,11 +179,11 @@ uint64 Random::Xorshift128plus::operator()() {
|
|||||||
return seed_[1] + y;
|
return seed_[1] + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Random::Xorshift128plus::fast(int min, int max) {
|
int Random::Xorshift128plus::fast(int min_value, int max_value) {
|
||||||
return static_cast<int>((*this)() % (max - min + 1) + min);
|
return static_cast<int>((*this)() % (max_value - min_value + 1) + min_value);
|
||||||
}
|
}
|
||||||
int64 Random::Xorshift128plus::fast64(int64 min, int64 max) {
|
int64 Random::Xorshift128plus::fast64(int64 min_value, int64 max_value) {
|
||||||
return static_cast<int64>((*this)() % (max - min + 1) + min);
|
return static_cast<int64>((*this)() % (max_value - min_value + 1) + min_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Random::Xorshift128plus::bytes(MutableSlice dest) {
|
void Random::Xorshift128plus::bytes(MutableSlice dest) {
|
||||||
|
@ -32,9 +32,9 @@ class Random {
|
|||||||
static uint32 fast_uint32();
|
static uint32 fast_uint32();
|
||||||
static uint64 fast_uint64();
|
static uint64 fast_uint64();
|
||||||
|
|
||||||
// distribution is not uniform, min and max are included
|
// distribution is not uniform, min_value and max_value are included
|
||||||
static int fast(int min, int max);
|
static int fast(int min_value, int max_value);
|
||||||
static double fast(double min, double max);
|
static double fast(double min_value, double max_value);
|
||||||
static bool fast_bool();
|
static bool fast_bool();
|
||||||
|
|
||||||
class Fast {
|
class Fast {
|
||||||
@ -48,8 +48,8 @@ class Random {
|
|||||||
explicit Xorshift128plus(uint64 seed);
|
explicit Xorshift128plus(uint64 seed);
|
||||||
Xorshift128plus(uint64 seed_a, uint64 seed_b);
|
Xorshift128plus(uint64 seed_a, uint64 seed_b);
|
||||||
uint64 operator()();
|
uint64 operator()();
|
||||||
int fast(int min, int max);
|
int fast(int min_value, int max_value);
|
||||||
int64 fast64(int64 min, int64 max);
|
int64 fast64(int64 min_value, int64 max_value);
|
||||||
void bytes(MutableSlice dest);
|
void bytes(MutableSlice dest);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -790,10 +790,10 @@ const NativeFd &UdpSocketFd::get_native_fd() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if TD_PORT_POSIX
|
#if TD_PORT_POSIX
|
||||||
static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
|
static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max_size) {
|
||||||
if (setsockopt(socket_fd, SOL_SOCKET, optname, &max, sizeof(max)) == 0) {
|
if (setsockopt(socket_fd, SOL_SOCKET, optname, &max_size, sizeof(max_size)) == 0) {
|
||||||
// fast path
|
// fast path
|
||||||
return max;
|
return max_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start with the default size. */
|
/* Start with the default size. */
|
||||||
@ -807,32 +807,32 @@ static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Binary-search for the real maximum. */
|
/* Binary-search for the real maximum. */
|
||||||
uint32 last_good = old_size;
|
uint32 last_good_size = old_size;
|
||||||
uint32 min = old_size;
|
uint32 min_size = old_size;
|
||||||
while (min <= max) {
|
while (min_size <= max_size) {
|
||||||
uint32 avg = min + (max - min) / 2;
|
uint32 avg_size = min_size + (max_size - min_size) / 2;
|
||||||
if (setsockopt(socket_fd, SOL_SOCKET, optname, &avg, sizeof(avg)) == 0) {
|
if (setsockopt(socket_fd, SOL_SOCKET, optname, &avg_size, sizeof(avg_size)) == 0) {
|
||||||
last_good = avg;
|
last_good_size = avg_size;
|
||||||
min = avg + 1;
|
min_size = avg_size + 1;
|
||||||
} else {
|
} else {
|
||||||
max = avg - 1;
|
max_size = avg_size - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return last_good;
|
return last_good_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {
|
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max_size) {
|
||||||
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max);
|
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max_size == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) {
|
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max_size) {
|
||||||
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max);
|
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max_size == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max_size);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {
|
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max_size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) {
|
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max_size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,8 +45,8 @@ class UdpSocketFd {
|
|||||||
UdpSocketFd(const UdpSocketFd &) = delete;
|
UdpSocketFd(const UdpSocketFd &) = delete;
|
||||||
UdpSocketFd &operator=(const UdpSocketFd &) = delete;
|
UdpSocketFd &operator=(const UdpSocketFd &) = delete;
|
||||||
|
|
||||||
Result<uint32> maximize_snd_buffer(uint32 max_buffer_size = 0);
|
Result<uint32> maximize_snd_buffer(uint32 max_size = 0);
|
||||||
Result<uint32> maximize_rcv_buffer(uint32 max_buffer_size = 0);
|
Result<uint32> maximize_rcv_buffer(uint32 max_size = 0);
|
||||||
|
|
||||||
static Result<UdpSocketFd> open(const IPAddress &address) TD_WARN_UNUSED_RESULT;
|
static Result<UdpSocketFd> open(const IPAddress &address) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user