Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7772 for code


Ignore:
Timestamp:
Dec 17, 2010, 10:41:24 AM (14 years ago)
Author:
scheusso
Message:

network is now multithreaded again
further testing needed

Location:
code/branches/network5/src/libraries/network
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/Client.cc

    r7759 r7772  
    114114  }
    115115
    116   bool Client::queuePacket(ENetPacket *packet, int clientID)
    117   {
    118     bool b = ClientConnection::addPacket(packet);
    119     assert(b);
    120     return b;
     116  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
     117  {
     118    ClientConnection::addPacket(packet, channelID);
    121119  }
    122120
     
    170168      }
    171169    }
    172     sendPackets(); // flush the enet queue
     170//     sendPackets(); // flush the enet queue
    173171
    174172    Connection::processQueue();
     
    180178    }
    181179    gamestate->cleanup();
    182     Connection::sendPackets();
     180//     Connection::sendPackets();
    183181
    184182    return;
  • code/branches/network5/src/libraries/network/Client.h

    r7163 r7772  
    7878    void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
    7979    bool closeConnection();
    80     bool queuePacket(ENetPacket *packet, int clientID);
     80    void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);
    8181    bool processChat(const std::string& message, unsigned int playerID);
    8282    virtual bool chat(const std::string& message);
  • code/branches/network5/src/libraries/network/ClientConnection.cc

    r7459 r7772  
    9999      {
    100100        this->established_=true;
     101        Connection::startCommunicationThread();
    101102        return true;
    102103      }
     
    112113      return true;
    113114    this->established_ = false;
     115    Connection::stopCommunicationThread();
    114116    enet_peer_disconnect(this->server_, 0);
    115117    for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
     
    138140
    139141
    140   bool ClientConnection::addPacket(ENetPacket *packet) {
     142  void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) {
    141143    assert( this->server_ );
    142144    assert( packet );
    143     return Connection::addPacket( packet, this->server_ );
     145    return Connection::addPacket( packet, this->server_, channelID );
    144146  }
    145147
  • code/branches/network5/src/libraries/network/ClientConnection.h

    r6417 r7772  
    5151    virtual bool closeConnection();
    5252    // add a packet to queue for the server
    53     bool addPacket(ENetPacket *packet);
     53    void addPacket(ENetPacket *packet, uint8_t channelID);
    5454    inline bool isConnected(){ return this->established_; }
    5555  protected:
  • code/branches/network5/src/libraries/network/Connection.cc

    r7163 r7772  
    3030
    3131#include <cassert>
     32#include <deque>
    3233#define WIN32_LEAN_AND_MEAN
    3334#include <enet/enet.h>
     35#include <boost/thread.hpp>
     36#include <boost/thread/mutex.hpp>
     37#include <boost/date_time.hpp>
     38
    3439#include "packet/Packet.h"
    3540
    3641namespace orxonox
    3742{
    38 //   Connection *Connection::instance_=0;
     43  const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
    3944
    4045  Connection::Connection():
    41     host_(0)
    42   {
    43 //     assert(instance_==0);
    44 //     Connection::instance_=this;
     46    host_(0), bCommunicationThreadRunning_(false)
     47  {
    4548    enet_initialize();
    4649    atexit(enet_deinitialize);
    47   }
    48 
    49   Connection::~Connection(){
    50 //     Connection::instance_=0;
    51   }
    52 
    53   int Connection::service(ENetEvent* event) {
    54     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
    55   }
    56 
    57   void Connection::disconnectPeer(ENetPeer *peer) {
    58     enet_peer_disconnect(peer, 0);
    59   }
    60 
    61   bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
    62     if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
    63       return false;
    64     else
    65       return true;
    66   }
    67 
    68   bool Connection::sendPackets() {
    69     if ( /*!Connection::instance_ || */this->host_==NULL )
    70       return false;
    71     enet_host_flush(this->host_);
    72     return true;
    73   }
    74 
    75   void Connection::processQueue() {
     50    this->incomingEventsMutex_ = new boost::mutex;
     51    this->outgoingEventsMutex_ = new boost::mutex;
     52  }
     53
     54  Connection::~Connection()
     55  {
     56    delete this->incomingEventsMutex_;
     57    delete this->outgoingEventsMutex_;
     58  }
     59
     60  void Connection::startCommunicationThread()
     61  {
     62    this->bCommunicationThreadRunning_ = true;
     63    this->communicationThread_ = new boost::thread(&Connection::communicationThread, this);
     64  }
     65 
     66  void Connection::stopCommunicationThread()
     67  {
     68    this->bCommunicationThreadRunning_ = false;
     69    if( !this->communicationThread_->timed_join(NETWORK_COMMUNICATION_THREAD_WAIT_TIME) )
     70    {
     71      // force thread to stop
     72      this->communicationThread_->interrupt();
     73    }
     74    delete this->communicationThread_;
     75  }
     76
     77
     78//   int Connection::service(ENetEvent* event) {
     79//     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
     80//   }
     81
     82  void Connection::disconnectPeer(ENetPeer *peer)
     83  {
     84    outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
     85   
     86    this->outgoingEventsMutex_->lock();
     87    this->outgoingEvents_.push_back(outEvent);
     88    this->outgoingEventsMutex_->unlock();
     89  }
     90
     91  void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
     92  {
     93    outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
     94   
     95    this->outgoingEventsMutex_->lock();
     96    this->outgoingEvents_.push_back(outEvent);
     97    this->outgoingEventsMutex_->unlock();
     98  }
     99 
     100  void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
     101  {
     102    outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };
     103   
     104    this->outgoingEventsMutex_->lock();
     105    this->outgoingEvents_.push_back(outEvent);
     106    this->outgoingEventsMutex_->unlock();
     107  }
     108
     109 
     110  void Connection::communicationThread()
     111  {
     112    COUT(0) << "starting communication thread" << endl;
    76113    ENetEvent event;
    77 
    78     assert(this->host_);
    79 
    80     while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     114   
     115    while( bCommunicationThreadRunning_ )
    81116    {
    82       switch(event.type){
     117      // Receive all pending incoming Events (such as packets, connects and disconnects)
     118      while( enet_host_check_events( this->host_, &event ) > 0 )
     119      {
     120//         COUT(0) << "incoming event" << endl;
     121        // received an event
     122        this->incomingEventsMutex_->lock();
     123        this->incomingEvents_.push_back(event);
     124        this->incomingEventsMutex_->unlock();
     125      }
     126     
     127      // Send all waiting outgoing packets
     128      this->outgoingEventsMutex_->lock();
     129      uint32_t outgoingEventsCount = this->outgoingEvents_.size();
     130      this->outgoingEventsMutex_->unlock();
     131      while( outgoingEventsCount > 0 )
     132      {
     133//         COUT(0) << "outgoing event" << endl;
     134        this->outgoingEventsMutex_->lock();
     135        outgoingEvent outEvent = this->outgoingEvents_.front();
     136        this->outgoingEvents_.pop_front();
     137        this->outgoingEventsMutex_->unlock();
     138       
     139        switch( outEvent.type )
     140        {
     141          case outgoingEventType::sendPacket:
     142            enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
     143            break;
     144          case outgoingEventType::disconnectPeer:
     145            enet_peer_disconnect(outEvent.peer, 0);
     146            break;
     147          case outgoingEventType::broadcastPacket:
     148            enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
     149            break;
     150          default:
     151            assert(0);
     152        }
     153        this->outgoingEventsMutex_->lock();
     154        outgoingEventsCount = this->outgoingEvents_.size();
     155        this->outgoingEventsMutex_->unlock();
     156      }
     157     
     158      // Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms)
     159      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     160      {
     161//         COUT(0) << "incoming event after wait" << endl;
     162        //received an event
     163        this->incomingEventsMutex_->lock();
     164        this->incomingEvents_.push_back(event);
     165        this->incomingEventsMutex_->unlock();
     166      }
     167    }
     168  }
     169
     170  void Connection::processQueue()
     171  {
     172    ENetEvent event;
     173
     174    this->incomingEventsMutex_->lock();
     175    uint32_t incomingEventsCount = this->incomingEvents_.size();
     176    this->incomingEventsMutex_->unlock();
     177    while( incomingEventsCount > 0 )
     178    {
     179      this->incomingEventsMutex_->lock();
     180      event = this->incomingEvents_.front();
     181      this->incomingEvents_.pop_front();
     182      this->incomingEventsMutex_->unlock();
     183     
     184      switch(event.type)
     185      {
    83186        // log handling ================
    84187        case ENET_EVENT_TYPE_CONNECT:
     
    89192          break;
    90193        case ENET_EVENT_TYPE_RECEIVE:
     194//           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
    91195          processPacket( &event );
    92196          break;
     
    94198          break;
    95199      }
     200     
     201      this->incomingEventsMutex_->lock();
     202      incomingEventsCount = this->incomingEvents_.size();
     203      this->incomingEventsMutex_->unlock();
    96204    }
    97205  }
    98206
    99   bool Connection::processPacket(ENetEvent* event) {
     207  bool Connection::processPacket(ENetEvent* event)
     208  {
    100209    packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
    101210    return p->process();
  • code/branches/network5/src/libraries/network/Connection.h

    r7163 r7772  
    4343#include "NetworkPrereqs.h"
    4444
     45#include <deque>
     46
     47namespace boost
     48{
     49  class thread;
     50  class mutex;
     51}
     52
    4553namespace orxonox
    4654{
    47     const unsigned int NETWORK_PORT = 55556;
    48     const unsigned int NETWORK_MAX_CONNECTIONS = 50;
    49     const unsigned int NETWORK_WAIT_TIMEOUT = 0;
    50     const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
    51     const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
    52 
    53   class _NetworkExport Connection{
     55  const unsigned int NETWORK_PORT                   = 55556;
     56  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
     57  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
     58  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
     59 
     60  namespace outgoingEventType
     61  {
     62    enum Value
     63    {
     64      sendPacket      = 1,
     65      disconnectPeer  = 2,
     66      broadcastPacket = 3
     67    };
     68   
     69  }
     70 
     71  struct _NetworkExport outgoingEvent
     72  {
     73    ENetPeer*                 peer;
     74    outgoingEventType::Value  type;
     75    ENetPacket*               packet;
     76    ENetChannelID             channelID;
     77  };
     78 
     79  class _NetworkExport Connection
     80  {
    5481  public:
    5582    virtual ~Connection();
    5683
    57     static bool addPacket(ENetPacket *packet, ENetPeer *peer);
    58     bool sendPackets();
     84    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
     85    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
    5986    ENetHost* getHost(){ return this->host_; }
    6087
     
    6390//     static Connection* getInstance(){ return Connection::instance_; }
    6491
    65     int service(ENetEvent* event);
     92//     int service(ENetEvent* event);
     93    void startCommunicationThread();
     94    void stopCommunicationThread();
     95    void communicationThread();
    6696    virtual void disconnectPeer(ENetPeer *peer);
    6797
     
    71101    virtual bool processPacket(ENetEvent* event);
    72102
    73     ENetHost *host_;
     103    ENetHost*                   host_;
     104    boost::mutex*               incomingEventsMutex_;
     105    boost::mutex*               outgoingEventsMutex_;
    74106  private:
    75     ENetAddress *bindAddress_;
     107    boost::thread*              communicationThread_;
     108    bool                        bCommunicationThreadRunning_;
     109    ENetAddress*                bindAddress_;
     110    std::deque<ENetEvent>       incomingEvents_;
     111    std::deque<outgoingEvent>   outgoingEvents_;
    76112
    77113//     static Connection *instance_;
  • code/branches/network5/src/libraries/network/Host.cc

    r7284 r7772  
    7676  * @return success?
    7777  */
    78   bool Host::addPacket(ENetPacket *packet, int clientID)
     78  void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID)
    7979  {
    80     bool result = true;
    8180    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
    8281    {
    8382      if( (*it)->isActive() )
    8483      {
    85         if( !(*it)->queuePacket(packet, clientID) )
    86           result = false;
     84        (*it)->queuePacket(packet, clientID, channelID);
    8785      }
    8886    }
    89     return result;
    9087  }
    9188
  • code/branches/network5/src/libraries/network/Host.h

    r7284 r7772  
    5454    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
    5555    //virtual bool sendChat(packet::Chat *chat)=0;
    56     virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
     56    virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0;
    5757    virtual bool chat(const std::string& message)=0;
    5858    virtual bool broadcast(const std::string& message)=0;
     
    7171//     static Host* getInstance(){ return instance_; }
    7272    static bool running(){ return instances_s.size(); }
    73     static bool addPacket(ENetPacket *packet, int clientID=0);
     73    static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0);
    7474    //static bool chat(std::string& message);
    7575//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
  • code/branches/network5/src/libraries/network/NetworkPrereqs.h

    r7759 r7772  
    6464namespace orxonox
    6565{
    66   static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
    67   static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
     66  static const unsigned int GAMESTATEID_INITIAL       = static_cast<unsigned int>(-1);
     67  static const unsigned int CLIENTID_UNKNOWN          = static_cast<unsigned int>(-2);
    6868  extern const char* LAN_DISCOVERY_MESSAGE;
    6969  extern const char* LAN_DISCOVERY_ACK;
    70   static const unsigned int LAN_DISCOVERY_PORT      = 55557;
    71   static const unsigned int NETWORK_PEER_ID_SERVER = 0;
     70  static const unsigned int LAN_DISCOVERY_PORT        = 55557;
     71  static const unsigned int NETWORK_PEER_ID_SERVER    = 0;
     72  static const unsigned int NETWORK_CHANNEL_DEFAULT   = 0;
     73  static const unsigned int NETWORK_CHANNEL_RELIABLE  = 1;
    7274}
    7375
     
    98100// from ENet
    99101struct _ENetPeer;
    100 typedef _ENetPeer ENetPeer;
     102typedef _ENetPeer     ENetPeer;
    101103struct _ENetPacket;
    102 typedef _ENetPacket ENetPacket;
     104typedef _ENetPacket   ENetPacket;
    103105struct _ENetEvent;
    104 typedef _ENetEvent ENetEvent;
     106typedef _ENetEvent    ENetEvent;
    105107struct _ENetHost;
    106 typedef _ENetHost ENetHost;
     108typedef _ENetHost     ENetHost;
    107109struct _ENetAddress;
    108 typedef _ENetAddress ENetAddress;
     110typedef _ENetAddress  ENetAddress;
     111typedef uint8_t       ENetChannelID;
    109112
    110113namespace orxonox
     
    162165}
    163166
     167namespace boost
     168{
     169  class mutex;
     170  class thread;
     171}
     172
    164173#endif /* _NetworkPrereqs_H__ */
  • code/branches/network5/src/libraries/network/Server.cc

    r7759 r7772  
    229229        updateGamestate();
    230230      }
    231       sendPackets(); // flush the enet queue
    232     }
    233   }
    234 
    235   bool Server::queuePacket(ENetPacket *packet, int clientID)
    236   {
    237     return ServerConnection::addPacket(packet, clientID);
     231//       sendPackets(); // flush the enet queue
     232    }
     233  }
     234
     235  void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
     236  {
     237    ServerConnection::addPacket(packet, clientID, channelID);
    238238  }
    239239
  • code/branches/network5/src/libraries/network/Server.h

    r7739 r7772  
    6464    void close();
    6565    bool processChat(const std::string& message, unsigned int playerID);
    66     bool queuePacket(ENetPacket *packet, int clientID);
     66    void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);
    6767    void update(const Clock& time);
    6868    unsigned int getRTT(unsigned int clientID);
  • code/branches/network5/src/libraries/network/ServerConnection.cc

    r7459 r7772  
    4949  }
    5050
    51   ServerConnection::~ServerConnection(){
     51  ServerConnection::~ServerConnection()
     52  {
    5253    if ( this->bListening_ )
    5354      closeListener();
     
    5556  }
    5657
    57   void ServerConnection::setBindAddress( const std::string& bindAddress ) {
     58  void ServerConnection::setBindAddress( const std::string& bindAddress )
     59  {
    5860    if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
    5961        COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
     
    6466  }
    6567
    66   bool ServerConnection::openListener() {
     68  bool ServerConnection::openListener()
     69  {
    6770    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
    6871    if ( this->host_ == NULL )
     
    7881    else
    7982        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
     83   
     84    Connection::startCommunicationThread();
    8085
    8186    return true;
    8287  }
    8388
    84   bool ServerConnection::closeListener() {
     89  bool ServerConnection::closeListener()
     90  {
    8591    this->bListening_=false;
    8692    disconnectClients();
     
    8995  }
    9096
    91   bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
     97  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
     98  {
    9299    if ( clientID == CLIENTID_UNKNOWN )
    93100    {
    94       return addPacketAll(packet);
     101      broadcastPacket(packet, channelID);
    95102    }
    96103    else
     
    99106      if(!temp){
    100107        COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
    101         return false;
    102108      }
    103       return Connection::addPacket(packet, temp->getPeer());
     109      Connection::addPacket(packet, temp->getPeer(), channelID);
    104110    }
    105   }
    106 
    107   bool ServerConnection::addPacketAll(ENetPacket *packet) {
    108 //     if ( !Connection::getInstance() )
    109 //       return false;
    110     enet_host_broadcast( Connection::getHost(), 0, packet);
    111     return true;
    112111  }
    113112
     
    117116  }
    118117
    119   void ServerConnection::disconnectClient(int clientID){
     118  void ServerConnection::disconnectClient(int clientID)
     119  {
    120120    ClientInformation *client = ClientInformation::findClient(clientID);
    121121    if(client)
     
    123123  }
    124124
    125   void ServerConnection::disconnectClients() {
    126     ENetEvent event;
     125  void ServerConnection::disconnectClients()
     126  {
    127127    ClientInformation *temp = ClientInformation::getBegin();
    128     while(temp!=0){
     128    while(temp!=0)
     129    {
    129130      ServerConnection::disconnectClient( temp );
    130131      temp = temp->next();
    131     }
    132     temp = ClientInformation::getBegin();
    133     while( temp!=0 ){
    134       if( service( &event ) )
    135       {
    136         switch (event.type)
    137         {
    138         case ENET_EVENT_TYPE_NONE: break;
    139         case ENET_EVENT_TYPE_CONNECT: break;
    140         case ENET_EVENT_TYPE_RECEIVE:
    141           enet_packet_destroy(event.packet);
    142           break;
    143         case ENET_EVENT_TYPE_DISCONNECT:
    144           removePeer( &event );
    145           temp = ClientInformation::getBegin();
    146           break;
    147         }
    148       }
    149132    }
    150133    return;
     
    152135
    153136
    154   int ServerConnection::getClientID(ENetPeer* peer) {
     137  int ServerConnection::getClientID(ENetPeer* peer)
     138  {
    155139    return getClientID(&(peer->address));
    156140  }
    157141
    158   int ServerConnection::getClientID(ENetAddress* address) {
     142  int ServerConnection::getClientID(ENetAddress* address)
     143  {
    159144    return ClientInformation::findClient(address)->getID();
    160145  }
    161146
    162   ENetPeer *ServerConnection::getClientPeer(int clientID) {
     147  ENetPeer *ServerConnection::getClientPeer(int clientID)
     148  {
    163149    return ClientInformation::findClient(clientID)->getPeer();
    164150  }
  • code/branches/network5/src/libraries/network/ServerConnection.h

    r7163 r7772  
    5656    bool openListener();
    5757    bool closeListener();
    58     bool addPacket(ENetPacket *packet, unsigned int ID);
    59     bool addPacketAll(ENetPacket *packet);
     58    void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
    6059    virtual void disconnectClient(ClientInformation *client);
    6160    void disconnectClient(int clientID);
  • code/branches/network5/src/libraries/network/packet/Packet.cc

    r7759 r7772  
    3535#include <enet/enet.h>
    3636#include <boost/static_assert.hpp>
     37#include <boost/thread/mutex.hpp>
    3738
    3839#include "util/Debug.h"
     
    6162
    6263std::map<size_t, Packet *> Packet::packetMap_;
     64boost::mutex Packet::packetMapMutex_;
    6365
    6466Packet::Packet()
     
    142144      // Assures we don't create a packet and destroy it right after in another thread
    143145      // without having a reference in the packetMap_
     146      Packet::packetMapMutex_.lock();
    144147      packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
     148      Packet::packetMapMutex_.unlock();
    145149    }
    146150  }
     
    164168//  ENetPacket *temp = enetPacket_;
    165169//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    166   if(!Host::addPacket( enetPacket_, clientID_))
    167     enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
     170  if( this->flags_ & PacketFlag::Reliable )
     171    Host::addPacket( enetPacket_, clientID_, 0);
     172  else
     173    Host::addPacket( enetPacket_, clientID_, 0);
    168174  return true;
    169175}
     
    228234void Packet::deletePacket(ENetPacket *enetPacket){
    229235  // Get our Packet from a global map with all Packets created in the send() method of Packet.
     236  Packet::packetMapMutex_.lock();
    230237  std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
    231238  assert(it != packetMap_.end());
     
    234241  delete it->second;
    235242  packetMap_.erase(it);
     243  Packet::packetMapMutex_.unlock();
    236244//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
    237245}
  • code/branches/network5/src/libraries/network/packet/Packet.h

    r7490 r7772  
    9696  private:
    9797    static std::map<size_t, Packet *> packetMap_;
     98    static boost::mutex               packetMapMutex_;
    9899    ENetPacket *enetPacket_;
    99100};
Note: See TracChangeset for help on using the changeset viewer.