2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-01-18 14:35:03 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-07 13:29:33 -04:00
|
|
|
#include "common/common_funcs.h"
|
2020-07-11 21:26:24 -04:00
|
|
|
#include "common/common_types.h"
|
2018-01-18 14:35:03 -05:00
|
|
|
|
services/bsd: Implement most of bsd:s
This implements: Socket, Poll, Accept, Bind, Connect, GetPeerName,
GetSockName, Listen, Fcntl, SetSockOpt, Shutdown, Recv, RecvFrom,
Send, SendTo, Write, and Close
The implementation was done referencing: SwIPC, switchbrew, testing
with libnx and inspecting its code, general information about bsd
sockets online, and analysing official software.
Not everything from these service calls is implemented, but everything
that is not implemented will be logged in some way.
2020-07-11 21:37:47 -04:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::Sockets {
|
2018-01-18 14:35:03 -05:00
|
|
|
|
2020-07-11 21:26:24 -04:00
|
|
|
enum class Errno : u32 {
|
|
|
|
SUCCESS = 0,
|
|
|
|
BADF = 9,
|
|
|
|
AGAIN = 11,
|
|
|
|
INVAL = 22,
|
|
|
|
MFILE = 24,
|
2022-07-29 23:58:23 -04:00
|
|
|
MSGSIZE = 90,
|
2023-02-21 14:43:31 -05:00
|
|
|
CONNRESET = 104,
|
2020-07-11 21:26:24 -04:00
|
|
|
NOTCONN = 107,
|
2022-07-29 23:58:23 -04:00
|
|
|
TIMEDOUT = 110,
|
2020-07-11 21:26:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Domain : u32 {
|
|
|
|
INET = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Type : u32 {
|
|
|
|
STREAM = 1,
|
|
|
|
DGRAM = 2,
|
|
|
|
RAW = 3,
|
|
|
|
SEQPACKET = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Protocol : u32 {
|
|
|
|
UNSPECIFIED = 0,
|
|
|
|
ICMP = 1,
|
|
|
|
TCP = 6,
|
|
|
|
UDP = 17,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class OptName : u32 {
|
|
|
|
REUSEADDR = 0x4,
|
2022-04-07 17:05:50 -04:00
|
|
|
KEEPALIVE = 0x8,
|
2020-07-11 21:26:24 -04:00
|
|
|
BROADCAST = 0x20,
|
|
|
|
LINGER = 0x80,
|
|
|
|
SNDBUF = 0x1001,
|
|
|
|
RCVBUF = 0x1002,
|
|
|
|
SNDTIMEO = 0x1005,
|
|
|
|
RCVTIMEO = 0x1006,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ShutdownHow : s32 {
|
|
|
|
RD = 0,
|
|
|
|
WR = 1,
|
|
|
|
RDWR = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class FcntlCmd : s32 {
|
|
|
|
GETFL = 3,
|
|
|
|
SETFL = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SockAddrIn {
|
|
|
|
u8 len;
|
|
|
|
u8 family;
|
|
|
|
u16 portno;
|
|
|
|
std::array<u8, 4> ip;
|
|
|
|
std::array<u8, 8> zeroes;
|
|
|
|
};
|
|
|
|
|
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.
2020-08-31 10:20:44 -04:00
|
|
|
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);
|
|
|
|
|
2020-07-11 21:26:24 -04:00
|
|
|
struct PollFD {
|
|
|
|
s32 fd;
|
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.
2020-08-31 10:20:44 -04:00
|
|
|
PollEvents events;
|
|
|
|
PollEvents revents;
|
2020-07-11 21:26:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Linger {
|
|
|
|
u32 onoff;
|
|
|
|
u32 linger;
|
|
|
|
};
|
|
|
|
|
2023-02-18 16:26:48 -05:00
|
|
|
void LoopProcess(Core::System& system);
|
2018-01-18 14:35:03 -05:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::Sockets
|