Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/ynl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
7 changes: 7 additions & 0 deletions lib/ynl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down