Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2012-06-30 04:09:24 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:40:25 +0300
commit117222c2068aa783263722a65b76f8c95d432143 (patch)
tree5ee1973ceb8bd83006b3b2dab9836c601f60344a /platform
parent65e502c38bac4fdf1c4738861aeaa8d09391a6e9 (diff)
[downloader] Handle exceptions correctly in downloader for FileWriter manipulations.
Diffstat (limited to 'platform')
-rw-r--r--platform/chunks_download_strategy.cpp1
-rw-r--r--platform/chunks_download_strategy.hpp2
-rw-r--r--platform/http_request.cpp41
-rw-r--r--platform/http_thread_callback.hpp2
4 files changed, 36 insertions, 10 deletions
diff --git a/platform/chunks_download_strategy.cpp b/platform/chunks_download_strategy.cpp
index 6e24acb73b..b6cd42f79d 100644
--- a/platform/chunks_download_strategy.cpp
+++ b/platform/chunks_download_strategy.cpp
@@ -23,7 +23,6 @@ ChunksDownloadStrategy::GetChunk(RangeT const & range)
{
vector<ChunkT>::iterator i = lower_bound(m_chunks.begin(), m_chunks.end(), range.first, LessChunks());
- // find server which was downloading this chunk
if (i != m_chunks.end() && i->m_pos == range.first)
{
ASSERT_EQUAL ( (i+1)->m_pos, range.second + 1, () );
diff --git a/platform/chunks_download_strategy.hpp b/platform/chunks_download_strategy.hpp
index d6ab853941..c3ae0cd841 100644
--- a/platform/chunks_download_strategy.hpp
+++ b/platform/chunks_download_strategy.hpp
@@ -48,6 +48,8 @@ private:
};
typedef pair<int64_t, int64_t> RangeT;
+
+ /// @return Chunk pointer and it's index for given file offsets range.
pair<ChunkT *, int> GetChunk(RangeT const & range);
public:
diff --git a/platform/http_request.cpp b/platform/http_request.cpp
index e2ded9c01b..a86bf89c61 100644
--- a/platform/http_request.cpp
+++ b/platform/http_request.cpp
@@ -58,12 +58,13 @@ class MemoryHttpRequest : public HttpRequest, public IHttpThreadCallback
string m_downloadedData;
MemWriter<string> m_writer;
- virtual void OnWrite(int64_t, void const * buffer, size_t size)
+ virtual bool OnWrite(int64_t, void const * buffer, size_t size)
{
m_writer.Write(buffer, size);
m_progress.first += size;
if (m_onProgress)
m_onProgress(*this);
+ return true;
}
virtual void OnFinish(long httpCode, int64_t, int64_t)
@@ -77,6 +78,7 @@ public:
: HttpRequest(onFinish, onProgress), m_writer(m_downloadedData)
{
m_thread = CreateNativeHttpThread(url, *this);
+ ASSERT ( m_thread, () );
}
MemoryHttpRequest(string const & url, string const & postData,
@@ -84,6 +86,7 @@ public:
: HttpRequest(onFinish, onProgress), m_writer(m_downloadedData)
{
m_thread = CreateNativeHttpThread(url, *this, 0, -1, -1, postData);
+ ASSERT ( m_thread, () );
}
virtual ~MemoryHttpRequest()
@@ -116,8 +119,11 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
pair<int64_t, int64_t> range;
ChunksDownloadStrategy::ResultT result;
while ((result = m_strategy.NextChunk(url, range)) == ChunksDownloadStrategy::ENextChunk)
- m_threads.push_back(make_pair(CreateNativeHttpThread(url, *this, range.first, range.second,
- m_progress.second), range.first));
+ {
+ HttpThread * p = CreateNativeHttpThread(url, *this, range.first, range.second, m_progress.second);
+ ASSERT ( p, () );
+ m_threads.push_back(make_pair(p, range.first));
+ }
return result;
}
@@ -130,18 +136,27 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
m_threads.erase(it);
return;
}
- ASSERT(false, ("Tried to remove invalid thread?"));
+ ASSERT ( false, ("Tried to remove invalid thread?") );
}
- virtual void OnWrite(int64_t offset, void const * buffer, size_t size)
+ virtual bool OnWrite(int64_t offset, void const * buffer, size_t size)
{
#ifdef DEBUG
static threads::ThreadID const id = threads::GetCurrentThreadID();
ASSERT_EQUAL(id, threads::GetCurrentThreadID(), ("OnWrite called from different threads"));
#endif
- m_writer->Seek(offset);
- m_writer->Write(buffer, size);
+ try
+ {
+ m_writer->Seek(offset);
+ m_writer->Write(buffer, size);
+ return true;
+ }
+ catch (Writer::Exception const & ex)
+ {
+ LOG(LWARNING, ("Can't write buffer for size = ", size));
+ return false;
+ }
}
/// Called for each chunk by one main (GUI) thread.
@@ -185,7 +200,17 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
if (m_status != EInProgress)
{
- m_writer.reset();
+ try
+ {
+ m_writer.reset();
+ }
+ catch (Writer::Exception const & ex)
+ {
+ LOG(LWARNING, ("Can't close file correctly. There is not enough space, possibly."));
+
+ ASSERT_EQUAL ( m_status, EFailed, () );
+ m_status = EFailed;
+ }
// clean up resume file with chunks range on success
if (m_status == ECompleted)
diff --git a/platform/http_thread_callback.hpp b/platform/http_thread_callback.hpp
index da3e19810d..3b827bed35 100644
--- a/platform/http_thread_callback.hpp
+++ b/platform/http_thread_callback.hpp
@@ -8,7 +8,7 @@ namespace downloader
class IHttpThreadCallback
{
public:
- virtual void OnWrite(int64_t offset, void const * buffer, size_t size) = 0;
+ virtual bool OnWrite(int64_t offset, void const * buffer, size_t size) = 0;
virtual void OnFinish(long httpCode, int64_t begRange, int64_t endRange) = 0;
};