diff --git a/lib/ynl-cpp.cpp b/lib/ynl-cpp.cpp index 2a72b8d..dbbf834 100644 --- a/lib/ynl-cpp.cpp +++ b/lib/ynl-cpp.cpp @@ -6,6 +6,22 @@ ynl_socket::ynl_socket(const ynl_family& family, struct ynl_error* err) { sock_ = ynl_sock_create(&family, err); } +ynl_socket::ynl_socket(ynl_socket&& other) noexcept : sock_(other.sock_) { + other.sock_ = nullptr; +} + +ynl_socket& ynl_socket::operator=(ynl_socket&& other) noexcept { + if (this == &other) + return *this; + + if (sock_) + ynl_sock_destroy(sock_); + + sock_ = other.sock_; + other.sock_ = nullptr; + return *this; +} + ynl_socket::~ynl_socket() { if (sock_) { ynl_sock_destroy(sock_); diff --git a/lib/ynl.hpp b/lib/ynl.hpp index 87d851b..65d9177 100644 --- a/lib/ynl.hpp +++ b/lib/ynl.hpp @@ -14,6 +14,13 @@ namespace ynl_cpp { class ynl_socket { public: explicit ynl_socket(const ynl_family& family, ynl_error* err = nullptr); + + ynl_socket(const ynl_socket&) = delete; + ynl_socket& operator=(const ynl_socket&) = delete; + + ynl_socket(ynl_socket&& other) noexcept; + ynl_socket& operator=(ynl_socket&& other) noexcept; + ~ynl_socket(); operator bool() const {