diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2022-07-26 00:31:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-26 00:31:45 +0200 |
commit | 1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2 (patch) | |
tree | 999411f1ca76390654d1034c6d0bd2c47c3f101c /src/core/internal_network/sockets.h | |
parent | Merge pull request #8564 from lat9nq/dinner-fork (diff) | |
parent | network: Address review comments (diff) | |
download | yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.gz yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.bz2 yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.lz yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.xz yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.zst yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.zip |
Diffstat (limited to 'src/core/internal_network/sockets.h')
-rw-r--r-- | src/core/internal_network/sockets.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/core/internal_network/sockets.h b/src/core/internal_network/sockets.h new file mode 100644 index 000000000..77e27e928 --- /dev/null +++ b/src/core/internal_network/sockets.h @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <map> +#include <memory> +#include <utility> + +#if defined(_WIN32) +#elif !YUZU_UNIX +#error "Platform not implemented" +#endif + +#include "common/common_types.h" +#include "core/internal_network/network.h" + +// 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); + + std::pair<s32, Errno> Recv(int flags, std::vector<u8>& message); + + std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr); + + std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags); + + 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); + + Errno SetKeepAlive(bool enable); + + 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; +#elif YUZU_UNIX + int fd = -1; +#endif +}; + +std::pair<s32, Errno> Poll(std::vector<PollFD>& poll_fds, s32 timeout); + +} // namespace Network |