Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 11, 2009, 4:06:31 PM (15 years ago)
Author:
rgrieder
Message:

Removed all enet and boost includes from header files in the network library.

  • Reduces dependencies
  • Minimises problems with windows.h
  • Speeds up the compiling process a little bit (probably negligible)
  • Also removes ugly WIN32_LEAN_AND_MEAN declarations before every enet.h include in the network library.

Removed windows.h header from util/Sleep.h by adding Sleep.cc

File:
1 edited

Legend:

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

    r2662 r2773  
    4040#include "ClientConnection.h"
    4141
     42#include <enet/enet.h>
    4243#include <iostream>
    4344// boost.thread library for multithreading support
    4445#include <boost/thread/thread.hpp>
    4546#include <boost/bind.hpp>
     47#include <boost/thread/recursive_mutex.hpp>
    4648
    4749#include "util/Sleep.h"
     
    5254  //static boost::thread_group network_threads;
    5355
    54   boost::recursive_mutex ClientConnection::enet_mutex_;
     56  static boost::recursive_mutex enet_mutex_g;
    5557
    5658  ClientConnection::ClientConnection(int port, const std::string& address) {
    5759    quit=false;
    5860    server=NULL;
    59     enet_address_set_host(&serverAddress, address.c_str());
    60     serverAddress.port = port;
     61    serverAddress = new ENetAddress();
     62    enet_address_set_host(serverAddress, address.c_str());
     63    serverAddress->port = port;
    6164    established=false;
    6265  }
     
    6568    quit=false;
    6669    server=NULL;
    67     enet_address_set_host(&serverAddress, address);
    68     serverAddress.port = port;
     70    serverAddress = new ENetAddress();
     71    enet_address_set_host(serverAddress, address);
     72    serverAddress->port = port;
    6973    established=false;
    7074  }
     
    8084    if(established)
    8185      closeConnection();
     86    delete serverAddress; // surely was created
    8287  }
    8388
     
    116121      return false;
    117122    }
    118     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     123    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    119124    if(enet_peer_send(server, 0, packet)<0)
    120125      return false;
     
    126131    if(server==NULL)
    127132      return false;
    128     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     133    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    129134    enet_host_flush(client);
    130135    lock.unlock();
     
    137142    ENetEvent *event;
    138143    {
    139       boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     144      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    140145      enet_initialize();
    141146      client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
     
    158163      //std::cout << "connection loop" << std::endl;
    159164      {
    160         boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     165        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    161166        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    162167          // we should never reach this point
     
    192197    if(!disconnectConnection())
    193198      // if disconnecting failed destroy conn.
    194       boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     199      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    195200      enet_peer_reset(server);
    196201    return;
     
    199204  bool ClientConnection::disconnectConnection() {
    200205    ENetEvent event;
    201     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     206    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    202207    enet_peer_disconnect(server, 0);
    203208    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
     
    220225    ENetEvent event;
    221226    // connect to peer (server is type ENetPeer*)
    222     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    223     server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
     227    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
     228    server = enet_host_connect(client, serverAddress, NETWORK_CLIENT_CHANNELS);
    224229    if(server==NULL) {
    225230      COUT(2) << "ClientConnection: server == NULL" << std::endl;
Note: See TracChangeset for help on using the changeset viewer.