Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2007, 11:30:17 PM (16 years ago)
Author:
nicolasc
Message:

cleaned up network, builds with CML

File:
1 edited

Legend:

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

    r278 r285  
    22// C++ Interface: ClientConnection
    33//
    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
    66// connection processes is provided by ...
    77//
     
    1010//
    1111
    12 #include "network/ClientConnection.h"
     12#include "ClientConnection.h"
    1313
    1414namespace network{
    15  
     15
    1616  boost::thread_group network_threads;
    17  
     17
    1818  ClientConnection::ClientConnection(int port, std::string address){
    1919    quit=false;
     
    2323    established=false;
    2424  }
    25  
     25
    2626  ClientConnection::ClientConnection(int port, const char *address){
    2727    quit=false;
     
    3131    established=false;
    3232  }
    33  
     33
    3434  bool ClientConnection::waitEstablished(int milisec){
    3535    for(int i=0; i<=milisec && !established; i++)
     
    3737    return established;
    3838  }
    39  
    40  
     39
     40
    4141  ENetPacket *ClientConnection::getPacket(ENetAddress &address){
    4242    if(!buffer.isEmpty())
     
    4545        return NULL;
    4646  }
    47  
     47
    4848  bool ClientConnection::queueEmpty(){
    4949    return buffer.isEmpty();
    5050  }
    51  
     51
    5252  bool ClientConnection::createConnection(){
    5353    network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
     
    5555    return waitEstablished(10000);
    5656  }
    57  
     57
    5858  bool ClientConnection::closeConnection(){
    5959    quit=true;
     
    6262    return true;
    6363  }
    64  
    65  
     64
     65
    6666  bool ClientConnection::addPacket(ENetPacket *packet){
    6767    if(server==NULL)
     
    7272      return true;
    7373  }
    74  
     74
    7575  bool ClientConnection::sendPackets(ENetEvent *event){
    7676    if(server==NULL)
     
    7878    if(enet_host_service(client, event, NETWORK_SEND_WAIT)>=0)
    7979      return true;
    80     else 
     80    else
    8181      return false;
    8282  }
    83  
     83
    8484  bool ClientConnection::sendPackets(){
    8585    ENetEvent event;
     
    8888    if(enet_host_service(client, &event, NETWORK_SEND_WAIT)>=0)
    8989      return true;
    90     else 
     90    else
    9191      return false;
    9292  }
    93  
     93
    9494  void ClientConnection::receiverThread(){
    9595    // what about some error-handling here ?
     
    123123    }
    124124    // now disconnect
    125    
    126     if(!disconnectConnection()) 
     125
     126    if(!disconnectConnection())
    127127    // if disconnecting failed destroy conn.
    128128      enet_peer_reset(server);
    129129    return;
    130130  }
    131  
     131
    132132  bool ClientConnection::disconnectConnection(){
    133133    ENetEvent event;
     
    145145    enet_peer_reset(server);
    146146  }
    147  
     147
    148148  bool ClientConnection::establishConnection(){
    149149    ENetEvent event;
     
    161161      return false;
    162162  }
    163  
     163
    164164  bool ClientConnection::processData(ENetEvent *event){
    165165    // just add packet to the buffer
     
    167167    return buffer.push(event);
    168168  }
    169  
    170  
     169
     170
    171171}
Note: See TracChangeset for help on using the changeset viewer.