From 83e8023c5e46635753a609329cf9805a3520001e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 13 Feb 2008 22:53:01 +0000 Subject: network subsystem initial import --- src/net/tcpconnection.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/net/tcpconnection.h (limited to 'src/net/tcpconnection.h') diff --git a/src/net/tcpconnection.h b/src/net/tcpconnection.h new file mode 100644 index 0000000..7e71ed0 --- /dev/null +++ b/src/net/tcpconnection.h @@ -0,0 +1,73 @@ +/* + 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 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__ -- cgit v1.2.3