Changeset 8ed6c8a in network-game for common/MessageProcessor.cpp


Ignore:
Timestamp:
Jan 14, 2018, 6:44:45 PM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
8cbeffc
Parents:
e2a0a27
Message:

Debug message acks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/MessageProcessor.cpp

    re2a0a27 r8ed6c8a  
    3232   msg->id = ++lastUsedId;
    3333   MessageContainer message(*msg, *dest);
     34   message.setTimeSent(getCurrentMillis());
    3435
    3536   if (outputLog)
     
    107108   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it;
    108109   map<unsigned long, MessageContainer>::iterator it2;
    109    map<unsigned long, MessageContainer> sentMsg;
     110   map<unsigned long, MessageContainer>* sentMsg;
    110111
    111112   for (it = sentMessages.begin(); it != sentMessages.end(); it++) {
    112       sentMsg = it->second;
    113       for (it2 = sentMsg.begin(); it2 != sentMsg.end(); it2++) {
     113
     114      unsigned long long maxAge = 0;
     115      sentMsg = &(it->second);
     116
     117      for (it2 = sentMsg->begin(); it2 != sentMsg->end(); it2++) {
    114118         if (!(it2->second.getAcked())) {
     119            cout << "Maybe resending message" << endl;
     120            cout << "time sent: " << it2->second.getTimeSent() << endl;
     121            unsigned long long age = getCurrentMillis() - it2->second.getTimeSent();
     122
     123            cout << "age: " << age << endl;
     124            if (maxAge < age) {
     125                maxAge = age;
     126                cout << "new max age: " << maxAge << endl;
     127            }
     128
     129            if (maxAge > 10000) {
     130               cout << "id " << it2->second.getMessage()->id << " is not getting acked" << endl;
     131               // this will prevent the message from getting resent anymore
     132               it2->second.setAcked(true);
     133               cout << "acked after being set: " << it2->second.getAcked() << endl;
     134            }
     135
    115136            sendto(sock, (const char*)it2->second.getMessage(), sizeof(NETWORK_MSG), 0, (struct sockaddr *)&it2->first, sizeof(struct sockaddr_in));
    116137         }
     138      }
     139
     140      if (maxAge > 10000) {
     141         cout << "Connection lost" << endl;
    117142      }
    118143   }
Note: See TracChangeset for help on using the changeset viewer.