Changeset 8327 for code/trunk/src/libraries/network/Connection.h
- Timestamp:
- Apr 25, 2011, 8:22:36 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/network6 (added) merged: 7823-7825,7875,7878,7881-7882,7898,7900,7931,8315
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/Connection.h
r7801 r8327 44 44 45 45 #include <deque> 46 #include <map> 46 47 #include <enet/enet.h> 48 #include <boost/concept_check.hpp> 47 49 48 50 namespace boost … … 59 61 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 60 62 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 61 74 namespace outgoingEventType 62 75 { 63 76 enum Value 64 77 { 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 68 82 }; 69 83 70 84 } 71 85 86 struct _NetworkExport incomingEvent 87 { 88 uint32_t peerID; 89 incomingEventType::Value type; 90 packet::Packet* packet; 91 }; 92 72 93 struct _NetworkExport outgoingEvent 73 94 { 74 ENetPeer* peer;95 uint32_t peerID; 75 96 outgoingEventType::Value type; 76 97 ENetPacket* packet; … … 83 104 virtual ~Connection(); 84 105 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 89 106 protected: 90 Connection(); 91 // static Connection* getInstance(){ return Connection::instance_; } 92 93 // int service(ENetEvent* event); 107 Connection(uint32_t firstPeerID = NETWORK_PEER_ID_SERVER+1); 108 94 109 void startCommunicationThread(); 95 110 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(); 98 116 99 117 void enableCompression(); 100 118 101 119 void processQueue(); 102 virtual void addPeer(ENetEvent* event)=0; 103 virtual void removePeer(ENetEvent* event)=0; 120 void waitOutgoingQueue(); // wait for the outgoing queue to become empty (everything processed by communication thread) 121 virtual void addPeer(uint32_t peerID)=0; 122 virtual void removePeer(uint32_t peerID)=0; 104 123 virtual void processPacket( packet::Packet* packet)=0; 105 virtual packet::Packet* createPacket(ENetEvent* event); 124 125 incomingEvent preprocessConnectEvent(ENetEvent& event); 126 incomingEvent preprocessDisconnectEvent(ENetEvent& event); 127 incomingEvent preprocessReceiveEvent(ENetEvent& event); 128 129 void processIncomingEvent(ENetEvent& event); 130 void processOutgoingEvent(outgoingEvent& event); 131 132 void disconnectPeersInternal(); 106 133 107 ENetHost* host_;134 ENetHost* host_; 108 135 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_; 116 117 // static Connection *instance_; 136 void communicationThread(); 137 138 boost::thread* communicationThread_; 139 bool bCommunicationThreadRunning_; 140 ENetAddress* bindAddress_; 141 std::deque<incomingEvent> incomingEvents_; 142 std::deque<outgoingEvent> outgoingEvents_; 143 boost::mutex* incomingEventsMutex_; 144 boost::mutex* outgoingEventsMutex_; 145 boost::mutex* overallMutex_; 146 std::map<uint32_t, ENetPeer*> peerMap_; 147 std::map<ENetPeer*, uint32_t> peerIDMap_; 148 uint32_t nextPeerID_; 118 149 119 150 };
Note: See TracChangeset
for help on using the changeset viewer.