diff options
| author | 2020-07-21 16:05:47 +1000 | |
|---|---|---|
| committer | 2020-07-21 16:05:47 +1000 | |
| commit | e9bfe05e04f4a83cadb2cc036689921defb4e342 (patch) | |
| tree | 12910935b977f97b94a3af6ae3210c097940b407 /src/core/network/sockets.h | |
| parent | Merge pull request #4324 from ReinUsesLisp/formats (diff) | |
| parent | core/network: Add network abstraction (diff) | |
| download | yuzu-e9bfe05e04f4a83cadb2cc036689921defb4e342.tar.gz yuzu-e9bfe05e04f4a83cadb2cc036689921defb4e342.tar.xz yuzu-e9bfe05e04f4a83cadb2cc036689921defb4e342.zip | |
Merge pull request #4306 from ReinUsesLisp/bsd-network
core/network: Add network abstraction
Diffstat (limited to 'src/core/network/sockets.h')
| -rw-r--r-- | src/core/network/sockets.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/core/network/sockets.h b/src/core/network/sockets.h new file mode 100644 index 000000000..7bdff0fe4 --- /dev/null +++ b/src/core/network/sockets.h | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <utility> | ||
| 9 | |||
| 10 | #if defined(_WIN32) | ||
| 11 | #include <winsock.h> | ||
| 12 | #elif !defined(__unix__) | ||
| 13 | #error "Platform not implemented" | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #include "common/common_types.h" | ||
| 17 | #include "core/network/network.h" | ||
| 18 | |||
| 19 | // TODO: C++20 Replace std::vector usages with std::span | ||
| 20 | |||
| 21 | namespace Network { | ||
| 22 | |||
| 23 | class Socket { | ||
| 24 | public: | ||
| 25 | struct AcceptResult { | ||
| 26 | std::unique_ptr<Socket> socket; | ||
| 27 | SockAddrIn sockaddr_in; | ||
| 28 | }; | ||
| 29 | |||
| 30 | explicit Socket() = default; | ||
| 31 | ~Socket(); | ||
| 32 | |||
| 33 | Socket(const Socket&) = delete; | ||
| 34 | Socket& operator=(const Socket&) = delete; | ||
| 35 | |||
| 36 | Socket(Socket&& rhs) noexcept; | ||
| 37 | |||
| 38 | // Avoid closing sockets implicitly | ||
| 39 | Socket& operator=(Socket&&) noexcept = delete; | ||
| 40 | |||
| 41 | Errno Initialize(Domain domain, Type type, Protocol protocol); | ||
| 42 | |||
| 43 | Errno Close(); | ||
| 44 | |||
| 45 | std::pair<AcceptResult, Errno> Accept(); | ||
| 46 | |||
| 47 | Errno Connect(SockAddrIn addr_in); | ||
| 48 | |||
| 49 | std::pair<SockAddrIn, Errno> GetPeerName(); | ||
| 50 | |||
| 51 | std::pair<SockAddrIn, Errno> GetSockName(); | ||
| 52 | |||
| 53 | Errno Bind(SockAddrIn addr); | ||
| 54 | |||
| 55 | Errno Listen(s32 backlog); | ||
| 56 | |||
| 57 | Errno Shutdown(ShutdownHow how); | ||
| 58 | |||
| 59 | std::pair<s32, Errno> Recv(int flags, std::vector<u8>& message); | ||
| 60 | |||
| 61 | std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr); | ||
| 62 | |||
| 63 | std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags); | ||
| 64 | |||
| 65 | std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, const SockAddrIn* addr); | ||
| 66 | |||
| 67 | Errno SetLinger(bool enable, u32 linger); | ||
| 68 | |||
| 69 | Errno SetReuseAddr(bool enable); | ||
| 70 | |||
| 71 | Errno SetBroadcast(bool enable); | ||
| 72 | |||
| 73 | Errno SetSndBuf(u32 value); | ||
| 74 | |||
| 75 | Errno SetRcvBuf(u32 value); | ||
| 76 | |||
| 77 | Errno SetSndTimeo(u32 value); | ||
| 78 | |||
| 79 | Errno SetRcvTimeo(u32 value); | ||
| 80 | |||
| 81 | Errno SetNonBlock(bool enable); | ||
| 82 | |||
| 83 | bool IsOpened() const; | ||
| 84 | |||
| 85 | #if defined(_WIN32) | ||
| 86 | SOCKET fd = INVALID_SOCKET; | ||
| 87 | #elif defined(__unix__) | ||
| 88 | int fd = -1; | ||
| 89 | #endif | ||
| 90 | }; | ||
| 91 | |||
| 92 | std::pair<s32, Errno> Poll(std::vector<PollFD>& poll_fds, s32 timeout); | ||
| 93 | |||
| 94 | } // namespace Network | ||