From 1fe4256462826c218ed9bf171be4c07e0db33e25 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Tue, 31 Mar 2015 10:35:51 +0200 Subject: Connection::Receive(): receive Network Packet instead of SharedBuffer. Because we get a Buffer from ConnectionEvent, don't convert it to SharedBuffer and return it to Server/Client::Receive which will convert it to NetworkPacket Instead, put the Buffer 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 --- src/client.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/client.cpp') 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 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="<