Changeset 1705 for code/branches/network/src/network/ConnectionManager.cc
- Timestamp:
- Sep 4, 2008, 9:45:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/ConnectionManager.cc
r1699 r1705 51 51 #include "ConnectionManager.h" 52 52 #include "Synchronisable.h" 53 #include "packet/ClassID.h" 53 54 54 55 namespace std … … 75 76 bindAddress.port = NETWORK_PORT; 76 77 } 77 boost::recursive_mutex ConnectionManager::enet_mutex _;78 boost::recursive_mutex ConnectionManager::enet_mutex; 78 79 79 80 // ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { … … 172 173 173 174 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { 174 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex _);175 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex); 175 176 if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0) 176 177 return false; … … 190 191 if(!instance_) 191 192 return false; 192 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex _);193 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex); 193 194 for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){ 194 195 COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl; … … 203 204 if(server==NULL || !instance_) 204 205 return false; 205 boost::recursive_mutex::scoped_lock lock(enet_mutex _);206 boost::recursive_mutex::scoped_lock lock(enet_mutex); 206 207 enet_host_flush(server); 207 208 lock.unlock(); … … 214 215 atexit(enet_deinitialize); 215 216 { //scope of the mutex 216 boost::recursive_mutex::scoped_lock lock(enet_mutex _);217 boost::recursive_mutex::scoped_lock lock(enet_mutex); 217 218 enet_initialize(); 218 219 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); … … 228 229 while(!quit){ 229 230 { //mutex scope 230 boost::recursive_mutex::scoped_lock lock(enet_mutex _);231 boost::recursive_mutex::scoped_lock lock(enet_mutex); 231 232 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 232 233 // we should never reach this point … … 270 271 // if we're finishied, destroy server 271 272 { 272 boost::recursive_mutex::scoped_lock lock(enet_mutex _);273 boost::recursive_mutex::scoped_lock lock(enet_mutex); 273 274 enet_host_destroy(server); 274 275 lock.unlock(); … … 284 285 while(temp!=0){ 285 286 { 286 boost::recursive_mutex::scoped_lock lock(enet_mutex _);287 boost::recursive_mutex::scoped_lock lock(enet_mutex); 287 288 enet_peer_disconnect(temp->getPeer(), 0); 288 289 lock.unlock(); … … 292 293 //bugfix: might be the reason why server crashes when clients disconnects 293 294 temp = ClientInformation::getBegin()->next(); 294 boost::recursive_mutex::scoped_lock lock(enet_mutex _);295 boost::recursive_mutex::scoped_lock lock(enet_mutex); 295 296 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){ 296 297 switch (event.type) … … 337 338 std::string classname; 338 339 orxonox::Identifier *id; 340 packet::Packet packet; 341 packet.setClientID(clientID); 342 packet::ClassID *classid; 339 343 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin(); 340 344 while(it != orxonox::Factory::getFactoryEnd()){ … … 348 352 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 349 353 350 while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){ 354 classid = new packet::ClassID(network_id, classname); 355 packet.setPacketContent(classid); 356 while(!packet.send() && failures < 10){ 351 357 failures++; 352 358 } 359 delete classid; 353 360 ++it; 354 361 } 362 packet.setPacketContent(0); 355 363 //sendPackets(); 356 364 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; … … 370 378 } 371 379 372 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){373 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){374 //sendPackets();375 return true;376 }else377 return false;378 }379 380 380 381 void ConnectionManager::disconnectClient(ClientInformation *client){ 381 382 { 382 boost::recursive_mutex::scoped_lock lock(enet_mutex _);383 boost::recursive_mutex::scoped_lock lock(enet_mutex); 383 384 enet_peer_disconnect(client->getPeer(), 0); 384 385 lock.unlock(); … … 387 388 } 388 389 389 bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){390 ENetEvent event;391 event.peer=ev->peer;392 event.packet = packet_gen.generateConnectRequest();393 return buffer.push(&event);394 }395 396 397 390 398 391 }
Note: See TracChangeset
for help on using the changeset viewer.