add threadpool for ntcp dh

This commit is contained in:
Jeff Becker 2018-02-20 11:38:48 -05:00
parent b02464990b
commit 91fdb038d9
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
3 changed files with 98 additions and 17 deletions

View file

@ -171,27 +171,14 @@ namespace transport
return;
}
}
#if ((__GNUC__ == 4) && (__GNUC_MINOR__ <= 7)) || defined(__NetBSD__)
// due the bug in gcc 4.7. std::shared_future.get() is not const
if (!m_DHKeysPair)
m_DHKeysPair = transports.GetNextDHKeysPair ();
CreateAESKey (m_Establisher->phase1.pubKey);
SendPhase2 ();
#else
// TODO: check for number of pending keys
auto s = shared_from_this ();
auto keyCreated = std::async (std::launch::async, [s] ()
{
m_Server.Work(s, [s]() -> std::function<void(void)> {
if (!s->m_DHKeysPair)
s->m_DHKeysPair = transports.GetNextDHKeysPair ();
s->CreateAESKey (s->m_Establisher->phase1.pubKey);
}).share ();
m_Server.GetService ().post ([s, keyCreated]()
{
keyCreated.get ();
s->SendPhase2 ();
return std::bind(&NTCPSession::SendPhase2, s);
});
#endif
}
}
@ -788,12 +775,14 @@ namespace transport
}
//-----------------------------------------
NTCPServer::NTCPServer ():
NTCPServer::NTCPServer (int workers):
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service),
m_TerminationTimer (m_Service), m_NTCPAcceptor (nullptr), m_NTCPV6Acceptor (nullptr),
m_ProxyType(eNoProxy), m_Resolver(m_Service), m_ProxyEndpoint(nullptr),
m_SoftLimit(0), m_HardLimit(0)
{
if(workers <= 0) workers = 1;
m_CryptoPool = std::make_shared<Pool>(workers);
}
NTCPServer::~NTCPServer ()