Implemented sceNetEpollControl,sceNetEpollDestroy

This commit is contained in:
georgemoralis 2025-01-09 17:42:46 +02:00
parent 885182c1d3
commit 9af002a433
3 changed files with 31 additions and 2 deletions

View File

@ -1,18 +1,32 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <common/assert.h>
#include "epoll.h" #include "epoll.h"
#include "net_error.h"
namespace Libraries::Net { namespace Libraries::Net {
int NetEpoll::Add(int id, net_socket sock, OrbisNetEpollEvent* ev) { int NetEpoll::Add(int id, net_socket sock, OrbisNetEpollEvent* ev) {
if (!eventEntries.try_emplace(id, EpollSocket{ev->events, ev->data, sock}).second) {
return ORBIS_NET_ERROR_EEXIST;
}
return 0; return 0;
} }
int NetEpoll::Del(int id, net_socket sock, OrbisNetEpollEvent* ev) { int NetEpoll::Del(int id, net_socket sock, OrbisNetEpollEvent* ev) {
if (eventEntries.erase(id) == 0) {
return ORBIS_NET_ERROR_ENOENT;
}
return 0; return 0;
} }
int NetEpoll::Mod(int id, net_socket sock, OrbisNetEpollEvent* ev) { int NetEpoll::Mod(int id, net_socket sock, OrbisNetEpollEvent* ev) {
auto it = eventEntries.find(id);
if (it == eventEntries.end()) {
return ORBIS_NET_ERROR_ENOENT;
}
it->second.events = ev->events;
it->second.data = ev->data;
return 0; return 0;
} }

View File

@ -48,6 +48,12 @@ struct EpollSocket {
net_socket sock; net_socket sock;
}; };
enum SceNetEpollControlFlag : u32 {
ORBIS_NET_EPOLL_CTL_ADD = 1,
ORBIS_NET_EPOLL_CTL_MOD,
ORBIS_NET_EPOLL_CTL_DEL
};
struct NetEpoll { struct NetEpoll {
std::map<int, EpollSocket> eventEntries; std::map<int, EpollSocket> eventEntries;
@ -63,7 +69,7 @@ class NetEpollInternal {
public: public:
explicit NetEpollInternal() = default; explicit NetEpollInternal() = default;
~NetEpollInternal() = default; ~NetEpollInternal() = default;
EpollPtr FindSocket(int sockid) { EpollPtr FindEpoll(int sockid) {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
const auto it = epolls.find(sockid); const auto it = epolls.find(sockid);
if (it != epolls.end()) { if (it != epolls.end()) {
@ -71,6 +77,10 @@ public:
} }
return 0; return 0;
} }
int EraseEpoll(int eid) {
std::scoped_lock lock{m_mutex};
return epolls.erase(eid);
}
public: public:
std::mutex m_mutex; std::mutex m_mutex;

View File

@ -4,10 +4,15 @@
#pragma once #pragma once
// net errno codes // net errno codes
constexpr int ORBIS_NET_ENOENT = 2;
constexpr int ORBIS_NET_EBADF = 9; constexpr int ORBIS_NET_EBADF = 9;
constexpr int ORBIS_NET_EFAULT = 14; constexpr int ORBIS_NET_EFAULT = 14;
constexpr int ORBIS_NET_EEXIST = 17;
constexpr int ORBIS_NET_EINVAL = 22;
// error codes // error codes
constexpr int ORBIS_NET_ERROR_ENOENT = 0x80410102;
constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109; constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109;
constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e; constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e;
constexpr int ORBIS_NET_ERROR_EEXIST = 0x80410111;
constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;