MCPcopy Create free account
hub / github.com/comaps/comaps / NextChunk

Method NextChunk

libs/platform/chunks_download_strategy.cpp:196–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196ChunksDownloadStrategy::ResultT ChunksDownloadStrategy::NextChunk(std::string & outUrl, RangeT & range)
197{
198 // If no servers at all.
199 if (m_servers.empty())
200 return EDownloadFailed;
201
202 // Find first free server.
203 ServerT * server = 0;
204 for (size_t i = 0; i < m_servers.size(); ++i)
205 {
206 if (m_servers[i].m_chunkIndex == SERVER_READY)
207 {
208 server = &m_servers[i];
209 break;
210 }
211 }
212 if (server == 0)
213 return ENoFreeServers;
214
215 bool allChunksDownloaded = true;
216
217 // Find first free chunk.
218 for (size_t i = 0; i < m_chunks.size() - 1; ++i)
219 {
220 switch (m_chunks[i].m_status)
221 {
222 case CHUNK_FREE:
223 server->m_chunkIndex = static_cast<int>(i);
224 outUrl = server->m_url;
225
226 range.first = m_chunks[i].m_pos;
227 range.second = m_chunks[i + 1].m_pos - 1;
228
229 m_chunks[i].m_status = CHUNK_DOWNLOADING;
230 LOG(LDEBUG, ("Download chunk", server->m_chunkIndex, "via", outUrl));
231 return ENextChunk;
232
233 case CHUNK_DOWNLOADING: allChunksDownloaded = false; break;
234 }
235 }
236
237 return (allChunksDownloaded ? EDownloadSucceeded : ENoFreeServers);
238}
239} // namespace downloader

Callers 2

StartThreadsMethod · 0.80
UNIT_TESTFunction · 0.80

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.64