Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/netconnection.h')
-rw-r--r--src/core/netconnection.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
new file mode 100644
index 0000000..9a801ec
--- /dev/null
+++ b/src/core/netconnection.h
@@ -0,0 +1,58 @@
+/*
+ net/netconnection.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CORE_NETCONNECTION_H__
+#define __INCLUDED_CORE_NETCONNECTION_H__
+
+#include <sys/select.h>
+
+#include <string>
+#include <deque>
+#include <map>
+
+#include "net/tcpconnection.h"
+
+namespace core
+{
+
+/// a client to server connection
+class NetConnection : public net::TCPConnection
+{
+public:
+ NetConnection();
+ virtual ~NetConnection();
+
+ /// connect to a remote host
+ virtual void connect(std::string const &to_host, int to_port);
+
+ /// disconnect from a remote host
+ virtual void disconnect();
+
+ /// process pending incoming messages
+ void frame(float seconds);
+
+protected:
+ /// receive incoming data and store messages
+ void receive();
+
+ /// return true if there are incoming messages
+ bool has_messages() const;
+
+ /// retreive an incoming message
+ void retreive(std::string & message);
+
+ /// parse an incoming message
+ void parse_incoming_message(const std::string & message);
+
+private:
+ std::string messageblock;
+ std::deque<std::string> recvq;
+ fd_set clientset;
+};
+
+}
+
+#endif // __INCLUDED_CORE_NETCONNECTION_H__