mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2025-06-11 00:17:57 -05:00
network, sockets: Replace POLL_IN
, POLL_OUT
, etc. constants with an enum class PollEvents
Actually, two enum classes, since for some reason there are two separate yet identical `PollFD` types used in the codebase. I get that one is ABI-compatible with the Switch while the other is an abstract type used for the host, but why not use `WSAPOLLFD` directly for the latter? Anyway, why make this change? Because on Apple platforms, `POLL_IN`, `POLL_OUT`, etc. (with an underscore) are defined as macros in <sys/signal.h>. (This is inherited from FreeBSD.) So defining a variable with the same name causes a compile error. I could just rename the variables, but while I was at it I thought I might as well switch to an enum for stronger typing. Also, change the type used for values copied directly to/from the `events` and `revents` fields of the host *native* `pollfd`/`WSASPOLLFD`, from `u32` to `short`, as `short` is the correct canonical type on both Unix and Windows.
This commit is contained in:
@ -489,18 +489,18 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
|
||||
}
|
||||
|
||||
for (PollFD& pollfd : fds) {
|
||||
ASSERT(pollfd.revents == 0);
|
||||
ASSERT(False(pollfd.revents));
|
||||
|
||||
if (pollfd.fd > static_cast<s32>(MAX_FD) || pollfd.fd < 0) {
|
||||
LOG_ERROR(Service, "File descriptor handle={} is invalid", pollfd.fd);
|
||||
pollfd.revents = 0;
|
||||
pollfd.revents = PollEvents{};
|
||||
return {0, Errno::SUCCESS};
|
||||
}
|
||||
|
||||
const std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd];
|
||||
if (!descriptor) {
|
||||
LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd);
|
||||
pollfd.revents = POLL_NVAL;
|
||||
pollfd.revents = PollEvents::Nval;
|
||||
return {0, Errno::SUCCESS};
|
||||
}
|
||||
}
|
||||
@ -510,7 +510,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
|
||||
Network::PollFD result;
|
||||
result.socket = file_descriptors[pollfd.fd]->socket.get();
|
||||
result.events = TranslatePollEventsToHost(pollfd.events);
|
||||
result.revents = 0;
|
||||
result.revents = Network::PollEvents{};
|
||||
return result;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user