#pragma once #include #include #include #include #include #include namespace Void::Net { class UdpSocket final { public: UdpSocket() noexcept = default; ~UdpSocket(); UdpSocket(UdpSocket&& other) noexcept; UdpSocket& operator=(UdpSocket&& other) noexcept; UdpSocket(const UdpSocket&) = delete; UdpSocket& operator=(const UdpSocket&) = delete; [[nodiscard]] static Void::Result::Result connect(std::string_view host, std::uint16_t port); [[nodiscard]] bool valid() const noexcept { return handle_ >= 0; } [[nodiscard]] int native_handle() const noexcept { return handle_; } void close() noexcept; void shutdown() noexcept; [[nodiscard]] Void::Result::Result wait_readable(std::chrono::milliseconds timeout) const; [[nodiscard]] Void::Result::Result send(std::span bytes); [[nodiscard]] Void::Result::Result receive(std::span destination); private: explicit UdpSocket(int handle) noexcept : handle_(handle) {} int handle_{-1}; }; }