mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Connection::Receive(): receive Network Packet instead of SharedBuffer<u8>.
Because we get a Buffer<u8> from ConnectionEvent, don't convert it to SharedBuffer<u8> and return it to Server/Client::Receive which will convert it to NetworkPacket Instead, put the Buffer<u8> directly to NetworkPacket and return it to packet processing This remove a long existing memory copy Also check the packet size directly into Connection::Receive instead of packet processing
This commit is contained in:
parent
ab77bf98ee
commit
1fe4256462
9 changed files with 104 additions and 98 deletions
|
@ -22,17 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "exceptions.h"
|
||||
#include "util/serialize.h"
|
||||
|
||||
NetworkPacket::NetworkPacket(u8 *data, u32 datasize, u16 peer_id):
|
||||
m_read_offset(0), m_peer_id(peer_id)
|
||||
{
|
||||
m_read_offset = 0;
|
||||
m_datasize = datasize - 2;
|
||||
|
||||
// split command and datas
|
||||
m_command = readU16(&data[0]);
|
||||
m_data = std::vector<u8>(&data[2], &data[2 + m_datasize]);
|
||||
}
|
||||
|
||||
NetworkPacket::NetworkPacket(u16 command, u32 datasize, u16 peer_id):
|
||||
m_datasize(datasize), m_read_offset(0), m_command(command), m_peer_id(peer_id)
|
||||
{
|
||||
|
@ -50,6 +39,20 @@ NetworkPacket::~NetworkPacket()
|
|||
m_data.clear();
|
||||
}
|
||||
|
||||
void NetworkPacket::putRawPacket(u8 *data, u32 datasize, u16 peer_id)
|
||||
{
|
||||
// If a m_command is already set, we are rewriting on same packet
|
||||
// This is not permitted
|
||||
assert(m_command == 0);
|
||||
|
||||
m_datasize = datasize - 2;
|
||||
m_peer_id = peer_id;
|
||||
|
||||
// split command and datas
|
||||
m_command = readU16(&data[0]);
|
||||
m_data = std::vector<u8>(&data[2], &data[2 + m_datasize]);
|
||||
}
|
||||
|
||||
char* NetworkPacket::getString(u32 from_offset)
|
||||
{
|
||||
if (from_offset >= m_datasize)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue