CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/FileLoaders/RetryingFileLoader.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Core/FileLoaders/RetryingFileLoader.h"1819// Takes ownership of backend.20RetryingFileLoader::RetryingFileLoader(FileLoader *backend)21: ProxiedFileLoader(backend) {22}2324bool RetryingFileLoader::Exists() {25if (!ProxiedFileLoader::Exists()) {26// Retry once, immediately.27return ProxiedFileLoader::Exists();28}29return true;30}3132bool RetryingFileLoader::ExistsFast() {33if (!ProxiedFileLoader::ExistsFast()) {34// Retry once, immediately.35return ProxiedFileLoader::ExistsFast();36}37return true;38}3940bool RetryingFileLoader::IsDirectory() {41// Can't tell if it's an error either way.42return ProxiedFileLoader::IsDirectory();43}4445s64 RetryingFileLoader::FileSize() {46s64 filesize = ProxiedFileLoader::FileSize();47if (filesize == 0) {48return ProxiedFileLoader::FileSize();49}50return filesize;51}5253size_t RetryingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {54size_t readSize = backend_->ReadAt(absolutePos, bytes, data, flags);5556int retries = 0;57while (readSize < bytes && retries < MAX_RETRIES) {58u8 *p = (u8 *)data;59readSize += backend_->ReadAt(absolutePos + readSize, bytes - readSize, p + readSize, flags);60++retries;61}6263return readSize;64}656667