RunCommandQueues: little optimization
authorLoic Blot <loic.blot@unix-experience.fr>
Tue, 31 Mar 2015 07:22:44 +0000 (09:22 +0200)
committerLoic Blot <loic.blot@unix-experience.fr>
Tue, 31 Mar 2015 07:29:33 +0000 (09:29 +0200)
remove command from queue on success, else do nothing, instead of remove command from queue and push it front on success

src/network/connection.cpp

index 5ea739dd4cc82abeea50285fd682405560bba17d..b808c3ab60d7f0e6553b7e0955a97ae0c878cf30 100644 (file)
@@ -1190,15 +1190,18 @@ void UDPPeer::RunCommandQueues(
                                (commands_processed < maxcommands)) {
                        try {
                                ConnectionCommand c = channels[i].queued_commands.front();
-                               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()
+
+                               LOG(dout_con << m_connection->getDesc()
+                                               << " processing queued reliable command " << std::endl);
+
+                               // Packet is processed, remove it from queue
+                               if (processReliableSendCommand(c,max_packet_size)) {
+                                       channels[i].queued_commands.pop_front();
+                               } else {
+                                       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_front(c);
                                }
                        }
                        catch (ItemNotFoundException &e) {