diff options
Diffstat (limited to 'src/net/network.h')
-rw-r--r-- | src/net/network.h | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/src/net/network.h b/src/net/network.h index 13929ec1..d6fec761 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -41,29 +41,52 @@ class Network friend class MessageOut; Network(); + ~Network(); - bool connect(const std::string &address, short port); - void disconnect(); + bool + connect(const std::string &address, short port); + + void + disconnect(); + + void + registerHandler(MessageHandler *handler); + + void + unregisterHandler(MessageHandler *handler); + + void + clearHandlers(); + + int + getState() const { return mState; } - void registerHandler(MessageHandler *handler); - void unregisterHandler(MessageHandler *handler); - void clearHandlers(); + const std::string& + getError() const { return mError; } - int getState() const { return mState; } - bool isConnected() const { return mState == CONNECTED; } + bool + isConnected() const { return mState == CONNECTED; } - int getInSize() const { return mInSize; } + int + getInSize() const { return mInSize; } - void skip(int len); + void + skip(int len); - bool messageReady(); - MessageIn getNextMessage(); + bool + messageReady(); - void dispatchMessages(); - void flush(); + MessageIn + getNextMessage(); - // ERROR replaced by NET_ERROR because already defined in Windows + void + dispatchMessages(); + + void + flush(); + + // ERROR replaced by NET_ERROR because already defined in Windows enum { IDLE, CONNECTED, @@ -73,7 +96,17 @@ class Network }; protected: - Uint16 readWord(int pos); + void + setError(const std::string& error); + + Uint16 + readWord(int pos); + + bool + realConnect(); + + void + receive(); TCPsocket mSocket; @@ -86,6 +119,7 @@ class Network unsigned int mToSkip; int mState; + std::string mError; SDL_Thread *mWorkerThread; SDL_mutex *mMutex; @@ -93,9 +127,6 @@ class Network typedef std::map<Uint16, MessageHandler*> MessageHandlers; typedef MessageHandlers::iterator MessageHandlerIterator; MessageHandlers mMessageHandlers; - - bool realConnect(); - void receive(); }; /** Convert an address from int format to string */ |