common RunnableService

This commit is contained in:
orignal 2020-02-02 17:05:30 -05:00
parent 85b88b8749
commit 49810eb153
4 changed files with 90 additions and 49 deletions

View file

@ -5,6 +5,7 @@
#include <functional>
#include <memory>
#include <mutex>
#include <thread>
#include <utility>
#include <boost/asio.hpp>
@ -122,6 +123,43 @@ namespace util
std::mutex m_Mutex;
};
class RunnableService
{
public:
RunnableService (const std::string& name): m_Name (name), m_IsRunning (false) {}
virtual ~RunnableService () {}
boost::asio::io_service& GetService () { return m_Service; }
bool IsRunning () const { return m_IsRunning; };
void StartService ();
void StopService ();
private:
void Run ();
private:
std::string m_Name;
bool m_IsRunning;
std::unique_ptr<std::thread> m_Thread;
boost::asio::io_service m_Service;
};
class RunnableServiceWithWork: public RunnableService
{
public:
RunnableServiceWithWork (const std::string& name):
RunnableService (name), m_Work (GetService ()) {}
private:
boost::asio::io_service::work m_Work;
};
namespace net
{
int GetMTU (const boost::asio::ip::address& localAddress);