Changeset 198cf2d in network-game


Ignore:
Timestamp:
Jul 15, 2013, 12:14:43 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
3de664d
Parents:
10f6fc2
Message:

MessageProcessor handles receiving multiple ACKs for the same message

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/MessageProcessor.cpp

    r10f6fc2 r198cf2d  
    22
    33#include <iostream>
     4
     5#include "Common.h"
    46
    57MessageProcessor::MessageProcessor() {
     
    3032   // add id to the NETWORK_MSG struct
    3133   if (msg->type == MSG_TYPE_ACK) {
    32       sentMessages.erase(msg->id);
     34      if (!sentMessages[msg->id].isAcked) {
     35         sentMessages[msg->id].isAcked = true;
     36         sentMessages[msg->id].timeAcked = getCurrentMillis();
     37      }
     38
     39      return -1; // don't do any further processing
    3340   }else {
    3441      NETWORK_MSG ack;
     
    5057
    5158void MessageProcessor::cleanAckedMessages() {
    52    // shouldn't be needed since I can just remove messages when I get their ACKs
     59   map<int, MessageContainer>::iterator it;
     60
     61   for(it = sentMessages.begin(); it != sentMessages.end(); it++) {
     62      if (it->second.isAcked && (getCurrentMillis() - it->second.timeAcked) > 1000)
     63         sentMessages.erase(it);
     64   }
    5365}
  • common/MessageProcessor.h

    r10f6fc2 r198cf2d  
    7373      NETWORK_MSG msg;
    7474      struct sockaddr_in clientAddr;
     75      bool isAcked;
     76      unsigned long long timeAcked;
    7577   };
    7678
  • server/server.cpp

    r10f6fc2 r198cf2d  
    149149         timeLastUpdated = curTime;
    150150
     151         msgProcessor.cleanAckedMessages();
    151152         msgProcessor.resendUnackedMessages(sock);
    152153
     
    487488
    488489      if (n >= 0) {
    489          broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed);
     490         broadcastResponse = processMessage(clientMsg, from, msgProcessor, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed);
    490491
    491492         if (broadcastResponse)
Note: See TracChangeset for help on using the changeset viewer.