Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-16 12:22:33 +0000
committerStijn Buys <ingar@osirion.org>2008-02-16 12:22:33 +0000
commitd6ee7ec642cc6b3097c8d321a1a00630e24027d1 (patch)
tree35f56e5168cc3e12724898b9efb81b4b2938f575 /src/core/netconnection.h
parent715d0c3952a3a1d59b64074e472d0a9a3b414351 (diff)
initial client-to-server connection
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__