From 9af002a433ff4d693fcb20b85adeefea0eea7a67 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 9 Jan 2025 17:42:46 +0200 Subject: [PATCH] Implemented sceNetEpollControl,sceNetEpollDestroy --- src/core/libraries/network/epoll.cpp | 14 ++++++++++++++ src/core/libraries/network/epoll.h | 12 +++++++++++- src/core/libraries/network/net_error.h | 7 ++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/network/epoll.cpp b/src/core/libraries/network/epoll.cpp index 270c3bb49..da15cf37d 100644 --- a/src/core/libraries/network/epoll.cpp +++ b/src/core/libraries/network/epoll.cpp @@ -1,18 +1,32 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include "epoll.h" +#include "net_error.h" namespace Libraries::Net { 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; } int NetEpoll::Del(int id, net_socket sock, OrbisNetEpollEvent* ev) { + if (eventEntries.erase(id) == 0) { + return ORBIS_NET_ERROR_ENOENT; + } return 0; } 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; } diff --git a/src/core/libraries/network/epoll.h b/src/core/libraries/network/epoll.h index 902df96bf..ec6b5c61d 100644 --- a/src/core/libraries/network/epoll.h +++ b/src/core/libraries/network/epoll.h @@ -48,6 +48,12 @@ struct EpollSocket { net_socket sock; }; +enum SceNetEpollControlFlag : u32 { + ORBIS_NET_EPOLL_CTL_ADD = 1, + ORBIS_NET_EPOLL_CTL_MOD, + ORBIS_NET_EPOLL_CTL_DEL +}; + struct NetEpoll { std::map eventEntries; @@ -63,7 +69,7 @@ class NetEpollInternal { public: explicit NetEpollInternal() = default; ~NetEpollInternal() = default; - EpollPtr FindSocket(int sockid) { + EpollPtr FindEpoll(int sockid) { std::scoped_lock lock{m_mutex}; const auto it = epolls.find(sockid); if (it != epolls.end()) { @@ -71,6 +77,10 @@ public: } return 0; } + int EraseEpoll(int eid) { + std::scoped_lock lock{m_mutex}; + return epolls.erase(eid); + } public: std::mutex m_mutex; diff --git a/src/core/libraries/network/net_error.h b/src/core/libraries/network/net_error.h index a085d8aa5..88e3cac55 100644 --- a/src/core/libraries/network/net_error.h +++ b/src/core/libraries/network/net_error.h @@ -4,10 +4,15 @@ #pragma once // net errno codes - +constexpr int ORBIS_NET_ENOENT = 2; constexpr int ORBIS_NET_EBADF = 9; constexpr int ORBIS_NET_EFAULT = 14; +constexpr int ORBIS_NET_EEXIST = 17; +constexpr int ORBIS_NET_EINVAL = 22; // error codes +constexpr int ORBIS_NET_ERROR_ENOENT = 0x80410102; constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109; constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e; +constexpr int ORBIS_NET_ERROR_EEXIST = 0x80410111; +constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;