diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index e38712767e..ebb093bd44 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -245,7 +245,8 @@ bool IsDirectory(const std::string &filename) std::wstring copy = ConvertUTF8ToWString(fn); WIN32_FILE_ATTRIBUTE_DATA data{}; if (!GetFileAttributesEx(copy.c_str(), GetFileExInfoStandard, &data) || data.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { - WARN_LOG(COMMON, "GetFileAttributes failed on %s: %08x", fn.c_str(), (uint32_t)GetLastError()); + auto err = GetLastError(); + WARN_LOG(COMMON, "GetFileAttributes failed on %s: %08x %s", fn.c_str(), (uint32_t)err, GetStringErrorMsg(err).c_str()); return false; } DWORD result = data.dwFileAttributes; @@ -311,7 +312,7 @@ bool CreateDir(const std::string &path) WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path.c_str()); return true; } - ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %08x", path.c_str(), (uint32_t)error); + ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %08x %s", path.c_str(), (uint32_t)error, GetStringErrorMsg(error).c_str()); return false; #else if (mkdir(fn.c_str(), 0755) == 0) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index fb86f96d6f..3dd540f326 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -337,17 +337,14 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & // Snarf all the data we can into RAM. A little unsafe but hey. static constexpr float CANCEL_INTERVAL = 0.25f; bool ready = false; - double leftTimeout = dataTimeout_; + double endTimeout = time_now_d() + dataTimeout_; while (!ready) { if (cancelled && *cancelled) return -1; ready = fd_util::WaitUntilReady(sock(), CANCEL_INTERVAL, false); - if (!ready && leftTimeout >= 0.0) { - leftTimeout -= CANCEL_INTERVAL; - if (leftTimeout < 0) { - ERROR_LOG(IO, "HTTP headers timed out"); - return -1; - } + if (!ready && time_now_d() > endTimeout) { + ERROR_LOG(IO, "HTTP headers timed out"); + return -1; } }; // Let's hope all the headers are available in a single packet... diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index 342f8f5604..2cc8901f05 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -75,7 +75,7 @@ public: protected: std::string userAgent_; const char *httpVersion_; - double dataTimeout_ = -1.0; + double dataTimeout_ = 900.0; }; // Not particularly efficient, but hey - it's a background download, that's pretty cool :P diff --git a/Common/Net/NetBuffer.cpp b/Common/Net/NetBuffer.cpp index 08059e76c8..377de82b5c 100644 --- a/Common/Net/NetBuffer.cpp +++ b/Common/Net/NetBuffer.cpp @@ -25,17 +25,14 @@ bool Buffer::FlushSocket(uintptr_t sock, double timeout, bool *cancelled) { static constexpr float CANCEL_INTERVAL = 0.25f; for (size_t pos = 0, end = data_.size(); pos < end; ) { bool ready = false; - double leftTimeout = timeout; - while (!ready && (leftTimeout >= 0 || cancelled)) { + double endTimeout = time_now_d() + timeout; + while (!ready) { if (cancelled && *cancelled) return false; ready = fd_util::WaitUntilReady(sock, CANCEL_INTERVAL, true); - if (!ready && leftTimeout >= 0.0) { - leftTimeout -= CANCEL_INTERVAL; - if (leftTimeout < 0) { - ERROR_LOG(IO, "FlushSocket timed out"); - return false; - } + if (!ready && time_now_d() > endTimeout) { + ERROR_LOG(IO, "FlushSocket timed out"); + return false; } } int sent = send(sock, &data_[pos], (int)(end - pos), MSG_NOSIGNAL); @@ -44,40 +41,11 @@ bool Buffer::FlushSocket(uintptr_t sock, double timeout, bool *cancelled) { return false; } pos += sent; - - // Buffer full, don't spin. - if (sent == 0 && timeout < 0.0) { - sleep_ms(1); - } } data_.resize(0); return true; } -bool Buffer::ReadAll(int fd, int hintSize) { - std::vector buf; - if (hintSize >= 65536 * 16) { - buf.resize(65536); - } else if (hintSize >= 1024 * 16) { - buf.resize(hintSize / 16); - } else { - buf.resize(4096); - } - - while (true) { - int retval = recv(fd, &buf[0], (int)buf.size(), MSG_NOSIGNAL); - if (retval == 0) { - break; - } else if (retval < 0) { - ERROR_LOG(IO, "Error reading from buffer: %i", retval); - return false; - } - char *p = Append((size_t)retval); - memcpy(p, &buf[0], retval); - } - return true; -} - bool Buffer::ReadAllWithProgress(int fd, int knownSize, float *progress, bool *cancelled) { static constexpr float CANCEL_INTERVAL = 0.25f; std::vector buf; diff --git a/Common/Net/NetBuffer.h b/Common/Net/NetBuffer.h index 3575dceddd..3ee7390aa3 100644 --- a/Common/Net/NetBuffer.h +++ b/Common/Net/NetBuffer.h @@ -6,9 +6,8 @@ namespace net { class Buffer : public ::Buffer { public: - bool FlushSocket(uintptr_t sock, double timeout = -1.0, bool *cancelled = nullptr); + bool FlushSocket(uintptr_t sock, double timeout, bool *cancelled = nullptr); - bool ReadAll(int fd, int hintSize = 0); bool ReadAllWithProgress(int fd, int knownSize, float *progress, bool *cancelled); // < 0: error diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 89869e7ca1..40184ee07d 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -36,6 +36,7 @@ #include "Common/File/FileUtil.h" #include "Common/File/DiskFree.h" #include "Common/File/VFS/VFS.h" +#include "Common/SysError.h" #include "Core/FileSystems/DirectoryFileSystem.h" #include "Core/FileSystems/ISOFileSystem.h" #include "Core/HLE/sceKernel.h" @@ -631,7 +632,8 @@ int DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const err = ReplayApplyDisk(ReplayAction::FILE_OPEN, err, CoreTiming::GetGlobalTimeUs()); if (err != 0) { #ifdef _WIN32 - ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile: FAILED, %i - access = %i", (int)GetLastError(), (int)access); + auto win32err = GetLastError(); + ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile: FAILED, %i - access = %i, %s", (int)win32err, (int)access, GetStringErrorMsg(win32err).c_str()); #else ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile: FAILED, %i - access = %i", errno, (int)access); #endif diff --git a/Core/Instance.cpp b/Core/Instance.cpp index a36aca0049..e8a5590dbd 100644 --- a/Core/Instance.cpp +++ b/Core/Instance.cpp @@ -25,14 +25,13 @@ #include #endif -#include "Common/Log.h" - #if PPSSPP_PLATFORM(WINDOWS) - #include "Common/CommonWindows.h" - #endif +#include "Common/Log.h" +#include "Common/SysError.h" + #include uint8_t PPSSPP_ID = 0; @@ -65,7 +64,8 @@ static bool UpdateInstanceCounter(void (*callback)(volatile InstanceInfo *)) { sizeof(InstanceInfo)); if (!buf) { - ERROR_LOG(SCENET, "Could not map view of file %s (%08x)", ID_SHM_NAME, (uint32_t)GetLastError()); + auto err = GetLastError(); + ERROR_LOG(SCENET, "Could not map view of file %s, %08x %s", ID_SHM_NAME, (uint32_t)err, GetStringErrorMsg(err).c_str()); return false; } @@ -137,7 +137,7 @@ void InitInstanceCounter() { DWORD lasterr = GetLastError(); if (!hIDMapFile) { - ERROR_LOG(SCENET, "Could not create %s file mapping object (%08x)", ID_SHM_NAME, (uint32_t)lasterr); + ERROR_LOG(SCENET, "Could not create %s file mapping object, %08x %s", ID_SHM_NAME, (uint32_t)lasterr, GetStringErrorMsg(lasterr).c_str()); PPSSPP_ID = 1; return; }