mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
common RunnableService
This commit is contained in:
parent
85b88b8749
commit
49810eb153
4 changed files with 90 additions and 49 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue