Skip to content

Commit

Permalink
[Hotfix] Copy/move assignment operators for Packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Pusnow committed Nov 16, 2021
1 parent aa24a80 commit c74958d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/E/Networking/E_Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Packet : public Module::MessageBase {
private:
Packet(UUID uuid, size_t maxSize);
std::vector<char> buffer;
const size_t bufferSize;
size_t bufferSize;
size_t dataSize;

const UUID packetID;
UUID packetID;

static std::unordered_set<UUID> packetUUIDSet;
static UUID packetUUIDStart;
Expand All @@ -48,6 +48,18 @@ class Packet : public Module::MessageBase {
*/
Packet(Packet &&other) noexcept;

/**
* Copy assignment operator. (Copied packet has same UUID)
* @param other Packet to copy.
*/
Packet &operator=(const Packet &other);

/**
* Move assignment operator. (Moved packet become emtpy)
* @param other Packet to move.
*/
Packet &operator=(Packet &&other) noexcept;

/**
* @param maxSize Maximum packet size.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Networking/E_Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ Packet::Packet(Packet &&other) noexcept
other.dataSize = 0;
}

Packet &Packet::operator=(const Packet &other) {
buffer = other.buffer;
bufferSize = other.bufferSize;
dataSize = other.dataSize;
packetID = other.packetID;
return *this;
}

Packet &Packet::operator=(Packet &&other) noexcept {
buffer = std::move(other.buffer);
bufferSize = std::move(other.bufferSize);
dataSize = std::move(other.dataSize);
packetID = std::move(other.packetID);
return *this;
}

Packet::Packet(size_t maxSize) : Packet(allocatePacketUUID(), maxSize) {}

Packet::~Packet() { freePacketUUID(this->packetID); }
Expand Down

0 comments on commit c74958d

Please sign in to comment.