draft epoll work

This commit is contained in:
georgemoralis 2025-01-06 00:52:02 +02:00
parent 6f8f9e1970
commit 65302b0267
4 changed files with 110 additions and 2 deletions

View File

@ -313,6 +313,8 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp
src/core/libraries/network/posix_sockets.cpp
src/core/libraries/network/sockets.h
src/core/libraries/network/net_error.h
src/core/libraries/network/epoll.cpp
src/core/libraries/network/epoll.h
)
set(AVPLAYER_LIB src/core/libraries/avplayer/avplayer_common.cpp

View File

@ -0,0 +1,20 @@
#include "epoll.h"
namespace Libraries::Net {
int NetEpoll::Add(int id, net_socket sock, OrbisNetEpollEvent* ev) {
return 0;
}
int NetEpoll::Del(int id, net_socket sock, OrbisNetEpollEvent* ev) {
return 0;
}
int NetEpoll::Mod(int id, net_socket sock, OrbisNetEpollEvent* ev) {
return 0;
}
int NetEpoll::Wait(OrbisNetEpollEvent* events, int maxevents, int timeout) {
return 0;
}
} // namespace Libraries::Net

View File

@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
#ifdef _WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Ws2tcpip.h>
#include <iphlpapi.h>
#include <winsock2.h>
typedef SOCKET net_socket;
typedef int socklen_t;
#else
#include <cerrno>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
typedef int net_socket;
#endif
#include <map>
#include <memory>
#include <mutex>
namespace Libraries::Net {
union OrbisNetEpollData {
void* ptr;
u32 _u32;
int fd;
u64 _u64;
};
struct OrbisNetEpollEvent {
u32 events;
u32 reserved;
u32 ident;
OrbisNetEpollData data;
};
struct EpollSocket {
unsigned int events;
OrbisNetEpollData data;
net_socket sock;
};
struct NetEpoll {
std::map<int, EpollSocket> eventEntries;
int Add(int id, net_socket sock, OrbisNetEpollEvent* ev);
int Del(int id, net_socket sock, OrbisNetEpollEvent* ev);
int Mod(int id, net_socket sock, OrbisNetEpollEvent* ev);
int Wait(OrbisNetEpollEvent* events, int maxevents, int timeout);
};
typedef std::shared_ptr<NetEpoll> EpollPtr;
class NetEpollInternal {
public:
explicit NetEpollInternal() = default;
~NetEpollInternal() = default;
EpollPtr FindSocket(int sockid) {
std::scoped_lock lock{m_mutex};
const auto it = epolls.find(sockid);
if (it != epolls.end()) {
return it->second;
}
return 0;
}
public:
std::mutex m_mutex;
typedef std::map<int, EpollPtr> NetEpolls;
NetEpolls epolls;
int next_epool_sock_id = 0;
};
} // namespace Libraries::Net

View File

@ -16,6 +16,7 @@
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
#include "core/libraries/network/net.h"
#include "epoll.h"
#include "net_error.h"
#include "sockets.h"
@ -560,8 +561,12 @@ int PS4_SYSV_ABI sceNetEpollControl() {
}
int PS4_SYSV_ABI sceNetEpollCreate(const char* name, int flags) {
LOG_ERROR(Lib_Net, "(STUBBED) called");
return ORBIS_OK;
LOG_ERROR(Lib_Net, "name = {} flags= {}", std::string(name), flags);
auto* net_epoll = Common::Singleton<NetEpollInternal>::Instance();
auto epoll = std::make_shared<NetEpoll>();
auto id = ++net_epoll->next_epool_sock_id;
net_epoll->epolls.emplace(id, epoll);
return id;
}
int PS4_SYSV_ABI sceNetEpollDestroy(int eid) {