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