MCPcopy Create free account
hub / github.com/Kitware/VTK / read

Method read

ThirdParty/libproj/vtklibproj/src/networkfilemanager.cpp:1331–1456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1329// ---------------------------------------------------------------------------
1330
1331size_t NetworkFile::read(void *buffer, size_t sizeBytes) {
1332
1333 if (sizeBytes == 0)
1334 return 0;
1335
1336 auto iterOffset = m_pos;
1337 while (sizeBytes) {
1338 const auto chunkIdxToDownload = iterOffset / DOWNLOAD_CHUNK_SIZE;
1339 const auto offsetToDownload = chunkIdxToDownload * DOWNLOAD_CHUNK_SIZE;
1340 std::vector<unsigned char> region;
1341 auto pChunk = gNetworkChunkCache.get(m_ctx, m_url, chunkIdxToDownload);
1342 if (pChunk != nullptr) {
1343 region = *pChunk;
1344 } else {
1345 if (offsetToDownload == m_lastDownloadedOffset) {
1346 // In case of consecutive reads (of small size), we use a
1347 // heuristic that we will read the file sequentially, so
1348 // we double the requested size to decrease the number of
1349 // client/server roundtrips.
1350 if (m_nBlocksToDownload < 100)
1351 m_nBlocksToDownload *= 2;
1352 } else {
1353 // Random reads. Cancel the above heuristics.
1354 m_nBlocksToDownload = 1;
1355 }
1356
1357 // Ensure that we will request at least the number of blocks
1358 // to satisfy the remaining buffer size to read.
1359 const auto endOffsetToDownload =
1360 ((iterOffset + sizeBytes + DOWNLOAD_CHUNK_SIZE - 1) /
1361 DOWNLOAD_CHUNK_SIZE) *
1362 DOWNLOAD_CHUNK_SIZE;
1363 const auto nMinBlocksToDownload = static_cast<size_t>(
1364 (endOffsetToDownload - offsetToDownload) / DOWNLOAD_CHUNK_SIZE);
1365 if (m_nBlocksToDownload < nMinBlocksToDownload)
1366 m_nBlocksToDownload = nMinBlocksToDownload;
1367
1368 // Avoid reading already cached data.
1369 // Note: this might get evicted if concurrent reads are done, but
1370 // this should not cause bugs. Just missed optimization.
1371 for (size_t i = 1; i < m_nBlocksToDownload; i++) {
1372 if (gNetworkChunkCache.get(m_ctx, m_url,
1373 chunkIdxToDownload + i) != nullptr) {
1374 m_nBlocksToDownload = i;
1375 break;
1376 }
1377 }
1378
1379 if (m_nBlocksToDownload > MAX_CHUNKS)
1380 m_nBlocksToDownload = MAX_CHUNKS;
1381
1382 region.resize(m_nBlocksToDownload * DOWNLOAD_CHUNK_SIZE);
1383 size_t nRead = 0;
1384 std::string errorBuffer;
1385 errorBuffer.resize(1024);
1386 if (!m_handle) {
1387 m_handle = m_ctx->networking.open(
1388 m_ctx, m_url.c_str(), offsetToDownload,

Callers

nothing calls this directly

Calls 12

proj_context_errno_setFunction · 0.85
pj_logFunction · 0.85
clearMemoryCacheMethod · 0.80
minFunction · 0.50
getMethod · 0.45
resizeMethod · 0.45
openMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected