diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-13 22:53:01 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-13 22:53:01 +0000 |
commit | 83e8023c5e46635753a609329cf9805a3520001e (patch) | |
tree | 23df93da350bb5e9bf084b5e64b506d8831fa013 /src/net/tcpclient.h | |
parent | 4c915658355ae3eeee195ef929fdf7453397edd5 (diff) |
network subsystem initial import
Diffstat (limited to 'src/net/tcpclient.h')
-rw-r--r-- | src/net/tcpclient.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/net/tcpclient.h b/src/net/tcpclient.h new file mode 100644 index 0000000..0fcb4b6 --- /dev/null +++ b/src/net/tcpclient.h @@ -0,0 +1,59 @@ +/* + net/tcpclient.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_NET_TCPCLIENT_H__ +#define __INCLUDED_NET_TCPCLIENT_H__ + +#include <string> + +namespace net +{ + +/// A TCP client, connected to a file descriptor +class TCPClient +{ +public: + /// A new TCP client, connected to a file descriptor + TCPClient(int tcpclientfd); + + /// Delete the TCP client + /// If the file descriptor is still open, it will be closed. + virtual ~TCPClient(); + + /// Returns the error state + bool error() const; + + /// Returns true if the TCP client has a valid file descriptor + bool valid() const; + + /// Returns true if the TCP client has an invalid file descriptor + bool invalid() const; + + /// Returns the file descriptor the TCP client is connected to + int fd() const; + + /// Sets the error state + void abort(); + + /// Sends outgoing data + void send(std::string const &msg); + + /// Called by receive() when the client has disconnected + /// @see receive + virtual void disconnect(); + +protected: + /// receives incoming data + void receive(std::string &msg); + +private: + int tcpclient_fd; + bool tcpclient_error; +}; + +} + +#endif //__INCLUDED_CORE_TCPCLIENT_H__ |