mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 19:27:49 +02:00
implement AcceptOnce for multiple acceptors
This commit is contained in:
parent
573ee0b584
commit
88a48a5c79
2 changed files with 25 additions and 0 deletions
|
@ -1037,6 +1037,29 @@ namespace stream
|
||||||
m_Acceptor = nullptr;
|
m_Acceptor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamingDestination::AcceptOnce (const Acceptor& acceptor)
|
||||||
|
{
|
||||||
|
m_Owner->GetService ().post([acceptor, this](void)
|
||||||
|
{
|
||||||
|
if (!m_PendingIncomingStreams.empty ())
|
||||||
|
{
|
||||||
|
acceptor (m_PendingIncomingStreams.front ());
|
||||||
|
m_PendingIncomingStreams.pop_front ();
|
||||||
|
if (m_PendingIncomingStreams.empty ())
|
||||||
|
m_PendingIncomingTimer.cancel ();
|
||||||
|
}
|
||||||
|
else // we must save old acceptor and set it back
|
||||||
|
{
|
||||||
|
auto oldAcceptor = m_Acceptor;
|
||||||
|
m_Acceptor = [acceptor, oldAcceptor, this](std::shared_ptr<Stream> stream)
|
||||||
|
{
|
||||||
|
acceptor (stream);
|
||||||
|
m_Acceptor = oldAcceptor;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void StreamingDestination::HandlePendingIncomingTimer (const boost::system::error_code& ecode)
|
void StreamingDestination::HandlePendingIncomingTimer (const boost::system::error_code& ecode)
|
||||||
{
|
{
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
|
|
@ -223,6 +223,8 @@ namespace stream
|
||||||
void SetAcceptor (const Acceptor& acceptor);
|
void SetAcceptor (const Acceptor& acceptor);
|
||||||
void ResetAcceptor ();
|
void ResetAcceptor ();
|
||||||
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
||||||
|
void AcceptOnce (const Acceptor& acceptor);
|
||||||
|
|
||||||
std::shared_ptr<i2p::client::ClientDestination> GetOwner () const { return m_Owner; };
|
std::shared_ptr<i2p::client::ClientDestination> GetOwner () const { return m_Owner; };
|
||||||
void SetOwner (std::shared_ptr<i2p::client::ClientDestination> owner) { m_Owner = owner; };
|
void SetOwner (std::shared_ptr<i2p::client::ClientDestination> owner) { m_Owner = owner; };
|
||||||
uint16_t GetLocalPort () const { return m_LocalPort; };
|
uint16_t GetLocalPort () const { return m_LocalPort; };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue