common RuunableBase with private inheritance

This commit is contained in:
orignal 2020-02-04 11:48:56 -05:00
parent b982be5ff5
commit 969f9aa436
13 changed files with 43 additions and 95 deletions

View file

@ -823,7 +823,7 @@ namespace client
}
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params):
RunnableService ("Destination"), LeaseSetDestination (GetService (), isPublic, params),
RunnableService ("Destination"), LeaseSetDestination (GetIOService (), isPublic, params),
m_Keys (keys), m_StreamingAckDelay (DEFAULT_INITIAL_ACK_DELAY),
m_DatagramDestination (nullptr), m_RefCounter (0),
m_ReadyChecker(GetService())
@ -905,7 +905,7 @@ namespace client
m_StreamingDestination->Start ();
for (auto& it: m_StreamingDestinationsByPorts)
it.second->Start ();
StartService ();
StartIOService ();
}
}
@ -929,7 +929,7 @@ namespace client
delete m_DatagramDestination;
m_DatagramDestination = nullptr;
}
StopService ();
StopIOService ();
}
}

View file

@ -102,6 +102,7 @@ namespace client
LeaseSetDestination (boost::asio::io_service& service, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
~LeaseSetDestination ();
const std::string& GetNickname () const { return m_Nickname; };
boost::asio::io_service& GetService () { return m_Service; };
virtual void Start ();
virtual void Stop ();
@ -191,7 +192,7 @@ namespace client
bool IsPerClientAuth () const { return m_AuthType > 0; };
};
class ClientDestination: public i2p::util::RunnableService, public LeaseSetDestination
class ClientDestination: private i2p::util::RunnableService, public LeaseSetDestination
{
public:
#ifdef I2LUA

View file

@ -1155,7 +1155,7 @@ namespace transport
{
if (!IsRunning ())
{
StartService ();
StartIOService ();
auto& addresses = context.GetRouterInfo ().GetAddresses ();
for (const auto& address: addresses)
{
@ -1217,7 +1217,7 @@ namespace transport
if (IsRunning ())
m_TerminationTimer.cancel ();
StopService ();
StopIOService ();
}
bool NTCP2Server::AddNTCP2Session (std::shared_ptr<NTCP2Session> session, bool incoming)

View file

@ -216,7 +216,7 @@ namespace transport
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
};
class NTCP2Server: public i2p::util::RunnableServiceWithWork
class NTCP2Server: private i2p::util::RunnableServiceWithWork
{
public:
@ -225,6 +225,7 @@ namespace transport
void Start ();
void Stop ();
boost::asio::io_service& GetService () { return GetIOService (); };
bool AddNTCP2Session (std::shared_ptr<NTCP2Session> session, bool incoming = false);
void RemoveNTCP2Session (std::shared_ptr<NTCP2Session> session);

View file

@ -58,7 +58,7 @@ namespace i2p
namespace util
{
void RunnableService::StartService ()
void RunnableService::StartIOService ()
{
if (!m_IsRunning)
{
@ -67,7 +67,7 @@ namespace util
}
}
void RunnableService::StopService ()
void RunnableService::StopIOService ()
{
if (m_IsRunning)
{
@ -245,10 +245,10 @@ namespace net
#else
std::string localAddressUniversal = localAddress.to_string();
#endif
typedef int (* IPN)(int af, const char *src, void *dst);
typedef int (* IPN)(int af, const char *src, void *dst);
IPN inetpton = (IPN)GetProcAddress (GetModuleHandle ("ws2_32.dll"), "InetPton");
if (!inetpton) inetpton = inet_pton_xp; // use own implementation if not found
if (!inetpton) inetpton = inet_pton_xp; // use own implementation if not found
if(localAddress.is_v4())
{

View file

@ -125,16 +125,16 @@ namespace util
class RunnableService
{
public:
protected:
RunnableService (const std::string& name): m_Name (name), m_IsRunning (false) {}
virtual ~RunnableService () {}
boost::asio::io_service& GetService () { return m_Service; }
boost::asio::io_service& GetIOService () { return m_Service; }
bool IsRunning () const { return m_IsRunning; };
void StartService ();
void StopService ();
void StartIOService ();
void StopIOService ();
private:
@ -150,10 +150,10 @@ namespace util
class RunnableServiceWithWork: public RunnableService
{
public:
protected:
RunnableServiceWithWork (const std::string& name):
RunnableService (name), m_Work (GetService ()) {}
RunnableService (name), m_Work (GetIOService ()) {}
private: