Browse Source

read incoming data util it's available

pull/120/head
orignal 10 years ago
parent
commit
46ea2291fe
  1. 15
      AddressBook.cpp

15
AddressBook.cpp

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

Loading…
Cancel
Save