summaryrefslogtreecommitdiffstats
path: root/src/core/network
diff options
context:
space:
mode:
authorcomex <comexk@gmail.com>2020-08-31 16:20:44 +0200
committercomex <comexk@gmail.com>2020-12-07 01:14:42 +0100
commit0791082b435371837bbecd50575911ce0ba16dc9 (patch)
tree363be86931fe14b0ddc33be3b4119ae21c9a1543 /src/core/network
parentMerge pull request #5155 from comex/xx-default (diff)
downloadyuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar.gz
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar.bz2
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar.lz
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar.xz
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.tar.zst
yuzu-0791082b435371837bbecd50575911ce0ba16dc9.zip
Diffstat (limited to 'src/core/network')
-rw-r--r--src/core/network/network.cpp44
-rw-r--r--src/core/network/network.h24
2 files changed, 37 insertions, 31 deletions
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp
index 5ef2e8511..6cb5312ea 100644
--- a/src/core/network/network.cpp
+++ b/src/core/network/network.cpp
@@ -238,49 +238,49 @@ SockAddrIn TranslateToSockAddrIn(sockaddr input_) {
return result;
}
-u16 TranslatePollEvents(u32 events) {
- u32 result = 0;
+short TranslatePollEvents(PollEvents events) {
+ short result = 0;
- if ((events & POLL_IN) != 0) {
- events &= ~POLL_IN;
+ if (True(events & PollEvents::In)) {
+ events &= ~PollEvents::In;
result |= POLLIN;
}
- if ((events & POLL_PRI) != 0) {
- events &= ~POLL_PRI;
+ if (True(events & PollEvents::Pri)) {
+ events &= ~PollEvents::Pri;
#ifdef _WIN32
LOG_WARNING(Service, "Winsock doesn't support POLLPRI");
#else
- result |= POLL_PRI;
+ result |= POLLPRI;
#endif
}
- if ((events & POLL_OUT) != 0) {
- events &= ~POLL_OUT;
+ if (True(events & PollEvents::Out)) {
+ events &= ~PollEvents::Out;
result |= POLLOUT;
}
- UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events);
+ UNIMPLEMENTED_IF_MSG((u16)events != 0, "Unhandled guest events=0x{:x}", (u16)events);
- return static_cast<u16>(result);
+ return result;
}
-u16 TranslatePollRevents(u32 revents) {
- u32 result = 0;
- const auto translate = [&result, &revents](u32 host, u32 guest) {
+PollEvents TranslatePollRevents(short revents) {
+ PollEvents result{};
+ const auto translate = [&result, &revents](short host, PollEvents guest) {
if ((revents & host) != 0) {
- revents &= ~host;
+ revents &= static_cast<short>(~host);
result |= guest;
}
};
- translate(POLLIN, POLL_IN);
- translate(POLLPRI, POLL_PRI);
- translate(POLLOUT, POLL_OUT);
- translate(POLLERR, POLL_ERR);
- translate(POLLHUP, POLL_HUP);
+ translate(POLLIN, PollEvents::In);
+ translate(POLLPRI, PollEvents::Pri);
+ translate(POLLOUT, PollEvents::Out);
+ translate(POLLERR, PollEvents::Err);
+ translate(POLLHUP, PollEvents::Hup);
UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents);
- return static_cast<u16>(result);
+ return result;
}
template <typename T>
@@ -350,7 +350,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
}
for (size_t i = 0; i < num; ++i) {
- pollfds[i].revents = TranslatePollRevents(static_cast<u32>(host_pollfds[i].revents));
+ pollfds[i].revents = TranslatePollRevents(host_pollfds[i].revents);
}
if (result > 0) {
diff --git a/src/core/network/network.h b/src/core/network/network.h
index 0622e4593..76b2821f2 100644
--- a/src/core/network/network.h
+++ b/src/core/network/network.h
@@ -61,19 +61,25 @@ struct SockAddrIn {
};
/// Cross-platform poll fd structure
+
+enum class PollEvents : u16 {
+ // Using Pascal case because IN is a macro on Windows.
+ In = 1 << 0,
+ Pri = 1 << 1,
+ Out = 1 << 2,
+ Err = 1 << 3,
+ Hup = 1 << 4,
+ Nval = 1 << 5,
+};
+
+DECLARE_ENUM_FLAG_OPERATORS(PollEvents);
+
struct PollFD {
Socket* socket;
- u16 events;
- u16 revents;
+ PollEvents events;
+ PollEvents revents;
};
-constexpr u16 POLL_IN = 1 << 0;
-constexpr u16 POLL_PRI = 1 << 1;
-constexpr u16 POLL_OUT = 1 << 2;
-constexpr u16 POLL_ERR = 1 << 3;
-constexpr u16 POLL_HUP = 1 << 4;
-constexpr u16 POLL_NVAL = 1 << 5;
-
class NetworkInstance {
public:
explicit NetworkInstance();