From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../src/XorayaPluginExecutor/TcpServer.cpp | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Master/Masterarbeit/src/XorayaPluginExecutor/TcpServer.cpp (limited to 'Master/Masterarbeit/src/XorayaPluginExecutor/TcpServer.cpp') diff --git a/Master/Masterarbeit/src/XorayaPluginExecutor/TcpServer.cpp b/Master/Masterarbeit/src/XorayaPluginExecutor/TcpServer.cpp new file mode 100644 index 0000000..3ba91fd --- /dev/null +++ b/Master/Masterarbeit/src/XorayaPluginExecutor/TcpServer.cpp @@ -0,0 +1,90 @@ +/*! + * \file TcpServer.cpp + * \author S. Eisenhauer + * \date 27.10.2011 + * \brief Implementation of CTcpServer + */ +#include +#include "CPluginExecutor.h" +#include "global.h" +#include "TcpServer.h" + +CTcpServer::CTcpServer(CPluginExecutor* pxExecutor + ,boost::asio::io_service& xIoService + ,int32_t i32Port) +:m_xAcceptor( + xIoService, + boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(),i32Port) + ) + ,m_pxExecutor(pxExecutor) + ,m_xIoService(xIoService) +{ + DEBUG_PRINT("entry"); + vStartAccept(); + DEBUG_PRINT("exit"); +} + +CTcpServer::~CTcpServer(void) +{ + DEBUG_PRINT("entry"); + vStop(); + DEBUG_PRINT("exit"); +} + +void CTcpServer::vStartAccept() +{ + CTcpConnection::tConnectionPtr pNewCon + = CTcpConnection::pxCreate(xGetIoService(),m_pxExecutor); + if(pNewCon) + { + DEBUG_PRINT("new accept"); + } + else + { + ERROR_PRINT("could not get new connection object"); + return; + } + + 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->vSetActive(true); + pNewCon->vWaitForClientRequest(); + vStartAccept(); + } +} +void CTcpServer::vStop() +{ + DEBUG_PRINT("entry"); + xGetIoService().stop(); + DEBUG_PRINT("exit"); +} + +void CTcpServer::vUploadLogMessage(const tstLogMessage& stLogMsg) +{ +// DEBUG_PRINT("entry"); + + tConIter xConIter(g_astActiveConnections.begin()); + + // find free memory for a new connection + for(; xConIter != g_astActiveConnections.end(); ++xConIter) + { + CTcpConnection::tConnectionPtr pxCon = &(*xConIter); + if(pxCon->boIsActive()) + { + xGetIoService().post(boost::bind(&CTcpConnection::vUploadLogMessage, pxCon, stLogMsg)); + } + } +// DEBUG_PRINT("exit"); +} -- cgit v1.2.3