diff options
Diffstat (limited to 'Master/Masterarbeit/src/Xoraya_Stub/Xoraya_Stub/TcpServer.cpp')
| -rw-r--r-- | Master/Masterarbeit/src/Xoraya_Stub/Xoraya_Stub/TcpServer.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Master/Masterarbeit/src/Xoraya_Stub/Xoraya_Stub/TcpServer.cpp b/Master/Masterarbeit/src/Xoraya_Stub/Xoraya_Stub/TcpServer.cpp new file mode 100644 index 0000000..a0509d5 --- /dev/null +++ b/Master/Masterarbeit/src/Xoraya_Stub/Xoraya_Stub/TcpServer.cpp @@ -0,0 +1,47 @@ +#include "StdAfx.h"
+#include "TcpServer.h"
+#include <boost/bind.hpp>
+#include "XorayaExecutor.h"
+
+CTcpServer::CTcpServer(boost::shared_ptr<CXorayaExecutor> pxExecutor
+ ,boost::asio::io_service& io_service
+ , int i32Port)
+:m_xAcceptor(
+ io_service,
+ boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(),i32Port)
+ )
+ ,m_pxExecutor(pxExecutor)
+ ,m_io_service(io_service)
+{
+ vStartAccept();
+}
+
+CTcpServer::~CTcpServer(void)
+{
+}
+
+void CTcpServer::vStartAccept()
+{
+ CTcpConnection::tConnectionPtr pNewCon
+ = CTcpConnection::pxCreate(m_io_service,m_pxExecutor);
+
+ std::cout << __FUNCTION__ << " new accept " << std::endl;
+
+ m_xAcceptor.async_accept(pNewCon->xGetSocket(),
+ boost::bind(
+ &CTcpServer::vAcceptHandler,
+ this,
+ pNewCon,
+ boost::asio::placeholders::error
+ )
+ );
+}
+
+void CTcpServer::vAcceptHandler(CTcpConnection::tConnectionPtr pNewCon, const boost::system::error_code& error)
+{
+ if(!error)
+ {
+ pNewCon->vStart();
+ vStartAccept();
+ }
+}
\ No newline at end of file |
