mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2025-06-23 20:27:53 -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:
@ -69,10 +69,22 @@ struct SockAddrIn {
|
||||
std::array<u8, 8> zeroes;
|
||||
};
|
||||
|
||||
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 {
|
||||
s32 fd;
|
||||
u16 events;
|
||||
u16 revents;
|
||||
PollEvents events;
|
||||
PollEvents revents;
|
||||
};
|
||||
|
||||
struct Linger {
|
||||
@ -80,13 +92,6 @@ struct Linger {
|
||||
u32 linger;
|
||||
};
|
||||
|
||||
constexpr u16 POLL_IN = 0x01;
|
||||
constexpr u16 POLL_PRI = 0x02;
|
||||
constexpr u16 POLL_OUT = 0x04;
|
||||
constexpr u16 POLL_ERR = 0x08;
|
||||
constexpr u16 POLL_HUP = 0x10;
|
||||
constexpr u16 POLL_NVAL = 0x20;
|
||||
|
||||
constexpr u32 FLAG_MSG_DONTWAIT = 0x80;
|
||||
|
||||
constexpr u32 FLAG_O_NONBLOCK = 0x800;
|
||||
|
Reference in New Issue
Block a user