Changeset 777 for code/branches/FICN/src/network/ClientConnection.cc
- Timestamp:
- Dec 31, 2007, 7:40:23 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/ClientConnection.cc
r742 r777 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Oliver Scheuss, (C) 2007 23 * Co-authors: 24 * ... 25 * 26 */ 27 27 28 28 // … … 37 37 // 38 38 39 #include <iostream> 40 // boost.thread library for multithreading support 41 #include <boost/thread/thread.hpp> 42 #include <boost/bind.hpp> 43 44 #include "util/Sleep.h" 39 45 #include "ClientConnection.h" 40 46 41 #include "util/Sleep.h" 42 43 namespace network{ 44 47 namespace network 48 { 45 49 static boost::thread_group network_threads; 46 50 47 ClientConnection::ClientConnection(int port, std::string address) {51 ClientConnection::ClientConnection(int port, std::string address) { 48 52 quit=false; 49 53 server=NULL; … … 53 57 } 54 58 55 ClientConnection::ClientConnection(int port, const char *address) {59 ClientConnection::ClientConnection(int port, const char *address) { 56 60 quit=false; 57 61 server=NULL; … … 61 65 } 62 66 63 bool ClientConnection::waitEstablished(int milisec) {67 bool ClientConnection::waitEstablished(int milisec) { 64 68 for(int i=0; i<=milisec && !established; i++) 65 69 usleep(1000); … … 69 73 70 74 71 ENetPacket *ClientConnection::getPacket(ENetAddress &address) {75 ENetPacket *ClientConnection::getPacket(ENetAddress &address) { 72 76 if(!buffer.isEmpty()) { 73 77 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; … … 75 79 } 76 80 else{ 77 78 } 79 } 80 81 ENetPacket *ClientConnection::getPacket() {81 return NULL; 82 } 83 } 84 85 ENetPacket *ClientConnection::getPacket() { 82 86 ENetAddress address; 83 87 return getPacket(address); 84 88 } 85 89 86 bool ClientConnection::queueEmpty() {90 bool ClientConnection::queueEmpty() { 87 91 return buffer.isEmpty(); 88 92 } 89 93 90 bool ClientConnection::createConnection() {94 bool ClientConnection::createConnection() { 91 95 network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this)); 92 96 // wait 10 seconds for the connection to be established … … 94 98 } 95 99 96 bool ClientConnection::closeConnection() {100 bool ClientConnection::closeConnection() { 97 101 quit=true; 98 102 network_threads.join_all(); … … 102 106 103 107 104 bool ClientConnection::addPacket(ENetPacket *packet) {108 bool ClientConnection::addPacket(ENetPacket *packet) { 105 109 if(server==NULL) 106 110 return false; … … 110 114 } 111 115 112 bool ClientConnection::sendPackets(ENetEvent *event) {116 bool ClientConnection::sendPackets(ENetEvent *event) { 113 117 if(server==NULL) 114 118 return false; … … 119 123 } 120 124 121 bool ClientConnection::sendPackets() {125 bool ClientConnection::sendPackets() { 122 126 ENetEvent event; 123 127 if(server==NULL) … … 129 133 } 130 134 131 void ClientConnection::receiverThread() {135 void ClientConnection::receiverThread() { 132 136 // what about some error-handling here ? 133 137 enet_initialize(); … … 170 174 171 175 if(!disconnectConnection()) 172 // if disconnecting failed destroy conn.176 // if disconnecting failed destroy conn. 173 177 enet_peer_reset(server); 174 178 return; 175 179 } 176 180 177 bool ClientConnection::disconnectConnection() {181 bool ClientConnection::disconnectConnection() { 178 182 ENetEvent event; 179 183 enet_peer_disconnect(server, 0); … … 181 185 switch (event.type) 182 186 { 183 184 185 186 187 188 189 187 case ENET_EVENT_TYPE_NONE: 188 case ENET_EVENT_TYPE_CONNECT: 189 case ENET_EVENT_TYPE_RECEIVE: 190 enet_packet_destroy(event.packet); 191 break; 192 case ENET_EVENT_TYPE_DISCONNECT: 193 return true; 190 194 } 191 195 } … … 194 198 } 195 199 196 bool ClientConnection::establishConnection() {200 bool ClientConnection::establishConnection() { 197 201 ENetEvent event; 198 202 // connect to peer … … 210 214 } 211 215 212 bool ClientConnection::processData(ENetEvent *event) {216 bool ClientConnection::processData(ENetEvent *event) { 213 217 //std::cout << "got packet, pushing to queue" << std::endl; 214 218 // just add packet to the buffer … … 217 221 } 218 222 219 220 223 }
Note: See TracChangeset
for help on using the changeset viewer.