From 88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 19 Aug 2017 22:23:47 +0200 Subject: Code modernization: subfolders (#6283) * Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo --- src/network/connection.h | 58 +++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'src/network/connection.h') diff --git a/src/network/connection.h b/src/network/connection.h index bf192870b..c64272035 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -133,16 +133,14 @@ inline bool seqnum_higher(u16 totest, u16 base) { if ((totest - base) > (SEQNUM_MAX/2)) return false; - else - return true; - } - else - { - if ((base - totest) > (SEQNUM_MAX/2)) - return true; - else - return false; + + return true; } + + if ((base - totest) > (SEQNUM_MAX/2)) + return true; + + return false; } inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size) @@ -150,14 +148,12 @@ inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size) u16 window_start = next; u16 window_end = ( next + window_size ) % (SEQNUM_MAX+1); - if (window_start < window_end) - { + if (window_start < window_end) { return ((seqnum >= window_start) && (seqnum < window_end)); } - else - { - return ((seqnum < window_end) || (seqnum >= window_start)); - } + + + return ((seqnum < window_end) || (seqnum >= window_start)); } struct BufferedPacket @@ -166,8 +162,7 @@ struct BufferedPacket data(a_data, a_size) {} BufferedPacket(u32 a_size): - data(a_size), time(0.0), totaltime(0.0), absolute_send_time(-1), - resend_count(0) + data(a_size) {} Buffer data; // Data of the packet, including headers float time = 0.0f; // Seconds from buffering the packet or re-sending @@ -202,12 +197,13 @@ std::list > makeAutoSplitPacket( // Add the TYPE_RELIABLE header to the data SharedBuffer makeReliablePacket( - SharedBuffer data, + const SharedBuffer &data, u16 seqnum); struct IncomingSplitPacket { - IncomingSplitPacket() {} + IncomingSplitPacket() = default; + // Key is chunk number, value is data without headers std::map > chunks; u32 chunk_count; @@ -315,7 +311,7 @@ typedef std::list::iterator RPBSearchResult; class ReliablePacketBuffer { public: - ReliablePacketBuffer() {}; + ReliablePacketBuffer() = default; bool getFirstSeqnum(u16& result); @@ -410,7 +406,7 @@ struct ConnectionCommand bool reliable = false; bool raw = false; - ConnectionCommand() {} + ConnectionCommand() = default; void serve(Address address_) { @@ -501,8 +497,8 @@ public: IncomingSplitBuffer incoming_splits; - Channel() {}; - ~Channel() {}; + Channel() = default; + ~Channel() = default; void UpdatePacketLossCounter(unsigned int count); void UpdatePacketTooLateCounter(); @@ -590,12 +586,8 @@ class PeerHandler { public: - PeerHandler() - { - } - virtual ~PeerHandler() - { - } + PeerHandler() = default; + virtual ~PeerHandler() = default; /* This is called after the Peer has been inserted into the @@ -612,7 +604,7 @@ public: class PeerHelper { public: - PeerHelper() {}; + PeerHelper() = default;; PeerHelper(Peer* peer); ~PeerHelper(); @@ -744,7 +736,7 @@ class Peer { float max_rtt = 0.0f; float avg_rtt = -1.0f; - rttstats() {}; + rttstats() = default; }; rttstats m_rtt; @@ -769,7 +761,7 @@ public: friend class Connection; UDPPeer(u16 a_id, Address a_address, Connection* connection); - virtual ~UDPPeer() {}; + virtual ~UDPPeer() = default; void PutReliableSendCommand(ConnectionCommand &c, unsigned int max_packet_size); @@ -841,7 +833,7 @@ struct ConnectionEvent bool timeout = false; Address address; - ConnectionEvent() {} + ConnectionEvent() = default; std::string describe() { -- cgit v1.2.3