Minor fixes.

GitOrigin-RevId: a4aacfa1ecab2718475d32bcbd99f9671ba7e982
This commit is contained in:
levlam 2020-08-14 22:51:10 +03:00
parent 9c40e37288
commit f266aa3912
11 changed files with 27 additions and 16 deletions

View File

@ -1,4 +1,3 @@
#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
#define __SQLITESESSION_H_ 1

View File

@ -25,6 +25,7 @@
#include "td/utils/Status.h"
#include "td/utils/Time.h"
#include <limits>
#include <map>
namespace td {

View File

@ -17,7 +17,6 @@
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/SequenceDispatcher.h"
#include "td/telegram/StateManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
#include "td/telegram/secret_api.h"
@ -34,7 +33,6 @@
#include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"

View File

@ -7,7 +7,6 @@
#pragma once
#include "td/telegram/logevent/SecretChatEvent.h"
#include "td/telegram/PtsManager.h"
#include "td/telegram/SecretChatActor.h"
#include "td/telegram/SecretChatId.h"
@ -17,6 +16,7 @@
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Time.h"
#include <map>

View File

@ -22,6 +22,7 @@
#include "td/utils/Time.h"
#include <functional>
#include <iterator>
#include <utility>
namespace td {

View File

@ -189,12 +189,12 @@ Result<SqliteDb> SqliteDb::do_open_with_key(CSlice path, const DbKey &db_key, in
auto key = db_key_to_sqlcipher_key(db_key);
TRY_STATUS(db.exec(PSLICE() << "PRAGMA key = " << key));
if (cipher_version != 0) {
LOG(INFO) << "Try Sqlcipher compatibility mode with version=" << cipher_version;
LOG(INFO) << "Trying SQLCipher compatibility mode with version = " << cipher_version;
TRY_STATUS(db.exec(PSLICE() << "PRAGMA cipher_compatibility = " << cipher_version));
}
db.set_cipher_version(cipher_version);
}
TRY_STATUS_PREFIX(db.check_encryption(), "Can't open database: ");
db.set_cipher_version(cipher_version);
return std::move(db);
}

View File

@ -12,10 +12,8 @@
#include "td/db/binlog/BinlogInterface.h"
#include "td/utils/misc.h"
#include "td/utils/port/Clocks.h"
#include "td/utils/Random.h"
#include "td/utils/StorerBase.h"
#include "td/utils/Time.h"
#include "td/utils/tl_helpers.h"
#include "td/utils/tl_parsers.h"
#include "td/utils/tl_storers.h"

View File

@ -6,16 +6,24 @@
//
#include "td/utils/port/Clocks.h"
#include "td/utils/port/platform.h"
#include <chrono>
#include <ctime>
#if TD_PORT_POSIX
#include <time.h>
#endif
namespace td {
double Clocks::monotonic() {
// TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows
#if TD_PORT_POSIX
// use system specific functions, because std::chrono::steady_clock is steady only under Windows
#ifdef CLOCK_BOOTTIME
{
static bool skip = []() {
static bool skip = [] {
struct timespec spec;
return clock_gettime(CLOCK_BOOTTIME, &spec) != 0;
}();
@ -27,7 +35,7 @@ double Clocks::monotonic() {
#endif
#ifdef CLOCK_MONOTONIC_RAW
{
static bool skip = []() {
static bool skip = [] {
struct timespec spec;
return clock_gettime(CLOCK_MONOTONIC_RAW, &spec) != 0;
}();
@ -37,6 +45,9 @@ double Clocks::monotonic() {
}
}
#endif
#endif
auto duration = std::chrono::steady_clock::now().time_since_epoch();
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
}

View File

@ -16,7 +16,6 @@ char disable_linker_warning_about_empty_file_event_fd_bsd_cpp TD_UNUSED;
#include "td/utils/port/PollFlags.h"
#include "td/utils/port/SocketFd.h"
#include "td/utils/Slice.h"
#include "td/utils/Time.h"
#include <cerrno>

View File

@ -15,6 +15,8 @@
#include "td/utils/port/sleep.h"
#include "td/utils/port/thread.h"
#include "td/utils/port/thread_local.h"
#include "td/utils/Random.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Slice.h"
#include "td/utils/tests.h"
#include "td/utils/Time.h"
@ -219,6 +221,7 @@ TEST(Port, SignalsAndThread) {
//LOG(ERROR) << addrs;
}
}
TEST(Port, EventFdAndSignals) {
set_signal_handler(SignalType::User, [](int signal) {}).ensure();
SCOPE_EXIT {
@ -239,7 +242,7 @@ TEST(Port, EventFdAndSignals) {
for (int timeout_ms : {0, 1, 2, 10, 100, 500}) {
double min_diff = 10000000;
double max_diff = 0;
for (int t = 0; t < max(5, 1000 / max(timeout_ms, 1)); t++) {
for (int t = 0; t < max(5, 1000 / td::max(timeout_ms, 1)); t++) {
td::EventFd event_fd;
event_fd.init();
auto start = td::Timestamp::now();
@ -247,13 +250,13 @@ TEST(Port, EventFdAndSignals) {
auto end = td::Timestamp::now();
auto passed = end.at() - start.at();
auto diff = passed * 1000 - timeout_ms;
min_diff = min(min_diff, diff);
max_diff = max(max_diff, diff);
min_diff = td::min(min_diff, diff);
max_diff = td::max(max_diff, diff);
}
LOG_CHECK(min_diff >= 0) << min_diff;
LOG_CHECK(max_diff < 10) << max_diff;
LOG(ERROR) << min_diff << " " << max_diff;
LOG(INFO) << min_diff << " " << max_diff;
}
flag.clear();
}

View File

@ -29,6 +29,7 @@
#include "td/utils/Status.h"
#include "td/utils/tests.h"
#include <atomic>
#include <cstdio>
#include <functional>
#include <map>