Changeset 1491
- Timestamp:
- May 31, 2008, 11:48:01 AM (16 years ago)
- Location:
- code/branches/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/TODO
r1432 r1491 1 - should we use enet_peer_ping to test if a client is still alive ? 2 - enet_host_broadcast ? (to all peers) 3 - enet_host_check_events ? instead of enet_host_service -
code/branches/network/src/network/ClientConnection.cc
r1409 r1491 50 50 { 51 51 //static boost::thread_group network_threads; 52 53 boost::recursive_mutex ClientConnection::enet_mutex_; 52 54 53 55 ClientConnection::ClientConnection(int port, std::string address) { … … 124 126 return false; 125 127 } 128 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 126 129 if(enet_peer_send(server, 0, packet)<0) 127 130 return false; … … 143 146 if(server==NULL) 144 147 return false; 148 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 145 149 enet_host_flush(client); 146 150 return true; … … 149 153 void ClientConnection::receiverThread() { 150 154 // what about some error-handling here ? 151 enet_initialize();152 155 atexit(enet_deinitialize); 153 156 ENetEvent *event; 154 client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 157 { 158 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 159 enet_initialize(); 160 client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 161 } 155 162 if(client==NULL) { 156 163 COUT(2) << "ClientConnection: could not create client host" << std::endl; … … 168 175 event = new ENetEvent; 169 176 //std::cout << "connection loop" << std::endl; 170 if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){ 171 // we should never reach this point 172 quit=true; 173 // add some error handling here ======================== 177 { 178 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 179 if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){ 180 // we should never reach this point 181 quit=true; 182 continue; 183 // add some error handling here ======================== 184 } 174 185 } 175 186 switch(event->type){ … … 196 207 if(!disconnectConnection()) 197 208 // if disconnecting failed destroy conn. 209 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 198 210 enet_peer_reset(server); 199 211 return; … … 202 214 bool ClientConnection::disconnectConnection() { 203 215 ENetEvent event; 216 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 204 217 enet_peer_disconnect(server, 0); 205 218 while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){ … … 222 235 ENetEvent event; 223 236 // connect to peer (server is type ENetPeer*) 237 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 224 238 server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS); 225 239 if(server==NULL) { -
code/branches/network/src/network/ClientConnection.h
r1443 r1491 96 96 ENetPeer *server; 97 97 boost::thread *receiverThread_; 98 99 static boost::recursive_mutex enet_mutex_; 98 100 }; 99 101 -
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 } -
code/branches/network/src/network/ConnectionManager.h
r1409 r1491 48 48 #include <enet/enet.h> 49 49 #include <boost/thread/thread.hpp> 50 #include <boost/thread/recursive_mutex.hpp> 50 51 51 52 #include "PacketBuffer.h" … … 116 117 117 118 boost::thread *receiverThread_; 119 static boost::recursive_mutex enet_mutex_; 118 120 // int getNumberOfClients(); 119 121 //functions to map what object every clients uses -
code/branches/network/src/orxonox/Orxonox.cc
r1466 r1491 186 186 else if (mode == "server") 187 187 mode_ = SERVER; 188 else if (mode == "dedicated") 189 mode_= DEDICATED; 188 190 else 189 191 { … … 215 217 bool Orxonox::start() 216 218 { 217 //if (mode == DEDICATED)219 //if (mode_ == DEDICATED) 218 220 // do something else 219 221 //else … … 433 435 // don't forget to call _fireFrameStarted in ogre to make sure 434 436 // everything goes smoothly 435 ogreRoot._fireFrameStarted(evt); 437 if(mode_!=DEDICATED) 438 ogreRoot._fireFrameStarted(evt); 436 439 437 440 // get current time … … 439 442 calculateEventTime(now, eventTimes[2]); 440 443 441 ogreRoot._updateAllRenderTargets(); // only render in non-server mode 444 if(mode_!=DEDICATED) 445 ogreRoot._updateAllRenderTargets(); // only render in non-server mode 442 446 443 447 // get current time … … 449 453 450 454 // again, just to be sure ogre works fine 451 ogreRoot._fireFrameEnded(evt); 455 if(mode_!=DEDICATED) 456 ogreRoot._fireFrameEnded(evt); 452 457 } 453 458 -
code/branches/network/src/orxonox/Orxonox.h
r1446 r1491 50 50 SERVER, 51 51 CLIENT, 52 STANDALONE 52 STANDALONE, 53 DEDICATED 53 54 }; 54 55
Note: See TracChangeset
for help on using the changeset viewer.