diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-05-21 12:25:08 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-05-21 12:25:08 +0300 |
commit | fe02a19f1795429c110e6c7ed76d333cb42a3072 (patch) | |
tree | fb422c8acb96aea2d814b44ceb86c28f8ceb0e4c /src/connection.cpp | |
parent | 3b707b8a4a52a88da4398ec9b32109c073683a76 (diff) | |
download | minetest-fe02a19f1795429c110e6c7ed76d333cb42a3072.tar.gz minetest-fe02a19f1795429c110e6c7ed76d333cb42a3072.tar.bz2 minetest-fe02a19f1795429c110e6c7ed76d333cb42a3072.zip |
Cleaned networking code a bit (had this one on the to-do list for like 4 months already)
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 26 |
1 files changed, 11 insertions, 15 deletions
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<u8> 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<u8>(); // 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<u8> 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<u8> data = incoming_splits.insert(packet, reliable); + if(data.getSize() != 0) { con->PrintInfo(); dout_con<<"RETURNING TYPE_SPLIT: Constructed full data, " - <<"size="<<e.getData().getSize()<<std::endl; - return e.getData(); + <<"size="<<data.getSize()<<std::endl; + return data; } con->PrintInfo(); - dout_con<<"BUFFERING TYPE_SPLIT"<<std::endl; + dout_con<<"BUFFERED TYPE_SPLIT"<<std::endl; throw ProcessedSilentlyException("Buffered a split packet chunk"); } else if(type == TYPE_RELIABLE) |