Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sceNet #2060

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft

sceNet #2060

Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9200a86
restarted implementation - draft work
georgemoralis Jan 5, 2025
59e0543
abstract socket implementation (initial)
georgemoralis Jan 5, 2025
5fbdd41
clang fix
georgemoralis Jan 5, 2025
2b041b7
intial sceNetSetsockopt
georgemoralis Jan 5, 2025
70f12e9
added sceNetBind,sceNetListen
georgemoralis Jan 5, 2025
9d895fa
added ORBIS_NET_CTL_INFO_MTU
georgemoralis Jan 5, 2025
29bb111
added SO_BROADCAST (optname =32) in SetSocketOptions
georgemoralis Jan 5, 2025
aad0cca
draft epoll work
georgemoralis Jan 5, 2025
b28f36d
reuse fix
georgemoralis Jan 5, 2025
34b55d7
correct socketoption struct and added ORBIS_NET_SO_SNDTIMEO
georgemoralis Jan 7, 2025
d58570b
Implemented sceNetEpollControl,sceNetEpollDestroy
georgemoralis Jan 9, 2025
bdc5c41
missed files
georgemoralis Jan 9, 2025
b7ade1f
added SetSocketOptions:53: Unreachable code! Unknown level =65535 opt…
georgemoralis Jan 10, 2025
8a5706c
fake p2p sockets makes peggle2 works again
georgemoralis Jan 10, 2025
4cd856f
fixed possible issue in sceNetResolverStartAton (found in bloodborne …
georgemoralis Jan 10, 2025
6be8acf
added case in SetSocketOptions for tony hawk 5
georgemoralis Jan 10, 2025
b8d490f
implemented sceNetAccept
georgemoralis Jan 13, 2025
10582a7
added more setsocket options and some error returns
georgemoralis Jan 20, 2025
a0704de
added sceNetRecvfrom
georgemoralis Jan 20, 2025
b43cdfb
handled null name issues
georgemoralis Jan 20, 2025
b54d1b6
improved net_errno
georgemoralis Jan 20, 2025
44e10a6
added sceNetResolverStartNtoa
georgemoralis Jan 22, 2025
c4b0103
forgot file...
georgemoralis Jan 22, 2025
c0b0f23
added sceNetGetsockname
georgemoralis Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp
src/core/libraries/network/ssl.h
src/core/libraries/network/ssl2.cpp
src/core/libraries/network/ssl2.h
src/core/libraries/network/posix_sockets.cpp
src/core/libraries/network/p2p_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
Expand Down
37 changes: 37 additions & 0 deletions src/core/libraries/network/epoll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <common/assert.h>
#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;
}

int NetEpoll::Wait(OrbisNetEpollEvent* events, int maxevents, int timeout) {
return 0;
}

} // namespace Libraries::Net
91 changes: 91 additions & 0 deletions src/core/libraries/network/epoll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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;
};

enum SceNetEpollControlFlag : u32 {
ORBIS_NET_EPOLL_CTL_ADD = 1,
ORBIS_NET_EPOLL_CTL_MOD,
ORBIS_NET_EPOLL_CTL_DEL
};

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 FindEpoll(int sockid) {
std::scoped_lock lock{m_mutex};
const auto it = epolls.find(sockid);
if (it != epolls.end()) {
return it->second;
}
return 0;
}
int EraseEpoll(int eid) {
std::scoped_lock lock{m_mutex};
return epolls.erase(eid);
}

public:
std::mutex m_mutex;
typedef std::map<int, EpollPtr> NetEpolls;
NetEpolls epolls;
int next_epool_sock_id = 0;
};
} // namespace Libraries::Net
Loading