Changeset 1491 for code/branches/network/src/network/ConnectionManager.cc
- Timestamp:
- May 31, 2008, 11:48:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/ConnectionManager.cc
r1409 r1491 65 65 66 66 ConnectionManager::ConnectionManager():receiverThread_(0){} 67 boost::recursive_mutex ConnectionManager::enet_mutex_; 67 68 68 69 ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { … … 143 144 if(!temp) 144 145 return false; 146 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 145 147 if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0) 146 148 return false; … … 152 154 if(!temp) 153 155 return false; 156 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 154 157 if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0) 155 158 return false; … … 158 161 159 162 bool ConnectionManager::addPacketAll(ENetPacket *packet) { 163 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 160 164 for(ClientInformation *i=head_->next(); i!=0; i=i->next()){ 161 165 if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0) … … 177 181 if(server==NULL) 178 182 return false; 183 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 179 184 enet_host_flush(server); 180 185 return true; … … 184 189 // what about some error-handling here ? 185 190 ENetEvent *event; 186 enet_initialize();187 191 atexit(enet_deinitialize); 188 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 192 { //scope of the mutex 193 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 194 enet_initialize(); 195 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 196 } 189 197 if(server==NULL){ 190 198 // add some error handling here ========================== … … 195 203 while(!quit){ 196 204 event = new ENetEvent; 197 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 198 // we should never reach this point 199 quit=true; 200 // add some error handling here ======================== 205 { //mutex scope 206 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 207 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 208 // we should never reach this point 209 quit=true; 210 continue; 211 // add some error handling here ======================== 212 } 201 213 } 202 214 switch(event->type){ … … 231 243 disconnectClients(); 232 244 // if we're finishied, destroy server 233 enet_host_destroy(server); 245 { 246 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 247 enet_host_destroy(server); 248 } 234 249 } 235 250 … … 241 256 ClientInformation *temp = head_->next(); 242 257 while(temp!=0){ 243 enet_peer_disconnect(temp->getPeer(), 0); 258 { 259 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 260 enet_peer_disconnect(temp->getPeer(), 0); 261 } 244 262 temp = temp->next(); 245 263 } 246 264 //bugfix: might be the reason why server crashes when clients disconnects 247 //temp = temp->next();248 265 temp = head_->next(); 249 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){ 266 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 267 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){ 250 268 switch (event.type) 251 269 { … … 273 291 } 274 292 275 /*bool ConnectionManager::clientDisconnect(ENetPeer *peer) {276 COUT(4) << "removing client from list" << std::endl;277 return removeClient(head_->findClient(&(peer->address))->getID());278 }*/279 293 /** 280 294 This function adds a client that connects to the clientlist of the server … … 422 436 423 437 void ConnectionManager::disconnectClient(ClientInformation *client){ 424 enet_peer_disconnect(client->getPeer(), 0); 438 { 439 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 440 enet_peer_disconnect(client->getPeer(), 0); 441 } 425 442 removeShip(client); 426 443 }
Note: See TracChangeset
for help on using the changeset viewer.