Changeset 7878 for code/branches/network6
- Timestamp:
- Feb 13, 2011, 9:34:22 PM (14 years ago)
- Location:
- code/branches/network6/src/libraries/network
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network6/src/libraries/network/Client.cc
r7801 r7878 207 207 if( packet->isReliable() ) 208 208 { 209 if( this->getLast ProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )209 if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 210 210 packet->process(static_cast<Host*>(this)); 211 211 else -
code/branches/network6/src/libraries/network/ClientConnection.cc
r7825 r7878 123 123 return true; 124 124 this->established_ = false; 125 126 // stop communication thread and disconnect server 125 127 Connection::stopCommunicationThread(); 126 128 enet_peer_disconnect(this->server_, 0); -
code/branches/network6/src/libraries/network/Connection.cc
r7825 r7878 38 38 39 39 #include "packet/Packet.h" 40 #include <util/Sleep.h> 40 41 41 42 namespace orxonox 42 43 { 43 44 const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20); 45 const unsigned int NETWORK_DISCONNECT_TIMEOUT = 500; 44 46 45 47 Connection::Connection(uint32_t firstPeerID): … … 50 52 this->incomingEventsMutex_ = new boost::mutex; 51 53 this->outgoingEventsMutex_ = new boost::mutex; 54 this->overallMutex_ = new boost::mutex; 52 55 } 53 56 … … 77 80 void Connection::disconnectPeer(uint32_t peerID) 78 81 { 82 this->overallMutex_->lock(); 79 83 outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, 0, 0 }; 80 84 … … 82 86 this->outgoingEvents_.push_back(outEvent); 83 87 this->outgoingEventsMutex_->unlock(); 88 this->overallMutex_->unlock(); 84 89 } 85 90 … … 95 100 void Connection::addPacket(ENetPacket* packet, uint32_t peerID, uint8_t channelID) 96 101 { 102 this->overallMutex_->lock(); 97 103 outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID }; 98 104 … … 100 106 this->outgoingEvents_.push_back(outEvent); 101 107 this->outgoingEventsMutex_->unlock(); 108 this->overallMutex_->unlock(); 102 109 } 103 110 104 111 void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID) 105 112 { 113 this->overallMutex_->lock(); 106 114 outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID }; 107 115 … … 109 117 this->outgoingEvents_.push_back(outEvent); 110 118 this->outgoingEventsMutex_->unlock(); 119 this->overallMutex_->unlock(); 111 120 } 112 121 … … 116 125 ENetEvent event; 117 126 127 this->overallMutex_->lock(); 118 128 while( bCommunicationThreadRunning_ ) 119 129 { … … 123 133 processIncomingEvent(event); 124 134 } 135 136 this->overallMutex_->unlock(); 137 msleep(10); 138 this->overallMutex_->lock(); 125 139 126 140 // Send all waiting outgoing packets … … 149 163 } 150 164 } 165 this->overallMutex_->unlock(); 151 166 } 152 167 … … 209 224 break; 210 225 case outgoingEventType::disconnectPeers: 211 while( this->peerMap_.size()!=0 ) 212 { 213 peer = this->peerMap_.begin()->second; 214 enet_peer_disconnect(peer, 0); 215 } 226 disconnectPeersInternal(); 216 227 break; 217 228 case outgoingEventType::broadcastPacket: … … 223 234 } 224 235 236 237 void Connection::disconnectPeersInternal() 238 { 239 std::map<uint32_t, ENetPeer*>::iterator it; 240 for( it=this->peerMap_.begin(); it!=this->peerMap_.end(); ++it ) 241 { 242 enet_peer_disconnect(it->second, 0); 243 } 244 uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT; 245 uint32_t i = 0; 246 while( this->peerMap_.size() && i++ < iterations ) 247 { 248 ENetEvent event; 249 if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 250 { 251 processIncomingEvent(event); 252 } 253 } 254 } 225 255 226 256 void Connection::processQueue() … … 261 291 } 262 292 } 293 294 void Connection::waitOutgoingQueue() 295 { 296 uint32_t outgoingEventsCount; 297 this->outgoingEventsMutex_->lock(); 298 outgoingEventsCount = this->outgoingEvents_.size(); 299 this->outgoingEventsMutex_->unlock(); 300 while( outgoingEventsCount ) 301 { 302 msleep(1); 303 this->outgoingEventsMutex_->lock(); 304 outgoingEventsCount = this->outgoingEvents_.size(); 305 this->outgoingEventsMutex_->unlock(); 306 } 307 } 308 263 309 264 310 incomingEvent Connection::preprocessConnectEvent(ENetEvent& event) -
code/branches/network6/src/libraries/network/Connection.h
r7825 r7878 118 118 119 119 void processQueue(); 120 void waitOutgoingQueue(); // wait for the outgoing queue to become empty (everything processed by communication thread) 120 121 virtual void addPeer(uint32_t peerID)=0; 121 122 virtual void removePeer(uint32_t peerID)=0; … … 128 129 void processIncomingEvent(ENetEvent& event); 129 130 void processOutgoingEvent(outgoingEvent& event); 131 132 void disconnectPeersInternal(); 130 133 131 134 ENetHost* host_; … … 140 143 boost::mutex* incomingEventsMutex_; 141 144 boost::mutex* outgoingEventsMutex_; 145 boost::mutex* overallMutex_; 142 146 std::map<uint32_t, ENetPeer*> peerMap_; 143 147 std::map<ENetPeer*, uint32_t> peerIDMap_; 144 148 uint32_t nextPeerID_; 145 146 // static Connection *instance_;147 149 148 150 }; -
code/branches/network6/src/libraries/network/GamestateHandler.h
r7801 r7878 51 51 virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0; 52 52 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0; 53 virtual uint32_t getLast ProcessedGamestateID( unsigned int clientID )=0;53 virtual uint32_t getLastReceivedGamestateID( unsigned int clientID )=0; 54 54 virtual uint32_t getCurrentGamestateID()=0; 55 55 }; -
code/branches/network6/src/libraries/network/GamestateManager.cc
r7825 r7878 110 110 bool b = processGamestate(it->second); 111 111 assert(b); 112 sendAck( it->second->getID(), it->second->getPeerID() );112 // sendAck( it->second->getID(), it->second->getPeerID() ); 113 113 delete it->second; 114 114 } … … 122 122 bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID) 123 123 { 124 assert( gamestateID != ACKID_NACK ); 124 125 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID); 125 126 if( !this->sendPacket(ack)) … … 151 152 { 152 153 assert(peerMap_.size()!=0); 153 newID = peerMap_[NETWORK_PEER_ID_SERVER].last ProcessedGamestateID;154 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID; 154 155 } 155 156 … … 190 191 } 191 192 192 peerGamestates.push_back(0); // insert an empty gamestate* to change193 peerGamestates.push_back(0); // insert an empty gamestate* to be changed 193 194 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 194 195 if( peerGamestates.back()==0 ) … … 266 267 unsigned int curid = it->second.lastAckedGamestateID; 267 268 268 if(gamestateID == ACKID_NACK){ 269 it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 270 // temp->setGamestateID(GAMESTATEID_INITIAL); 271 // now delete all saved gamestates for this client 272 std::map<uint32_t, packet::Gamestate*>::iterator it2; 273 for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 274 delete it2->second; 275 } 276 it->second.gamestates.clear(); 277 return true; 278 } 269 assert(gamestateID != ACKID_NACK); 270 // if(gamestateID == ACKID_NACK){ 271 // it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 272 // // temp->setGamestateID(GAMESTATEID_INITIAL); 273 // // now delete all saved gamestates for this client 274 // std::map<uint32_t, packet::Gamestate*>::iterator it2; 275 // for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 276 // delete it2->second; 277 // } 278 // it->second.gamestates.clear(); 279 // return true; 280 // } 279 281 280 282 assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); … … 303 305 } 304 306 305 uint32_t GamestateManager::getLast ProcessedGamestateID(unsigned int peerID)307 uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID) 306 308 { 307 309 assert( this->peerMap_.find(peerID)!=this->peerMap_.end() ); 308 310 if( this->peerMap_.find(peerID) != this->peerMap_.end() ) 309 return this->peerMap_[peerID].last ProcessedGamestateID;311 return this->peerMap_[peerID].lastReceivedGamestateID; 310 312 else 311 313 return GAMESTATEID_INITIAL; … … 317 319 assert(peerMap_.find(peerID)==peerMap_.end()); 318 320 peerMap_[peerID].peerID = peerID; 319 peerMap_[peerID].last ProcessedGamestateID = GAMESTATEID_INITIAL;321 peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL; 320 322 peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL; 321 323 if( GameMode::isMaster() ) … … 363 365 if( gs->spreadData(gsMode) ) 364 366 { 365 this->peerMap_[gs->getPeerID()].last ProcessedGamestateID = gs->getID();367 this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID(); 366 368 return true; 367 369 } -
code/branches/network6/src/libraries/network/GamestateManager.h
r7823 r7878 73 73 { 74 74 uint32_t peerID; 75 uint32_t last ProcessedGamestateID;76 uint32_t lastAckedGamestateID; 75 uint32_t lastReceivedGamestateID; //!< id of the last gamestate which was received (and processed) from the peer 76 uint32_t lastAckedGamestateID; //!< id of the last gamestate on which we received an ack from the peer 77 77 bool isSynched; 78 78 std::map< uint32_t, packet::Gamestate* > gamestates; … … 86 86 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID); 87 87 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID); 88 virtual uint32_t getLast ProcessedGamestateID( unsigned int peerID );88 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ); 89 89 virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); } 90 90 -
code/branches/network6/src/libraries/network/Server.cc
r7823 r7878 380 380 if( packet->isReliable() ) 381 381 { 382 if( this->getLast ProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )382 if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 383 383 packet->process(static_cast<Host*>(this)); 384 384 else -
code/branches/network6/src/libraries/network/ServerConnection.cc
r7823 r7878 35 35 36 36 #include "util/Debug.h" 37 #include <util/Sleep.h> 37 38 // #include "ClientInformation.h" 38 39 … … 133 134 { 134 135 Connection::disconnectPeers(); 135 // ClientInformation *temp = ClientInformation::getBegin(); 136 // while(temp!=0) 137 // { 138 // ServerConnection::disconnectClient( temp ); 139 // temp = temp->next(); 140 // } 136 Connection::waitOutgoingQueue(); 141 137 return; 142 138 }
Note: See TracChangeset
for help on using the changeset viewer.