mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-29 18:50:05 +00:00
Addressing clang-tidy findings
This commit is contained in:
parent
193f42318c
commit
072865d2e5
5 changed files with 24 additions and 14 deletions
|
|
@ -8,9 +8,13 @@ Checks:
|
|||
- 'performance-*'
|
||||
- '-bugprone-easily-swappable-parameters'
|
||||
- '-cppcoreguidelines-avoid-magic-numbers'
|
||||
- '-cppcoreguidelines-avoid-do-while'
|
||||
- '-cppcoreguidelines-avoid-non-const-global-variables'
|
||||
- '-cppcoreguidelines-pro-type-reinterpret-cast'
|
||||
- '-cppcoreguidelines-pro-type-union-access'
|
||||
- '-misc-include-cleaner'
|
||||
- '-misc-non-private-member-variables-in-classes'
|
||||
- '-misc-use-anonymous-namespace'
|
||||
- '-modernize-return-braced-init-list'
|
||||
- '-modernize-use-trailing-return-type'
|
||||
FormatStyle: 'file'
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace network
|
||||
namespace scwx::network
|
||||
{
|
||||
|
||||
TEST(NtpClient, Poll)
|
||||
|
|
@ -31,5 +29,4 @@ TEST(NtpClient, Poll)
|
|||
!error);
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
} // namespace scwx
|
||||
} // namespace scwx::network
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ public:
|
|||
NtpClient(NtpClient&&) noexcept;
|
||||
NtpClient& operator=(NtpClient&&) noexcept;
|
||||
|
||||
bool error();
|
||||
std::chrono::system_clock::duration time_offset() const;
|
||||
bool error();
|
||||
|
||||
[[nodiscard]] std::chrono::system_clock::duration time_offset() const;
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public:
|
|||
NtpTimestamp& operator=(NtpTimestamp&&) = default;
|
||||
|
||||
template<typename Clock = std::chrono::system_clock>
|
||||
std::chrono::time_point<Clock> ToTimePoint() const
|
||||
[[nodiscard]] std::chrono::time_point<Clock> ToTimePoint() const
|
||||
{
|
||||
// Convert NTP seconds to Unix seconds
|
||||
// Don't cast to a larger type to account for rollover, and this should
|
||||
|
|
@ -191,8 +191,8 @@ NtpClient::Impl::~Impl()
|
|||
|
||||
bool NtpClient::error()
|
||||
{
|
||||
bool returnValue = p->error_;
|
||||
p->error_ = false;
|
||||
const bool returnValue = p->error_;
|
||||
p->error_ = false;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
|
@ -273,6 +273,13 @@ void NtpClient::Impl::Poll()
|
|||
|
||||
static constexpr auto kTimeout_ = 5s;
|
||||
|
||||
if (!serverEndpoint_.has_value())
|
||||
{
|
||||
logger_->error("Server endpoint not set");
|
||||
error_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto originTimestamp =
|
||||
|
|
@ -280,7 +287,7 @@ void NtpClient::Impl::Poll()
|
|||
transmitPacket_.txTm_s = ntohl(originTimestamp.seconds_);
|
||||
transmitPacket_.txTm_f = ntohl(originTimestamp.fraction_);
|
||||
|
||||
std::size_t transmitPacketSize = sizeof(transmitPacket_);
|
||||
const std::size_t transmitPacketSize = sizeof(transmitPacket_);
|
||||
// Send NTP request
|
||||
socket_.send_to(boost::asio::buffer(&transmitPacket_, transmitPacketSize),
|
||||
*serverEndpoint_);
|
||||
|
|
@ -310,6 +317,7 @@ void NtpClient::Impl::Poll()
|
|||
catch (const std::exception& ex)
|
||||
{
|
||||
logger_->error("Error polling: {}", ex.what());
|
||||
error_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -437,7 +445,7 @@ void NtpClient::Impl::Run()
|
|||
|
||||
if (enabled_)
|
||||
{
|
||||
std::chrono::seconds pollIntervalSeconds {1u << pollInterval_};
|
||||
const std::chrono::seconds pollIntervalSeconds {1u << pollInterval_};
|
||||
pollTimer_.expires_after(pollIntervalSeconds);
|
||||
pollTimer_.async_wait(
|
||||
[this](const boost::system::error_code& e)
|
||||
|
|
@ -547,7 +555,7 @@ std::shared_ptr<NtpClient> NtpClient::Instance()
|
|||
static std::weak_ptr<NtpClient> ntpClientReference_ {};
|
||||
static std::mutex instanceMutex_ {};
|
||||
|
||||
std::unique_lock lock(instanceMutex_);
|
||||
const std::unique_lock lock(instanceMutex_);
|
||||
|
||||
std::shared_ptr<NtpClient> ntpClient = ntpClientReference_.lock();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace scwx::types::ntp
|
|||
|
||||
NtpPacket NtpPacket::Parse(const std::span<std::uint8_t> data)
|
||||
{
|
||||
NtpPacket packet;
|
||||
NtpPacket packet {};
|
||||
|
||||
assert(data.size() >= sizeof(NtpPacket));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue