From fe02a19f1795429c110e6c7ed76d333cb42a3072 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 21 May 2011 12:25:08 +0300 Subject: Cleaned networking code a bit (had this one on the to-do list for like 4 months already) --- src/connection.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/connection.cpp') diff --git a/src/connection.cpp b/src/connection.cpp index b07e0de90..548a7f532 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -320,7 +320,7 @@ IncomingSplitBuffer::~IncomingSplitBuffer() This will throw a GotSplitPacketException when a full split packet is constructed. */ -void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) +SharedBuffer IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) { u32 headersize = BASE_HEADER_SIZE + 7; assert(p.data.getSize() >= headersize); @@ -363,9 +363,9 @@ void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) // Set chunk data in buffer sp->chunks[chunk_num] = chunkdata; - // If not all chunks are received, return + // If not all chunks are received, return empty buffer if(sp->allReceived() == false) - return; + return SharedBuffer(); // Calculate total size u32 totalsize = 0; @@ -392,8 +392,8 @@ void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) // Remove sp from buffer m_buf.remove(seqnum); delete sp; - - throw GotSplitPacketException(fulldata); + + return fulldata; } void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout) { @@ -709,21 +709,17 @@ SharedBuffer Channel::ProcessPacket( con->GetProtocolID(), peer_id, channelnum); - try{ - // Buffer the packet - incoming_splits.insert(packet, reliable); - } - // This exception happens when all the pieces of a packet - // are collected. - catch(GotSplitPacketException &e) + // Buffer the packet + SharedBuffer data = incoming_splits.insert(packet, reliable); + if(data.getSize() != 0) { con->PrintInfo(); dout_con<<"RETURNING TYPE_SPLIT: Constructed full data, " - <<"size="<