Code optimizations
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
|
||||
namespace std
|
||||
{
|
||||
class BitConverter
|
||||
class ByteConverter
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
@ -24,7 +24,7 @@ namespace std
|
||||
inline static T FromBytes(uint8_t *data)
|
||||
{
|
||||
if (!data)
|
||||
throw std::invalid_argument("cant have null parameter -> BitConverter::FromBytes");
|
||||
throw std::invalid_argument("cant have null parameter -> ByteConverter::FromBytes");
|
||||
T value;
|
||||
memcpy(&value, data, sizeof(T));
|
||||
return value;
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "NetworkHeader.hpp"
|
||||
#include "BitConverter.hpp"
|
||||
#include "ByteConverter.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
@ -68,9 +68,9 @@ namespace std::net
|
||||
uint8_t *bytes = new uint8_t[header.Size];
|
||||
memcpy(bytes, &header, sizeOfNetHeader);
|
||||
|
||||
uint8_t *sender = BitConverter::ToBytes<uint32_t>(m_senderID); // 4
|
||||
uint8_t *destination = BitConverter::ToBytes<uint32_t>(m_destinationID); // 4
|
||||
uint8_t *tag = BitConverter::ToBytes<uint32_t>(m_tag); // 4
|
||||
uint8_t *sender = ByteConverter::ToBytes<uint32_t>(m_senderID); // 4
|
||||
uint8_t *destination = ByteConverter::ToBytes<uint32_t>(m_destinationID); // 4
|
||||
uint8_t *tag = ByteConverter::ToBytes<uint32_t>(m_tag); // 4
|
||||
|
||||
memcpy(bytes + sizeOfNetHeader, sender, 4);
|
||||
bytes[sizeOfNetHeader + 4] = (uint8_t)m_distributionMode;
|
||||
|
||||
@ -20,7 +20,5 @@ namespace std::net
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::net::TcpServer> m_tcpServer;
|
||||
|
||||
std::shared_ptr<MessageQueue> m_queue;
|
||||
};
|
||||
}
|
||||
@ -7,18 +7,12 @@
|
||||
#include <TcpListener.hpp>
|
||||
#include <TcpConnection.hpp>
|
||||
|
||||
//#include <BaseLibrary/SpinMutex.hpp>
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
class MessageQueue;
|
||||
class TcpConnection;
|
||||
class Server;
|
||||
|
||||
namespace sockets
|
||||
{
|
||||
class TcpListener;
|
||||
}
|
||||
class TcpListener;
|
||||
}
|
||||
|
||||
namespace std::net
|
||||
@ -49,7 +43,7 @@ namespace std::net
|
||||
std::vector<std::shared_ptr<TcpConnection>> m_list;
|
||||
std::mutex m_listMutex;
|
||||
|
||||
uint32_t m_maxConnections;
|
||||
uint32_t m_maxConnections = 0;
|
||||
|
||||
std::thread m_receiveThread;
|
||||
std::thread m_sendThread;
|
||||
@ -59,5 +53,7 @@ namespace std::net
|
||||
std::shared_ptr<MessageQueue> m_queue;
|
||||
|
||||
std::shared_ptr<TcpListener> m_listenerPtr;
|
||||
|
||||
std::vector<pollfd> poll_fds;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user