Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 28, 2010, 4:46:42 PM (14 years ago)
Author:
scheusso
Message:

again some structural changes in network to increase modularity/encapsulation
precondition for fixing client-disconnect bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network6/src/libraries/network/Connection.h

    r7801 r7823  
    4444
    4545#include <deque>
     46#include <map>
    4647#include <enet/enet.h>
     48#include <boost/concept_check.hpp>
    4749
    4850namespace boost
     
    5961  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
    6062 
     63  namespace incomingEventType
     64  {
     65    enum Value
     66    {
     67      receivePacket   = 1,  // incoming packet
     68      peerConnect     = 2,  // incoming connect request
     69      peerDisconnect  = 3   // incoming disconnect request
     70    };
     71   
     72  }
     73 
    6174  namespace outgoingEventType
    6275  {
    6376    enum Value
    6477    {
    65       sendPacket      = 1,
    66       disconnectPeer  = 2,
    67       broadcastPacket = 3
     78      sendPacket      = 1,  // outgoing packet
     79      broadcastPacket = 2,  // outgoing broadcast packet
     80      disconnectPeer  = 3,  // outgoing disconnect request
     81      disconnectPeers = 4   // outgoing disconnect request
    6882    };
    6983   
    7084  }
    7185 
     86  struct _NetworkExport incomingEvent
     87  {
     88    uint32_t                  peerID;
     89    incomingEventType::Value  type;
     90    packet::Packet*           packet;
     91  };
     92 
    7293  struct _NetworkExport outgoingEvent
    7394  {
    74     ENetPeer*                 peer;
     95    uint32_t                  peerID;
    7596    outgoingEventType::Value  type;
    7697    ENetPacket*               packet;
     
    83104    virtual ~Connection();
    84105
    85     void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
    86     void broadcastPacket(ENetPacket* packet, uint8_t channelID);
    87 //     ENetHost* getHost(){ return this->host_; }
    88 
    89106  protected:
    90107    Connection();
    91 //     static Connection* getInstance(){ return Connection::instance_; }
    92 
    93 //     int service(ENetEvent* event);
     108   
    94109    void startCommunicationThread();
    95110    void stopCommunicationThread();
    96     void communicationThread();
    97     virtual void disconnectPeer(ENetPeer *peer);
     111   
     112    void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID);
     113    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
     114    void disconnectPeer(uint32_t peerID);
     115    void disconnectPeers();
    98116   
    99117    void enableCompression();
    100118
    101119    void processQueue();
    102     virtual void addPeer(ENetEvent* event)=0;
    103     virtual void removePeer(ENetEvent* event)=0;
     120    virtual void addPeer(uint32_t peerID)=0;
     121    virtual void removePeer(uint32_t peerID)=0;
    104122    virtual void processPacket( packet::Packet* packet)=0;
    105     virtual packet::Packet* createPacket(ENetEvent* event);
     123   
     124    incomingEvent preprocessConnectEvent(ENetEvent& event);
     125    incomingEvent preprocessDisconnectEvent(ENetEvent& event);
     126    incomingEvent preprocessReceiveEvent(ENetEvent& event);
     127   
     128    void processIncomingEvent(ENetEvent& event);
     129    void processOutgoingEvent(outgoingEvent& event);
    106130
    107     ENetHost*                   host_;
     131    ENetHost*                     host_;
    108132  private:
    109     boost::thread*              communicationThread_;
    110     bool                        bCommunicationThreadRunning_;
    111     ENetAddress*                bindAddress_;
    112     std::deque<ENetEvent>       incomingEvents_;
    113     std::deque<outgoingEvent>   outgoingEvents_;
    114     boost::mutex*               incomingEventsMutex_;
    115     boost::mutex*               outgoingEventsMutex_;
     133    void communicationThread();
     134   
     135    boost::thread*                communicationThread_;
     136    bool                          bCommunicationThreadRunning_;
     137    ENetAddress*                  bindAddress_;
     138    std::deque<incomingEvent>     incomingEvents_;
     139    std::deque<outgoingEvent>     outgoingEvents_;
     140    boost::mutex*                 incomingEventsMutex_;
     141    boost::mutex*                 outgoingEventsMutex_;
     142    std::map<uint32_t, ENetPeer*> peerMap_;
     143    std::map<ENetPeer*, uint32_t> peerIDMap_;
     144    uint32_t                      nextPeerID_;
    116145
    117146//     static Connection *instance_;
Note: See TracChangeset for help on using the changeset viewer.