Skip to content

Commit

Permalink
queued_commands must be a std::deque. RunCommandQueues needs to push …
Browse files Browse the repository at this point in the history
…packet on front, not back
  • Loading branch information
nerzhul committed Mar 29, 2015
1 parent 3444dec commit dfe00ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/network/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,14 +1063,14 @@ void UDPPeer::PutReliableSendCommand(ConnectionCommand &c,
<<" processing reliable command for peer id: " << c.peer_id
<<" data size: " << c.data.getSize() << std::endl);
if (!processReliableSendCommand(c,max_packet_size)) {
channels[c.channelnum].queued_commands.push(c);
channels[c.channelnum].queued_commands.push_back(c);
}
}
else {
LOG(dout_con<<m_connection->getDesc()
<<" Queueing reliable command for peer id: " << c.peer_id
<<" data size: " << c.data.getSize() <<std::endl);
channels[c.channelnum].queued_commands.push(c);
channels[c.channelnum].queued_commands.push_back(c);
}
}

Expand Down Expand Up @@ -1182,25 +1182,23 @@ void UDPPeer::RunCommandQueues(
unsigned int maxtransfer)
{

for (unsigned int i = 0; i < CHANNEL_COUNT; i++)
{
for (unsigned int i = 0; i < CHANNEL_COUNT; i++) {
unsigned int commands_processed = 0;

if ((channels[i].queued_commands.size() > 0) &&
(channels[i].queued_reliables.size() < maxtransfer) &&
(commands_processed < maxcommands))
{
(commands_processed < maxcommands)) {
try {
ConnectionCommand c = channels[i].queued_commands.front();
channels[i].queued_commands.pop();
channels[i].queued_commands.pop_front();
LOG(dout_con<<m_connection->getDesc()
<<" processing queued reliable command "<<std::endl);
if (!processReliableSendCommand(c,max_packet_size)) {
LOG(dout_con<<m_connection->getDesc()
<< " Failed to queue packets for peer_id: " << c.peer_id
<< ", delaying sending of " << c.data.getSize()
<< " bytes" << std::endl);
channels[i].queued_commands.push(c);
channels[i].queued_commands.push_front(c);
}
}
catch (ItemNotFoundException &e) {
Expand Down Expand Up @@ -1328,12 +1326,10 @@ bool ConnectionSendThread::packetsQueued()
if (dynamic_cast<UDPPeer*>(&peer) == 0)
continue;

for(u16 i=0; i<CHANNEL_COUNT; i++)
{
for(u16 i=0; i < CHANNEL_COUNT; i++) {
Channel *channel = &(dynamic_cast<UDPPeer*>(&peer))->channels[i];

if (channel->queued_commands.size() > 0)
{
if (channel->queued_commands.size() > 0) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/network/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class Channel
std::queue<BufferedPacket> queued_reliables;

//queue commands prior splitting to packets
std::queue<ConnectionCommand> queued_commands;
std::deque<ConnectionCommand> queued_commands;

IncomingSplitBuffer incoming_splits;

Expand Down

0 comments on commit dfe00ab

Please sign in to comment.