Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

network is now multithreaded again
further testing needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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_;
Note: See TracChangeset for help on using the changeset viewer.