Browse Source

unlock mutex for good after wait

pull/1833/head
orignal 2 years ago
parent
commit
3e3e2c41bd
  1. 10
      libi2pd/Streaming.cpp

10
libi2pd/Streaming.cpp

@ -481,7 +481,6 @@ namespace stream @@ -481,7 +481,6 @@ namespace stream
volatile bool done = false;
std::condition_variable newDataReceived;
std::mutex newDataReceivedMutex;
std::unique_lock<std::mutex> l(newDataReceivedMutex);
AsyncReceive (boost::asio::buffer (buf, len),
[&ret, &done, &newDataReceived, &newDataReceivedMutex](const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
@ -490,12 +489,15 @@ namespace stream @@ -490,12 +489,15 @@ namespace stream
else
ret = bytes_transferred;
std::unique_lock<std::mutex> l(newDataReceivedMutex);
done = true;
newDataReceived.notify_all ();
done = true;
},
timeout);
if (newDataReceived.wait_for (l, std::chrono::seconds (timeout)) == std::cv_status::timeout)
ret = 0;
if (!done)
{ std::unique_lock<std::mutex> l(newDataReceivedMutex);
if (!done && newDataReceived.wait_for (l, std::chrono::seconds (timeout)) == std::cv_status::timeout)
ret = 0;
}
if (!done)
{
// make sure that AsycReceive complete

Loading…
Cancel
Save