/* net/tcpconnection.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_TCPCONNECTION_H__ #define __INCLUDED_NET_TCPCONNECTION_H__ #include namespace net { /// A TCP client, connected to a file descriptor /// Handles the connection from a client to a server class TCPConnection { public: /// A new TCP client TCPConnection(); /// Delete the TCP connection /// If the file descriptor is still open, it will be closed. virtual ~TCPConnection(); /// returns true if connected bool connected(); /// the remote hostname the client is connected to std::string host() const; /// the remote port the client is connected to int port() const; /// the error state of the TCP client bool error() const; /// returns true if the TCP connection has a valid file descriptor bool valid() const; /// true if the TCP connection has an invalid file descriptor bool invalid() const; /// return the file descriptor of the TCP connection int fd() const; /// connect to a remote host virtual void connect(std::string const &to_host, int to_port); /// disconnect from a remote host virtual void disconnect(); /// set the TCP connection to the error state void abort(); /// send outgoing data void send(std::string const &msg); protected: /// receive incoming data void receive(std::string &msg); private: int tcpconnection_fd; bool tcpconnection_error; std::string tcpconnection_host; int tcpconnection_port; }; } #endif // __INCLUDED_NET_TCPCONNECTION_H__