Files
ppsspp/Common/File/PathBrowser.h
T
libretroadmin 5f0f72bfda Remove sleeps and timed polling from networking
Socket waits now block in select() on the socket plus a wake or cancel
socket (Common/Net/Cancel), so a stop or cancel ends them at once.

- HTTP: cancel flags become net::CancelToken; Connect waits once on all
  addresses, receives wait instead of spinning, no DNS retry sleep.
- Adhoc: the friend finder and adhoc server block on their sockets with
  a wake socket and a deadline; matching runs on a CoreTiming tick
  instead of two threads (savestate section bumped).
- sceNetInet select/poll check without blocking and park the HLE thread,
  re-checked from a CoreTiming event until ready or the emulated
  timeout.
- Vendor the aemu_postoffice client (was a submodule) with no sleeps:
  waits on the socket, close via shutdown and an eventcount, cancelable
  connects, and lock-free session slot claims.
- PortManager waits without a timeout; PSP_InitWait replaces the
  headless boot poll.
- TimeUtil: sleep_us/sleep_ms only outside the core; sleep_precise,
  sleep_random, yield and the Windows timer period are gone.
- Unit test for the socket waits.
2026-10-08 17:58:46 +02:00

78 lines
1.8 KiB
C++

#pragma once
#include <condition_variable>
#include <memory>
#include <mutex>
#include <string_view>
#include <cstring>
#include <thread>
#include <vector>
#include <cstdlib>
#include "Common/File/DirListing.h"
#include "Common/File/Path.h"
#include "Common/Net/Cancel.h"
// Abstraction above path that lets you navigate easily and get listings off-thread.
// "/" is a special path that means the root of the file system. On Windows,
// listing "/" will yield drives.
class PathBrowser {
public:
PathBrowser() {}
~PathBrowser();
void SetPath(const Path &path);
void Refresh() {
HandlePath();
}
bool IsListingReady() const {
std::lock_guard<std::mutex> guard(pendingLock_);
return ready_;
}
// If called before IsListingReady() returns true, will block (becomes synchronous). Don't do that.
bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, const net::CancelToken *cancel = nullptr);
bool CanNavigateUp() const;
void NavigateUp();
void Navigate(std::string_view subdir);
const Path &GetPath() const {
return path_;
}
void SetUserAgent(std::string_view s) {
std::lock_guard<std::mutex> guard(pendingLock_);
userAgent_ = s;
}
void RestrictToRoot(const Path &root);
bool empty() const {
return path_.empty();
}
bool Success() const {
std::lock_guard<std::mutex> guard(pendingLock_);
return success_;
}
private:
void HandlePath();
void CancelPending();
void ApplyRestriction();
Path path_;
Path pendingPath_;
Path restrictedRoot_;
std::string userAgent_;
std::vector<File::FileInfo> pendingFiles_;
std::condition_variable pendingCond_;
mutable std::mutex pendingLock_;
std::thread pendingThread_;
bool pendingActive_ = false;
bool pendingCancel_ = false;
std::shared_ptr<net::CancelToken> loadCancel_;
bool pendingStop_ = false;
bool ready_ = false;
bool success_ = true;
};