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 25 commits into
base: main
Choose a base branch
from
Draft

sceNet #2060

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
04ce728
restarted implementation - draft work
georgemoralis Jan 5, 2025
398e889
abstract socket implementation (initial)
georgemoralis Jan 5, 2025
b7e20af
clang fix
georgemoralis Jan 5, 2025
4092106
intial sceNetSetsockopt
georgemoralis Jan 5, 2025
b171143
added sceNetBind,sceNetListen
georgemoralis Jan 5, 2025
6b64502
added ORBIS_NET_CTL_INFO_MTU
georgemoralis Jan 5, 2025
a9ec78d
added SO_BROADCAST (optname =32) in SetSocketOptions
georgemoralis Jan 5, 2025
66f63b6
draft epoll work
georgemoralis Jan 5, 2025
60f14a1
reuse fix
georgemoralis Jan 5, 2025
f243508
correct socketoption struct and added ORBIS_NET_SO_SNDTIMEO
georgemoralis Jan 7, 2025
5665e8c
Implemented sceNetEpollControl,sceNetEpollDestroy
georgemoralis Jan 9, 2025
f8438e3
missed files
georgemoralis Jan 9, 2025
25f55f1
added SetSocketOptions:53: Unreachable code! Unknown level =65535 opt…
georgemoralis Jan 10, 2025
63d59a6
fake p2p sockets makes peggle2 works again
georgemoralis Jan 10, 2025
497ee15
fixed possible issue in sceNetResolverStartAton (found in bloodborne …
georgemoralis Jan 10, 2025
f4e637c
added case in SetSocketOptions for tony hawk 5
georgemoralis Jan 10, 2025
5f22274
implemented sceNetAccept
georgemoralis Jan 13, 2025
3902879
added more setsocket options and some error returns
georgemoralis Jan 20, 2025
43b1aa0
added sceNetRecvfrom
georgemoralis Jan 20, 2025
c056d18
handled null name issues
georgemoralis Jan 20, 2025
6dac66f
improved net_errno
georgemoralis Jan 20, 2025
3d0b2d1
implemented ORBIS_NET_CTL_INFO_ETHER_ADDR
georgemoralis Jan 27, 2025
028a624
linux mac fix?
georgemoralis Jan 27, 2025
2514d2b
fix linux-mac part2
georgemoralis Jan 27, 2025
0ad0a5a
linux fix?
georgemoralis Jan 27, 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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ 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
src/core/libraries/network/net_util.cpp
src/core/libraries/network/net_util.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