Changeset 1491 for code/branches/network/src/network/ClientConnection.cc
- Timestamp:
- May 31, 2008, 11:48:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note: See TracChangeset
for help on using the changeset viewer.