Sockets are now files (#3319)

* Socket support for read/write/fstat

* Sockets are now files

* Fix ssize_t for windows

* Return posix error codes in net functions
This commit is contained in:
Marcin Mikołajczyk
2025-07-28 23:20:10 +02:00
committed by GitHub
parent 93767ae31b
commit 26a92d97fa
10 changed files with 182 additions and 92 deletions

View File

@@ -219,6 +219,18 @@ File* HandleTable::GetFile(int d) {
return m_files.at(d);
}
File* HandleTable::GetSocket(int d) {
std::scoped_lock lock{m_mutex};
if (d < 0 || d >= m_files.size()) {
return nullptr;
}
auto file = m_files.at(d);
if (file->type != Core::FileSys::FileType::Socket) {
return nullptr;
}
return file;
}
File* HandleTable::GetFile(const std::filesystem::path& host_name) {
for (auto* file : m_files) {
if (file != nullptr && file->m_host_name == host_name) {

View File

@@ -12,6 +12,10 @@
#include "common/logging/formatter.h"
#include "core/devices/base_device.h"
namespace Libraries::Net {
struct Socket;
}
namespace Core::FileSys {
class MntPoints {
@@ -77,6 +81,7 @@ enum class FileType {
Regular, // standard file
Directory,
Device,
Socket,
};
struct File {
@@ -88,7 +93,8 @@ struct File {
std::vector<DirEntry> dirents;
u32 dirents_index;
std::mutex m_mutex;
std::shared_ptr<Devices::BaseDevice> device; // only valid for type == Device
std::shared_ptr<Devices::BaseDevice> device; // only valid for type == Device
std::shared_ptr<Libraries::Net::Socket> socket; // only valid for type == Socket
};
class HandleTable {
@@ -99,6 +105,7 @@ public:
int CreateHandle();
void DeleteHandle(int d);
File* GetFile(int d);
File* GetSocket(int d);
File* GetFile(const std::filesystem::path& host_name);
int GetFileDescriptor(File* file);