Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2009, 9:35:10 PM (15 years ago)
Author:
scheusso
Message:

merged netp2 → netp3

Location:
code/branches/netp3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp3

  • code/branches/netp3/src/network/ClientConnection.cc

    r2773 r2990  
    4242#include <enet/enet.h>
    4343#include <iostream>
     44#include <cassert>
    4445// boost.thread library for multithreading support
    4546#include <boost/thread/thread.hpp>
     
    5758
    5859  ClientConnection::ClientConnection(int port, const std::string& address) {
    59     quit=false;
     60    quit_=false;
    6061    server=NULL;
    6162    serverAddress = new ENetAddress();
     
    6667
    6768  ClientConnection::ClientConnection(int port, const char *address) {
    68     quit=false;
     69    quit_=false;
    6970    server=NULL;
    7071    serverAddress = new ENetAddress();
     
    106107
    107108  bool ClientConnection::closeConnection() {
    108     quit=true;
     109    quit_=true;
    109110    //network_threads.join_all();
    110111    receiverThread_->join();
     
    150151      COUT(2) << "ClientConnection: could not create client host" << std::endl;
    151152      // add some error handling here ==========================
    152       quit=true;
     153      quit_=true;
    153154    }
    154155    //connect to the server
    155156    if(!establishConnection()){
    156157      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
    157       quit=true;
     158      quit_=true;
    158159      return;
    159160    }
    160161    event = new ENetEvent;
    161162    //main loop
    162     while(!quit){
     163    while(!quit_){
    163164      //std::cout << "connection loop" << std::endl;
    164165      {
     
    166167        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    167168          // we should never reach this point
    168           quit=true;
    169           continue;
     169//              assert(0);
     170          printf("ClientConnection: ENet returned with an error!\n");
     171          quit_=true;
     172          break;
    170173          // add some error handling here ========================
    171174        }
     
    183186        break;
    184187      case ENET_EVENT_TYPE_DISCONNECT:
    185         quit=true;
     188        quit_=true;
     189        printf("Received disconnect Packet from Server!\n");
    186190        // server closed the connection
    187191        return;
     
    206210    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    207211    enet_peer_disconnect(server, 0);
    208     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
     212    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
    209213      switch (event.type)
    210214      {
     
    233237    }
    234238    // handshake
    235     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit){
     239    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
    236240      if( event.type == ENET_EVENT_TYPE_CONNECT ){
    237241        established=true;
Note: See TracChangeset for help on using the changeset viewer.