summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2022-09-23 15:08:07 +0200
committerGitHub <noreply@github.com>2022-09-23 15:08:07 +0200
commit70abb13a434a5089bce284433c6df19b46ff27d2 (patch)
tree9c5696dfb3798bd9b772c4abbf2a55b77501cf2d /src
parentMerge pull request #8939 from lioncash/render (diff)
parentsockets: Make fd member variable protected (diff)
downloadyuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar.gz
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar.bz2
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar.lz
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar.xz
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.tar.zst
yuzu-70abb13a434a5089bce284433c6df19b46ff27d2.zip
Diffstat (limited to 'src')
-rw-r--r--src/core/internal_network/network.cpp12
-rw-r--r--src/core/internal_network/sockets.h11
2 files changed, 17 insertions, 6 deletions
diff --git a/src/core/internal_network/network.cpp b/src/core/internal_network/network.cpp
index cdf38a2a4..447fbffaa 100644
--- a/src/core/internal_network/network.cpp
+++ b/src/core/internal_network/network.cpp
@@ -364,7 +364,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
std::vector<WSAPOLLFD> host_pollfds(pollfds.size());
std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) {
WSAPOLLFD result;
- result.fd = fd.socket->fd;
+ result.fd = fd.socket->GetFD();
result.events = TranslatePollEvents(fd.events);
result.revents = 0;
return result;
@@ -430,12 +430,12 @@ std::pair<SocketBase::AcceptResult, Errno> Socket::Accept() {
return {AcceptResult{}, GetAndLogLastError()};
}
- AcceptResult result;
- result.socket = std::make_unique<Socket>();
- result.socket->fd = new_socket;
-
ASSERT(addrlen == sizeof(sockaddr_in));
- result.sockaddr_in = TranslateToSockAddrIn(addr);
+
+ AcceptResult result{
+ .socket = std::make_unique<Socket>(new_socket),
+ .sockaddr_in = TranslateToSockAddrIn(addr),
+ };
return {std::move(result), Errno::SUCCESS};
}
diff --git a/src/core/internal_network/sockets.h b/src/core/internal_network/sockets.h
index a70429b19..2e328c645 100644
--- a/src/core/internal_network/sockets.h
+++ b/src/core/internal_network/sockets.h
@@ -32,6 +32,10 @@ public:
std::unique_ptr<SocketBase> socket;
SockAddrIn sockaddr_in;
};
+
+ SocketBase() = default;
+ explicit SocketBase(SOCKET fd_) : fd{fd_} {}
+
virtual ~SocketBase() = default;
virtual SocketBase& operator=(const SocketBase&) = delete;
@@ -89,12 +93,19 @@ public:
virtual void HandleProxyPacket(const ProxyPacket& packet) = 0;
+ [[nodiscard]] SOCKET GetFD() const {
+ return fd;
+ }
+
+protected:
SOCKET fd = INVALID_SOCKET;
};
class Socket : public SocketBase {
public:
Socket() = default;
+ explicit Socket(SOCKET fd_) : SocketBase{fd_} {}
+
~Socket() override;
Socket(const Socket&) = delete;