aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-03-31 10:35:51 +0200
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-31 11:01:08 +0200
commit1fe4256462826c218ed9bf171be4c07e0db33e25 (patch)
tree8c07a04333c23599376327e847d030cfe6bec162 /src/client.cpp
parentab77bf98ee320835e5dc50ed9b013442221f96e8 (diff)
downloadminetest-1fe4256462826c218ed9bf171be4c07e0db33e25.tar.gz
minetest-1fe4256462826c218ed9bf171be4c07e0db33e25.tar.bz2
minetest-1fe4256462826c218ed9bf171be4c07e0db33e25.zip
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
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 611a73bb1..dc2b54e9b 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -834,10 +834,9 @@ void Client::ReceiveAll()
void Client::Receive()
{
DSTACK(__FUNCTION_NAME);
- SharedBuffer<u8> data;
- u16 sender_peer_id;
- u32 datasize = m_con.Receive(sender_peer_id, data);
- ProcessData(*data, datasize, sender_peer_id);
+ NetworkPacket pkt;
+ m_con.Receive(&pkt);
+ ProcessData(&pkt);
}
inline void Client::handleCommand(NetworkPacket* pkt)
@@ -849,19 +848,12 @@ inline void Client::handleCommand(NetworkPacket* pkt)
/*
sender_peer_id given to this shall be quaranteed to be a valid peer
*/
-void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
+void Client::ProcessData(NetworkPacket *pkt)
{
DSTACK(__FUNCTION_NAME);
- // Ignore packets that don't even fit a command
- if(datasize < 2) {
- m_packetcounter.add(60000);
- return;
- }
-
- NetworkPacket pkt(data, datasize, sender_peer_id);
-
- ToClientCommand command = (ToClientCommand) pkt.getCommand();
+ ToClientCommand command = (ToClientCommand) pkt->getCommand();
+ u32 sender_peer_id = pkt->getPeerId();
//infostream<<"Client: received command="<<command<<std::endl;
m_packetcounter.add((u16)command);
@@ -889,7 +881,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
* as a byte mask
*/
if(toClientCommandTable[command].state == TOCLIENT_STATE_NOT_CONNECTED) {
- handleCommand(&pkt);
+ handleCommand(pkt);
return;
}
@@ -904,7 +896,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
Handle runtime commands
*/
- handleCommand(&pkt);
+ handleCommand(pkt);
}
void Client::Send(NetworkPacket* pkt)