2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-07-12 02:42:56 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-12-25 20:27:52 +01:00
|
|
|
#include <map>
|
2020-07-12 02:42:56 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2020-08-31 16:09:06 +02:00
|
|
|
#elif !YUZU_UNIX
|
2020-07-12 02:42:56 +02:00
|
|
|
#error "Platform not implemented"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2021-12-25 20:27:52 +01:00
|
|
|
#include "core/internal_network/network.h"
|
2020-07-12 02:42:56 +02:00
|
|
|
|
|
|
|
// TODO: C++20 Replace std::vector usages with std::span
|
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
|
|
|
class Socket {
|
|
|
|
public:
|
|
|
|
struct AcceptResult {
|
|
|
|
std::unique_ptr<Socket> socket;
|
|
|
|
SockAddrIn sockaddr_in;
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit Socket() = default;
|
|
|
|
~Socket();
|
|
|
|
|
|
|
|
Socket(const Socket&) = delete;
|
|
|
|
Socket& operator=(const Socket&) = delete;
|
|
|
|
|
|
|
|
Socket(Socket&& rhs) noexcept;
|
|
|
|
|
|
|
|
// Avoid closing sockets implicitly
|
|
|
|
Socket& operator=(Socket&&) noexcept = delete;
|
|
|
|
|
|
|
|
Errno Initialize(Domain domain, Type type, Protocol protocol);
|
|
|
|
|
|
|
|
Errno Close();
|
|
|
|
|
|
|
|
std::pair<AcceptResult, Errno> Accept();
|
|
|
|
|
|
|
|
Errno Connect(SockAddrIn addr_in);
|
|
|
|
|
|
|
|
std::pair<SockAddrIn, Errno> GetPeerName();
|
|
|
|
|
|
|
|
std::pair<SockAddrIn, Errno> GetSockName();
|
|
|
|
|
|
|
|
Errno Bind(SockAddrIn addr);
|
|
|
|
|
|
|
|
Errno Listen(s32 backlog);
|
|
|
|
|
|
|
|
Errno Shutdown(ShutdownHow how);
|
|
|
|
|
2020-10-21 04:07:39 +02:00
|
|
|
std::pair<s32, Errno> Recv(int flags, std::vector<u8>& message);
|
2020-07-12 02:42:56 +02:00
|
|
|
|
2020-10-21 04:07:39 +02:00
|
|
|
std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr);
|
2020-07-12 02:42:56 +02:00
|
|
|
|
2020-10-21 04:07:39 +02:00
|
|
|
std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags);
|
2020-07-12 02:42:56 +02:00
|
|
|
|
|
|
|
std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, const SockAddrIn* addr);
|
|
|
|
|
|
|
|
Errno SetLinger(bool enable, u32 linger);
|
|
|
|
|
|
|
|
Errno SetReuseAddr(bool enable);
|
|
|
|
|
2022-04-07 23:05:50 +02:00
|
|
|
Errno SetKeepAlive(bool enable);
|
|
|
|
|
2020-07-12 02:42:56 +02:00
|
|
|
Errno SetBroadcast(bool enable);
|
|
|
|
|
|
|
|
Errno SetSndBuf(u32 value);
|
|
|
|
|
|
|
|
Errno SetRcvBuf(u32 value);
|
|
|
|
|
|
|
|
Errno SetSndTimeo(u32 value);
|
|
|
|
|
|
|
|
Errno SetRcvTimeo(u32 value);
|
|
|
|
|
|
|
|
Errno SetNonBlock(bool enable);
|
|
|
|
|
|
|
|
bool IsOpened() const;
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
SOCKET fd = INVALID_SOCKET;
|
2020-08-31 16:09:06 +02:00
|
|
|
#elif YUZU_UNIX
|
2020-07-12 02:42:56 +02:00
|
|
|
int fd = -1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
std::pair<s32, Errno> Poll(std::vector<PollFD>& poll_fds, s32 timeout);
|
|
|
|
|
|
|
|
} // namespace Network
|