read incoming data util it's available

This commit is contained in:
orignal 2014-12-25 10:42:49 -05:00
parent 66c2c7f789
commit 46ea2291fe

View File

@ -311,11 +311,15 @@ namespace client
std::string addr = s.substr(pos);
i2p::data::IdentityEx ident;
ident.FromBase64(addr);
if (ident.FromBase64(addr))
{
m_Addresses[name] = ident.GetIdentHash ();
m_Storage->AddAddress (ident);
numAddresses++;
}
else
LogPrint (eLogError, "Malformed address ", addr, " for ", name);
}
}
LogPrint (eLogInfo, numAddresses, " addresses processed");
if (numAddresses > 0)
@ -453,17 +457,20 @@ namespace client
{
std::condition_variable newDataReceived;
std::mutex newDataReceivedMutex;
std::unique_lock<std::mutex> l(newDataReceivedMutex);
stream->AsyncReceive (boost::asio::buffer (buf, 4096),
[&](const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
if (!ecode)
if (bytes_transferred)
response.write ((char *)buf, bytes_transferred);
else
{
if (ecode != boost::asio::error::timed_out || !stream->IsOpen ())
end = true;
newDataReceived.notify_one ();
}
newDataReceived.notify_all ();
},
30); // wait for 30 seconds
std::unique_lock<std::mutex> l(newDataReceivedMutex);
newDataReceived.wait (l);
}
// parse response