diff --git a/src/Properties.h b/src/Properties.h index ec3a6c0..897d878 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -8,10 +8,12 @@ #include #include #include +#include #include #include -#include +#include #include +#include #include "misc/spin_lock.h" #include "converters/converter.h" @@ -466,9 +468,17 @@ namespace ts { */ namespace impl { - template - constexpr auto make_property_array(Properties&&... props) noexcept { - return std::array, sizeof...(Properties)>{std::forward(props)...}; + constexpr inline auto property_count() { + size_t result{0}; + result += VIRTUALSERVER_ENDMARKER; + result += CHANNEL_ENDMARKER; + result += CLIENT_ENDMARKER; + result += GROUP_ENDMARKER; + result += SERVERINSTANCE_ENDMARKER; + result += CONNECTION_ENDMARKER; + result += PLAYLIST_ENDMARKER; + result += UNKNOWN_ENDMARKER; + return result; } extern bool validateInput(const std::string& input, ValueType type); @@ -539,19 +549,7 @@ namespace ts { }; #ifdef EXTERNALIZE_PROPERTY_DEFINITIONS - constexpr inline auto property_count() { - size_t result{0}; - result += VIRTUALSERVER_ENDMARKER; - result += CHANNEL_ENDMARKER; - result += CLIENT_ENDMARKER; - result += GROUP_ENDMARKER; - result += SERVERINSTANCE_ENDMARKER; - result += CONNECTION_ENDMARKER; - result += PLAYLIST_ENDMARKER; - result += UNKNOWN_ENDMARKER; - return result; - } - extern std::array property_list; + extern std::array property_list; #else #include "./PropertyDefinition.h" @@ -784,7 +782,7 @@ namespace ts { [[nodiscard]] const property::PropertyDescription& type() const { return *this->data_ptr->description; } [[nodiscard]] std::string value() const { - std::lock_guard lock(this->data_ptr->value_lock); + std::lock_guard lock{this->data_ptr->value_lock}; return this->data_ptr->value; } diff --git a/src/PropertyDefinition.h b/src/PropertyDefinition.h index dad31c6..4c42bb5 100644 --- a/src/PropertyDefinition.h +++ b/src/PropertyDefinition.h @@ -14,7 +14,7 @@ decltype(property::property_list) property:: #else constexpr auto #endif -property_list = property::impl::make_property_array( +property_list = std::array{ PropertyDescription{UNKNOWN_UNDEFINED, "undefined", "", TYPE_UNKNOWN, 0}, /* virtual server properties */ @@ -347,7 +347,7 @@ property_list = property::impl::make_property_array( PropertyDescription{PLAYLIST_FLAG_FINISHED, "playlist_flag_finished", "0", TYPE_BOOL, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE}, PropertyDescription{PLAYLIST_REPLAY_MODE, "playlist_replay_mode", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE}, PropertyDescription{PLAYLIST_CURRENT_SONG_ID, "playlist_current_song_id", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_SAVE} -); +}; #undef str_ #undef V diff --git a/src/misc/digest.cpp b/src/misc/digest.cpp index 9176278..9f21b6e 100644 --- a/src/misc/digest.cpp +++ b/src/misc/digest.cpp @@ -1,4 +1,7 @@ +#ifndef NO_OPEN_SSL #define NO_OPEN_SSL +#endif + #include "./digest.h" #include diff --git a/src/misc/net.h b/src/misc/net.h index 6d00544..f8997df 100644 --- a/src/misc/net.h +++ b/src/misc/net.h @@ -5,8 +5,10 @@ #include #include #include +#include #ifdef WIN32 + #define _WINSOCK_DEPRECATED_NO_WARNINGS /* gethostbyname is deprecated for windows */ #include #include #include diff --git a/src/misc/strobf.h b/src/misc/strobf.h index 13eaece..f834330 100644 --- a/src/misc/strobf.h +++ b/src/misc/strobf.h @@ -72,7 +72,7 @@ namespace str_obf { static_assert(sizeof(char_t) == 1, "Currently only 8 bit supported"); if(length == 0) return; if(key.size() == 0) _invalid_key_size(); - if(key.size() & (key.size() - 1)) _invalid_key_size(); /* key must be an power of 2 */ + if(key.size() & (key.size() - 1UL)) _invalid_key_size(); /* key must be an power of 2 */ auto left = length; size_t key_index{0}; @@ -140,7 +140,7 @@ namespace str_obf { length = (std::uint64_t) ((internal::rng32_next(rng_base, (uint32_t) seed) >> 12UL) & 0xFFUL); } while(length == 0 || length > power2); - return 1U << length; + return uint64_t{1} << length; } template diff --git a/src/protocol/AcknowledgeManager.cpp b/src/protocol/AcknowledgeManager.cpp index 67f29f1..7dfd683 100644 --- a/src/protocol/AcknowledgeManager.cpp +++ b/src/protocol/AcknowledgeManager.cpp @@ -1,6 +1,7 @@ #include "AcknowledgeManager.h" #include #include +#include using namespace ts; using namespace ts::connection; @@ -107,7 +108,7 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now , } } else { if(entry->next_resend <= now) { - entry->next_resend = now + std::chrono::milliseconds{(int64_t) min(ceil(this->rto), 1500.f)}; + entry->next_resend = now + std::chrono::milliseconds{(int64_t) std::min(ceil(this->rto), 1500.f)}; need_resend.push_back(entry); entry->resend_count++; entry->send_count++; @@ -139,7 +140,7 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now , /* we're not taking the clock granularity into account because its nearly 1ms and it would only add more branches */ void AcknowledgeManager::update_rto(size_t r) { if(srtt == -1) { - this->srtt = r; + this->srtt = (float) r; this->rttvar = r / 2.f; this->rto = srtt + 4 * this->rttvar; } else { diff --git a/src/protocol/PacketLossCalculator.cpp b/src/protocol/PacketLossCalculator.cpp index 45e2bca..6a1907a 100644 --- a/src/protocol/PacketLossCalculator.cpp +++ b/src/protocol/PacketLossCalculator.cpp @@ -15,22 +15,22 @@ void UnorderedPacketLossCalculator::packet_received(uint32_t packet_id) { if(age < this->packet_history.max_bits()) { const auto received = this->packet_history.shift_in_bounds(age).count(); - this->received_packets_ += received; - this->received_packets_total_ += received; + this->received_packets_ += (uint32_t) received; + this->received_packets_total_ += (uint32_t) received; - this->lost_packets_ += age - received; - this->lost_packets_total_ += age - received; + this->lost_packets_ += (uint32_t) (age - received); + this->lost_packets_total_ += (uint32_t) (age - received); } else { const auto received = this->packet_history.clear().count(); - this->received_packets_ += received; - this->received_packets_total_ += received; - this->lost_packets_ += this->packet_history.max_bits() - received; - this->lost_packets_total_ += this->packet_history.max_bits() - received; + this->received_packets_ += (uint32_t) received; + this->received_packets_total_ += (uint32_t) received; + this->lost_packets_ += (uint32_t) (this->packet_history.max_bits() - received); + this->lost_packets_total_ += (uint32_t) (this->packet_history.max_bits() - received); if(age >= this->packet_history.max_bits() * 2) { this->packet_history.set_unchecked(0); - this->lost_packets_ += age - this->packet_history.max_bits() * 2; - this->lost_packets_total_ += age - this->packet_history.max_bits() * 2; + this->lost_packets_ += (uint32_t) (age - this->packet_history.max_bits() * 2); + this->lost_packets_total_ += (uint32_t) (age - this->packet_history.max_bits() * 2); } else { this->packet_history.set_unchecked(age - this->packet_history.max_bits()); } @@ -60,8 +60,8 @@ void UnorderedPacketLossCalculator::short_stats() { if(packets_passed < target_interval) return; const auto factor = .5; - this->received_packets_ *= factor; - this->lost_packets_ *= factor; + this->received_packets_ = (uint32_t) (this->received_packets_ * factor); + this->lost_packets_ = (uint32_t) (this->lost_packets_ * factor); this->last_history_offset = this->packet_history_offset; } diff --git a/src/protocol/PacketLossCalculator.h b/src/protocol/PacketLossCalculator.h index 74366d2..18a4a70 100644 --- a/src/protocol/PacketLossCalculator.h +++ b/src/protocol/PacketLossCalculator.h @@ -60,8 +60,8 @@ namespace ts::protocol { [[nodiscard]] inline uint32_t received_packets_total() const { return this->received_packets_total_; } [[nodiscard]] inline uint32_t lost_packets_total() const { return this->lost_packets_total_; } - [[nodiscard]] inline uint32_t unconfirmed_received_packets() const { return this->packet_history.count(); }; - [[nodiscard]] inline uint32_t unconfirmed_lost_packets() const { return this->packet_history.max_bits() - this->packet_history.count(); }; + [[nodiscard]] inline uint32_t unconfirmed_received_packets() const { return (uint32_t) this->packet_history.count(); }; + [[nodiscard]] inline uint32_t unconfirmed_lost_packets() const { return (uint32_t) (this->packet_history.max_bits() - this->packet_history.count()); }; private: uint32_t received_packets_{0}, received_packets_total_{0}, lost_packets_{0}, lost_packets_total_{0};