mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
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:
committed by
GitHub
parent
93767ae31b
commit
26a92d97fa
@@ -20,6 +20,7 @@
|
||||
#include "core/libraries/kernel/orbis_error.h"
|
||||
#include "core/libraries/kernel/posix_error.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/sockets.h"
|
||||
#include "core/memory.h"
|
||||
#include "kernel.h"
|
||||
|
||||
@@ -257,6 +258,8 @@ s32 PS4_SYSV_ABI close(s32 fd) {
|
||||
}
|
||||
if (file->type == Core::FileSys::FileType::Regular) {
|
||||
file->f.Close();
|
||||
} else if (file->type == Core::FileSys::FileType::Socket) {
|
||||
file->socket->Close();
|
||||
}
|
||||
file->is_opened = false;
|
||||
LOG_INFO(Kernel_Fs, "Closing {}", file->m_guest_name);
|
||||
@@ -294,6 +297,13 @@ s64 PS4_SYSV_ABI write(s32 fd, const void* buf, size_t nbytes) {
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
} else if (file->type == Core::FileSys::FileType::Socket) {
|
||||
s64 result = file->socket->SendPacket(buf, nbytes, 0, nullptr, 0);
|
||||
if (result < 0) {
|
||||
ErrSceToPosix(result);
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return file->f.WriteRaw<u8>(buf, nbytes);
|
||||
@@ -475,6 +485,13 @@ s64 PS4_SYSV_ABI read(s32 fd, void* buf, size_t nbytes) {
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
} else if (file->type == Core::FileSys::FileType::Socket) {
|
||||
s64 result = file->socket->ReceivePacket(buf, nbytes, 0, nullptr, 0);
|
||||
if (result < 0) {
|
||||
ErrSceToPosix(result);
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ReadFile(file->f, buf, nbytes);
|
||||
}
|
||||
@@ -667,6 +684,14 @@ s32 PS4_SYSV_ABI fstat(s32 fd, OrbisKernelStat* sb) {
|
||||
// TODO incomplete
|
||||
break;
|
||||
}
|
||||
case Core::FileSys::FileType::Socket: {
|
||||
s32 result = file->socket->fstat(sb);
|
||||
if (result < 0) {
|
||||
ErrSceToPosix(result);
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
@@ -222,14 +222,15 @@ s32 PS4_SYSV_ABI posix_getpagesize() {
|
||||
|
||||
s32 PS4_SYSV_ABI posix_getsockname(Libraries::Net::OrbisNetId s,
|
||||
Libraries::Net::OrbisNetSockaddr* addr, u32* paddrlen) {
|
||||
auto* netcall = Common::Singleton<Libraries::Net::NetInternal>::Instance();
|
||||
auto sock = netcall->FindSocket(s);
|
||||
if (!sock) {
|
||||
LOG_INFO(Lib_Kernel, "s = {}", s);
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto file = h->GetSocket(s);
|
||||
if (!file) {
|
||||
*Libraries::Kernel::__Error() = ORBIS_NET_ERROR_EBADF;
|
||||
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
|
||||
return -1;
|
||||
}
|
||||
s32 returncode = sock->GetSocketAddress(addr, paddrlen);
|
||||
s32 returncode = file->socket->GetSocketAddress(addr, paddrlen);
|
||||
if (returncode >= 0) {
|
||||
LOG_ERROR(Lib_Net, "return code : {:#x}", (u32)returncode);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user