Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tcpconnection.h')
-rw-r--r--src/net/tcpconnection.h73
1 files changed, 73 insertions, 0 deletions
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 <string>
+
+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__