summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-12 13:37:21 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-12 13:37:21 (GMT)
commit9d47ed3d783da724c653a17619df904fa7986be7 (patch)
tree64cfa4710a6eb41895b5f9e8bf41eb11250e3912
parent599bff3dfc47572b355c38562a9ceeb2b9f87268 (diff)
downloadswift-contrib-9d47ed3d783da724c653a17619df904fa7986be7.zip
swift-contrib-9d47ed3d783da724c653a17619df904fa7986be7.tar.bz2
Created IncomingConnection & ConnectionServer.
-rw-r--r--Limber/main.cpp11
-rw-r--r--Swiften/Network/ConnectionServer.cpp8
-rw-r--r--Swiften/Network/ConnectionServer.h15
-rw-r--r--Swiften/Network/IncomingConnection.cpp8
-rw-r--r--Swiften/Network/IncomingConnection.h17
-rw-r--r--Swiften/Network/Makefile.inc2
6 files changed, 55 insertions, 6 deletions
diff --git a/Limber/main.cpp b/Limber/main.cpp
index bc061e5..0893fc8 100644
--- a/Limber/main.cpp
+++ b/Limber/main.cpp
@@ -11,6 +11,8 @@
#include "Swiften/Base/ByteArray.h"
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/Network/IncomingConnection.h"
+#include "Swiften/Network/ConnectionServer.h"
using namespace Swift;
@@ -33,7 +35,7 @@ class SharedBuffer {
boost::asio::const_buffer buffer_;
};
-class IncomingBoostConnection : public boost::enable_shared_from_this<IncomingBoostConnection> {
+class IncomingBoostConnection : public IncomingConnection, public boost::enable_shared_from_this<IncomingBoostConnection> {
public:
typedef boost::shared_ptr<IncomingBoostConnection> pointer;
@@ -64,7 +66,6 @@ class IncomingBoostConnection : public boost::enable_shared_from_this<IncomingBo
}
boost::asio::ip::tcp::socket socket_;
- std::string message_;
};
class BoostIOServiceThread {
@@ -92,14 +93,12 @@ class BoostIOServiceThread {
boost::thread thread_;
};
-class BoostConnectionServer {
+class BoostConnectionServer : public ConnectionServer {
public:
BoostConnectionServer(int port, boost::asio::io_service& ioService) : acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) {
acceptNextConnection();
}
- boost::signal<void (IncomingBoostConnection::pointer)> onNewConnection;
-
private:
// Called from Asio thread
void acceptNextConnection() {
@@ -119,7 +118,7 @@ class BoostConnectionServer {
boost::asio::ip::tcp::acceptor acceptor_;
};
-void doSomething(IncomingBoostConnection::pointer c) {
+void doSomething(boost::shared_ptr<IncomingConnection> c) {
c->write("Hello\n");
}
diff --git a/Swiften/Network/ConnectionServer.cpp b/Swiften/Network/ConnectionServer.cpp
new file mode 100644
index 0000000..7f63fee
--- /dev/null
+++ b/Swiften/Network/ConnectionServer.cpp
@@ -0,0 +1,8 @@
+#include "Swiften/Network/ConnectionServer.h"
+
+namespace Swift {
+
+ConnectionServer::~ConnectionServer() {
+}
+
+}
diff --git a/Swiften/Network/ConnectionServer.h b/Swiften/Network/ConnectionServer.h
new file mode 100644
index 0000000..d376308
--- /dev/null
+++ b/Swiften/Network/ConnectionServer.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <boost/signal.hpp>
+
+#include "Swiften/Network/IncomingConnection.h"
+
+namespace Swift {
+ class ConnectionServer {
+ public:
+ virtual ~ConnectionServer();
+
+ boost::signal<void (boost::shared_ptr<IncomingConnection>)> onNewConnection;
+ };
+}
diff --git a/Swiften/Network/IncomingConnection.cpp b/Swiften/Network/IncomingConnection.cpp
new file mode 100644
index 0000000..669f68e
--- /dev/null
+++ b/Swiften/Network/IncomingConnection.cpp
@@ -0,0 +1,8 @@
+#include "Swiften/Network/IncomingConnection.h"
+
+namespace Swift {
+
+IncomingConnection::~IncomingConnection() {
+}
+
+}
diff --git a/Swiften/Network/IncomingConnection.h b/Swiften/Network/IncomingConnection.h
new file mode 100644
index 0000000..eaa2ad6
--- /dev/null
+++ b/Swiften/Network/IncomingConnection.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <boost/signal.hpp>
+
+#include "Swiften/Base/ByteArray.h"
+
+namespace Swift {
+ class IncomingConnection {
+ public:
+ virtual ~IncomingConnection();
+
+ virtual void write(const ByteArray& data) = 0;
+
+ //boost::signal<void (Error)> onError;
+ boost::signal<void (const ByteArray&)> onDataRead;
+ };
+}
diff --git a/Swiften/Network/Makefile.inc b/Swiften/Network/Makefile.inc
index 17b2838..b0f0fd1 100644
--- a/Swiften/Network/Makefile.inc
+++ b/Swiften/Network/Makefile.inc
@@ -4,6 +4,8 @@ SWIFTEN_SOURCES += \
Swiften/Network/ConnectionFactory.cpp \
Swiften/Network/BoostConnection.cpp \
Swiften/Network/BoostConnectionFactory.cpp \
+ Swiften/Network/ConnectionServer.cpp \
+ Swiften/Network/IncomingConnection.cpp \
Swiften/Network/Timer.cpp
include Swiften/Network/UnitTest/Makefile.inc