From 46ea2291fece0efcb06fbe5ffeba16ccdbf70cd1 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 25 Dec 2014 10:42:49 -0500 Subject: [PATCH] read incoming data util it's available --- AddressBook.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index 1b842ca1..23fcfce3 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -311,10 +311,14 @@ namespace client std::string addr = s.substr(pos); i2p::data::IdentityEx ident; - ident.FromBase64(addr); - m_Addresses[name] = ident.GetIdentHash (); - m_Storage->AddAddress (ident); - numAddresses++; + 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"); @@ -453,17 +457,20 @@ namespace client { std::condition_variable newDataReceived; std::mutex newDataReceivedMutex; - std::unique_lock 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 - end = true; - newDataReceived.notify_one (); + { + if (ecode != boost::asio::error::timed_out || !stream->IsOpen ()) + end = true; + } + newDataReceived.notify_all (); }, 30); // wait for 30 seconds + std::unique_lock l(newDataReceivedMutex); newDataReceived.wait (l); } // parse response