From f266aa3912bef891abc5dbd9b1801e24b8953c0d Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 14 Aug 2020 22:51:10 +0300 Subject: [PATCH] Minor fixes. GitOrigin-RevId: a4aacfa1ecab2718475d32bcbd99f9671ba7e982 --- sqlite/sqlite/sqlite3session.h | 1 - td/telegram/ConfigManager.h | 1 + td/telegram/SecretChatsManager.cpp | 2 -- td/telegram/SecretChatsManager.h | 2 +- tdactor/td/actor/impl/Scheduler.cpp | 1 + tddb/td/db/SqliteDb.cpp | 4 ++-- tddb/td/db/TQueue.cpp | 2 -- tdutils/td/utils/port/Clocks.cpp | 17 ++++++++++++++--- tdutils/td/utils/port/detail/EventFdBsd.cpp | 1 - tdutils/test/port.cpp | 11 +++++++---- test/tdclient.cpp | 1 + 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/sqlite/sqlite/sqlite3session.h b/sqlite/sqlite/sqlite3session.h index 1ed3b550f..aac6342d7 100644 --- a/sqlite/sqlite/sqlite3session.h +++ b/sqlite/sqlite/sqlite3session.h @@ -1,4 +1,3 @@ - #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) #define __SQLITESESSION_H_ 1 diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 1d92ab760..3a0190f54 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -25,6 +25,7 @@ #include "td/utils/Status.h" #include "td/utils/Time.h" +#include #include namespace td { diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 5925b5335..89ec4c399 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -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" diff --git a/td/telegram/SecretChatsManager.h b/td/telegram/SecretChatsManager.h index 2e052fadb..06bf1b47a 100644 --- a/td/telegram/SecretChatsManager.h +++ b/td/telegram/SecretChatsManager.h @@ -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 diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index ef2b9fd91..69c48a2f4 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -22,6 +22,7 @@ #include "td/utils/Time.h" #include +#include #include namespace td { diff --git a/tddb/td/db/SqliteDb.cpp b/tddb/td/db/SqliteDb.cpp index ec23a50c5..a251079ee 100644 --- a/tddb/td/db/SqliteDb.cpp +++ b/tddb/td/db/SqliteDb.cpp @@ -189,12 +189,12 @@ Result 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); } diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp index 2a9509a41..6c703de82 100644 --- a/tddb/td/db/TQueue.cpp +++ b/tddb/td/db/TQueue.cpp @@ -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" diff --git a/tdutils/td/utils/port/Clocks.cpp b/tdutils/td/utils/port/Clocks.cpp index f9495c21a..2053ceef1 100644 --- a/tdutils/td/utils/port/Clocks.cpp +++ b/tdutils/td/utils/port/Clocks.cpp @@ -6,16 +6,24 @@ // #include "td/utils/port/Clocks.h" +#include "td/utils/port/platform.h" + #include #include +#if TD_PORT_POSIX +#include +#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(std::chrono::duration_cast(duration).count()) * 1e-9; } diff --git a/tdutils/td/utils/port/detail/EventFdBsd.cpp b/tdutils/td/utils/port/detail/EventFdBsd.cpp index aa8648c10..3544069d9 100644 --- a/tdutils/td/utils/port/detail/EventFdBsd.cpp +++ b/tdutils/td/utils/port/detail/EventFdBsd.cpp @@ -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 diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index a2f2bd2d3..2ca0b2aa2 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -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(); } diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 7b421231b..34ab41348 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -29,6 +29,7 @@ #include "td/utils/Status.h" #include "td/utils/tests.h" +#include #include #include #include