-
-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a1582b
commit 6b62ba2
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters