sync AcceptStream

pull/1804/head
orignal 2 years ago
parent 85b78dfb9b
commit 78357baca4

@ -1362,6 +1362,26 @@ namespace stream
acceptor (stream);
}
std::shared_ptr<Stream> StreamingDestination::AcceptStream (int timeout)
{
std::shared_ptr<i2p::stream::Stream> stream;
std::condition_variable streamAccept;
std::mutex streamAcceptMutex;
std::unique_lock<std::mutex> l(streamAcceptMutex);
AcceptOnce (
[&streamAccept, &streamAcceptMutex, &stream](std::shared_ptr<i2p::stream::Stream> s)
{
stream = s;
std::unique_lock<std::mutex> l(streamAcceptMutex);
streamAccept.notify_all ();
});
if (timeout)
streamAccept.wait_for (l, std::chrono::seconds (timeout));
else
streamAccept.wait (l);
return stream;
}
void StreamingDestination::HandlePendingIncomingTimer (const boost::system::error_code& ecode)
{
if (ecode != boost::asio::error::operation_aborted)

@ -279,7 +279,8 @@ namespace stream
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
void AcceptOnce (const Acceptor& acceptor);
void AcceptOnceAcceptor (std::shared_ptr<Stream> stream, Acceptor acceptor, Acceptor prev);
std::shared_ptr<Stream> AcceptStream (int timeout = 0); // sync
std::shared_ptr<i2p::client::ClientDestination> GetOwner () const { return m_Owner; };
void SetOwner (std::shared_ptr<i2p::client::ClientDestination> owner) { m_Owner = owner; };
uint16_t GetLocalPort () const { return m_LocalPort; };

Loading…
Cancel
Save