mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 22:57:22 +00:00
Merge pull request #8943 from lioncash/netiface
sockets: Make fd member variable protected
This commit is contained in:
commit
70abb13a43
2 changed files with 17 additions and 6 deletions
|
@ -364,7 +364,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
|
||||||
std::vector<WSAPOLLFD> host_pollfds(pollfds.size());
|
std::vector<WSAPOLLFD> host_pollfds(pollfds.size());
|
||||||
std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) {
|
std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) {
|
||||||
WSAPOLLFD result;
|
WSAPOLLFD result;
|
||||||
result.fd = fd.socket->fd;
|
result.fd = fd.socket->GetFD();
|
||||||
result.events = TranslatePollEvents(fd.events);
|
result.events = TranslatePollEvents(fd.events);
|
||||||
result.revents = 0;
|
result.revents = 0;
|
||||||
return result;
|
return result;
|
||||||
|
@ -430,12 +430,12 @@ std::pair<SocketBase::AcceptResult, Errno> Socket::Accept() {
|
||||||
return {AcceptResult{}, GetAndLogLastError()};
|
return {AcceptResult{}, GetAndLogLastError()};
|
||||||
}
|
}
|
||||||
|
|
||||||
AcceptResult result;
|
|
||||||
result.socket = std::make_unique<Socket>();
|
|
||||||
result.socket->fd = new_socket;
|
|
||||||
|
|
||||||
ASSERT(addrlen == sizeof(sockaddr_in));
|
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};
|
return {std::move(result), Errno::SUCCESS};
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ public:
|
||||||
std::unique_ptr<SocketBase> socket;
|
std::unique_ptr<SocketBase> socket;
|
||||||
SockAddrIn sockaddr_in;
|
SockAddrIn sockaddr_in;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketBase() = default;
|
||||||
|
explicit SocketBase(SOCKET fd_) : fd{fd_} {}
|
||||||
|
|
||||||
virtual ~SocketBase() = default;
|
virtual ~SocketBase() = default;
|
||||||
|
|
||||||
virtual SocketBase& operator=(const SocketBase&) = delete;
|
virtual SocketBase& operator=(const SocketBase&) = delete;
|
||||||
|
@ -89,12 +93,19 @@ public:
|
||||||
|
|
||||||
virtual void HandleProxyPacket(const ProxyPacket& packet) = 0;
|
virtual void HandleProxyPacket(const ProxyPacket& packet) = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] SOCKET GetFD() const {
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
SOCKET fd = INVALID_SOCKET;
|
SOCKET fd = INVALID_SOCKET;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Socket : public SocketBase {
|
class Socket : public SocketBase {
|
||||||
public:
|
public:
|
||||||
Socket() = default;
|
Socket() = default;
|
||||||
|
explicit Socket(SOCKET fd_) : SocketBase{fd_} {}
|
||||||
|
|
||||||
~Socket() override;
|
~Socket() override;
|
||||||
|
|
||||||
Socket(const Socket&) = delete;
|
Socket(const Socket&) = delete;
|
||||||
|
|
Loading…
Reference in a new issue