Changeset 285 for code/branches/merger/src/network/ClientConnection.cc
- Timestamp:
- Nov 27, 2007, 11:30:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merger/src/network/ClientConnection.cc
r278 r285 2 2 // C++ Interface: ClientConnection 3 3 // 4 // Description: The Class ClientConnection manages the servers conenctions to the clients. 5 // each connection is provided by a new process. communication between master process and 4 // Description: The Class ClientConnection manages the servers conenctions to the clients. 5 // each connection is provided by a new process. communication between master process and 6 6 // connection processes is provided by ... 7 7 // … … 10 10 // 11 11 12 #include " network/ClientConnection.h"12 #include "ClientConnection.h" 13 13 14 14 namespace network{ 15 15 16 16 boost::thread_group network_threads; 17 17 18 18 ClientConnection::ClientConnection(int port, std::string address){ 19 19 quit=false; … … 23 23 established=false; 24 24 } 25 25 26 26 ClientConnection::ClientConnection(int port, const char *address){ 27 27 quit=false; … … 31 31 established=false; 32 32 } 33 33 34 34 bool ClientConnection::waitEstablished(int milisec){ 35 35 for(int i=0; i<=milisec && !established; i++) … … 37 37 return established; 38 38 } 39 40 39 40 41 41 ENetPacket *ClientConnection::getPacket(ENetAddress &address){ 42 42 if(!buffer.isEmpty()) … … 45 45 return NULL; 46 46 } 47 47 48 48 bool ClientConnection::queueEmpty(){ 49 49 return buffer.isEmpty(); 50 50 } 51 51 52 52 bool ClientConnection::createConnection(){ 53 53 network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this)); … … 55 55 return waitEstablished(10000); 56 56 } 57 57 58 58 bool ClientConnection::closeConnection(){ 59 59 quit=true; … … 62 62 return true; 63 63 } 64 65 64 65 66 66 bool ClientConnection::addPacket(ENetPacket *packet){ 67 67 if(server==NULL) … … 72 72 return true; 73 73 } 74 74 75 75 bool ClientConnection::sendPackets(ENetEvent *event){ 76 76 if(server==NULL) … … 78 78 if(enet_host_service(client, event, NETWORK_SEND_WAIT)>=0) 79 79 return true; 80 else 80 else 81 81 return false; 82 82 } 83 83 84 84 bool ClientConnection::sendPackets(){ 85 85 ENetEvent event; … … 88 88 if(enet_host_service(client, &event, NETWORK_SEND_WAIT)>=0) 89 89 return true; 90 else 90 else 91 91 return false; 92 92 } 93 93 94 94 void ClientConnection::receiverThread(){ 95 95 // what about some error-handling here ? … … 123 123 } 124 124 // now disconnect 125 126 if(!disconnectConnection()) 125 126 if(!disconnectConnection()) 127 127 // if disconnecting failed destroy conn. 128 128 enet_peer_reset(server); 129 129 return; 130 130 } 131 131 132 132 bool ClientConnection::disconnectConnection(){ 133 133 ENetEvent event; … … 145 145 enet_peer_reset(server); 146 146 } 147 147 148 148 bool ClientConnection::establishConnection(){ 149 149 ENetEvent event; … … 161 161 return false; 162 162 } 163 163 164 164 bool ClientConnection::processData(ENetEvent *event){ 165 165 // just add packet to the buffer … … 167 167 return buffer.push(event); 168 168 } 169 170 169 170 171 171 }
Note: See TracChangeset
for help on using the changeset viewer.