Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1517


Ignore:
Timestamp:
Jun 2, 2008, 2:42:46 PM (16 years ago)
Author:
scheusso
Message:

improved client connection handling (better use of timeout)

Location:
code/branches/network/src/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/ClientConnection.cc

    r1515 r1517  
    107107    //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
    108108    // wait 10 seconds for the connection to be established
    109     return waitEstablished(3000);
     109    return waitEstablished(NETWORK_CLIENT_CONNECT_TIMEOUT);
    110110  }
    111111
     
    169169      {
    170170        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    171         if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){
     171        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    172172          // we should never reach this point
    173173          quit=true;
     
    211211    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    212212    enet_peer_disconnect(server, 0);
    213     while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){
     213    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
    214214      switch (event.type)
    215215      {
     
    238238    }
    239239    // handshake
    240     if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>=0 && event.type == ENET_EVENT_TYPE_CONNECT){
    241       established=true;
    242       return true;
    243     }
    244     else {
    245       COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
    246       return false;
    247     }
     240    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit){
     241      if( event.type == ENET_EVENT_TYPE_CONNECT ){
     242        established=true;
     243        return true;
     244      }
     245    }
     246    COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
     247    return false;
    248248  }
    249249
  • code/branches/network/src/network/ClientConnection.h

    r1505 r1517  
    5454#define NETWORK_PORT 55556
    5555#define NETWORK_CLIENT_MAX_CONNECTIONS 5
    56 #define NETWORK_CLIENT_TIMEOUT 1
     56#define NETWORK_CLIENT_WAIT_TIME 1
     57#define NETWORK_CLIENT_CONNECT_TIMEOUT 3000 // miliseconds
    5758#define NETWORK_CLIENT_CHANNELS 2
    5859
Note: See TracChangeset for help on using the changeset viewer.