Last change
on this file since 173 was
173,
checked in by scheusso, 16 years ago
|
created classes PacketBuffer and ConnectionManager
PacketBuffer: (hopefully) threadsafe implementation of a packet buffer
for communication between threads
ConnectionManager: low-level managment of connection; implementation of
multiple threads
|
File size:
1.4 KB
|
Rev | Line | |
---|
[173] | 1 | // |
---|
| 2 | // C++ Interface: ConnectionManager |
---|
| 3 | // |
---|
| 4 | // Description: |
---|
| 5 | // |
---|
| 6 | // |
---|
| 7 | // Author: <>, (C) 2007 |
---|
| 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
| 12 | #ifndef NETWORK_CONNECTIONMANAGER_H |
---|
| 13 | #define NETWORK_CONNECTIONMANAGER_H |
---|
| 14 | |
---|
| 15 | #include PacketBuffer.h |
---|
| 16 | |
---|
| 17 | namespace network{ |
---|
| 18 | // |
---|
| 19 | #define NETWORK_PORT 5555 |
---|
| 20 | #define NETWORK_MAX_CONNECTIONS 50 |
---|
| 21 | #define NETWORK_WAIT_TIMEOUT 5000 |
---|
| 22 | //just some defines to make life easier ;) |
---|
| 23 | #define ENetEvent std::ENetEvent |
---|
| 24 | #define ENetHost std::ENetHost |
---|
| 25 | #define ENetAddress std::ENetAddress |
---|
| 26 | #define ENetPeer std::ENetPeer |
---|
| 27 | |
---|
| 28 | struct ClientList{ |
---|
| 29 | ENetEvent event; |
---|
| 30 | int ID; |
---|
| 31 | ClientList *next; |
---|
| 32 | }; |
---|
| 33 | |
---|
| 34 | class ConnectionManager{ |
---|
| 35 | public: |
---|
| 36 | ConnectionManager(); |
---|
| 37 | ~ConnectionManager(); |
---|
| 38 | void loop(); // thread1 |
---|
| 39 | bool createListener(); |
---|
| 40 | bool quitServer(); |
---|
| 41 | bool sendEvent(/*.....*/); |
---|
| 42 | bool sendEvent(int clientID/*.....*/); |
---|
| 43 | void test(); |
---|
| 44 | private: |
---|
| 45 | void peerLoop(int clientNumber); //thread2 |
---|
| 46 | bool clientDisconnect(ENetPeer peer); |
---|
| 47 | bool processData(ENetEvent event); |
---|
| 48 | bool addClient(ENetEvent event); |
---|
| 49 | //packetbuffer |
---|
| 50 | PacketBuffer buffer; |
---|
| 51 | // enet stuff |
---|
| 52 | ENetHost *server; |
---|
| 53 | ENetAddress bindAddress; |
---|
| 54 | // quit-variable (communication with threads) |
---|
| 55 | bool quit; |
---|
| 56 | // thread group |
---|
| 57 | boost::thread_group threads; |
---|
| 58 | // clientlist |
---|
| 59 | ClientList *client; |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.