diff --git a/tdutils/td/utils/port/detail/NativeFd.cpp b/tdutils/td/utils/port/detail/NativeFd.cpp index 009465166..3899b4a71 100644 --- a/tdutils/td/utils/port/detail/NativeFd.cpp +++ b/tdutils/td/utils/port/detail/NativeFd.cpp @@ -104,7 +104,7 @@ FdSet &get_fd_set() { Status NativeFd::validate() const { #if TD_FD_DEBUG - return get_fd_set().validate(fd_.get()); + return get_fd_set().validate(fd_); #else return Status::OK(); #endif @@ -113,13 +113,13 @@ Status NativeFd::validate() const { NativeFd::NativeFd(Fd fd) : fd_(fd) { VLOG(fd) << *this << " create"; #if TD_FD_DEBUG - get_fd_set().on_create_fd(fd_.get()); + get_fd_set().on_create_fd(fd_); #endif } NativeFd::NativeFd(Fd fd, bool nolog) : fd_(fd) { #if TD_FD_DEBUG - get_fd_set().on_create_fd(fd_.get()); + get_fd_set().on_create_fd(fd_); #endif } @@ -127,18 +127,26 @@ NativeFd::NativeFd(Fd fd, bool nolog) : fd_(fd) { NativeFd::NativeFd(Socket socket) : fd_(reinterpret_cast(socket)), is_socket_(true) { VLOG(fd) << *this << " create"; #if TD_FD_DEBUG - get_fd_set().on_create_fd(fd_.get()); + get_fd_set().on_create_fd(fd_); #endif } #endif -NativeFd &NativeFd::operator=(NativeFd &&from) { - CHECK(this != &from); - close(); - fd_ = std::move(from.fd_); +NativeFd::NativeFd(NativeFd &&other) : fd_(other.fd_) { #if TD_PORT_WINDOWS - is_socket_ = from.is_socket_; + is_socket_ = other.is_socket_; #endif + other.fd_ = empty_fd(); +} + +NativeFd &NativeFd::operator=(NativeFd &&other) { + CHECK(this != &other); + close(); + fd_ = other.fd_; +#if TD_PORT_WINDOWS + is_socket_ = other.is_socket_; +#endif + other.fd_ = empty_fd(); return *this; } @@ -147,7 +155,7 @@ NativeFd::~NativeFd() { } NativeFd::operator bool() const { - return fd_.get() != empty_fd(); + return fd_ != empty_fd(); } NativeFd::Fd NativeFd::empty_fd() { @@ -159,7 +167,7 @@ NativeFd::Fd NativeFd::empty_fd() { } NativeFd::Fd NativeFd::fd() const { - return fd_.get(); + return fd_; } NativeFd::Socket NativeFd::socket() const { @@ -167,7 +175,7 @@ NativeFd::Socket NativeFd::socket() const { return fd(); #elif TD_PORT_WINDOWS CHECK(is_socket_); - return reinterpret_cast(fd_.get()); + return reinterpret_cast(fd_); #endif } @@ -231,13 +239,13 @@ void NativeFd::close() { auto error = OS_ERROR("Close fd"); LOG(ERROR) << error; } - fd_ = {}; + fd_ = empty_fd(); } NativeFd::Fd NativeFd::release() { VLOG(fd) << *this << " release"; - auto res = fd_.get(); - fd_ = {}; + auto res = fd_; + fd_ = empty_fd(); #if TD_FD_DEBUG get_fd_set().on_close_fd(res); #endif diff --git a/tdutils/td/utils/port/detail/NativeFd.h b/tdutils/td/utils/port/detail/NativeFd.h index e57d8afc7..f6dcce9b6 100644 --- a/tdutils/td/utils/port/detail/NativeFd.h +++ b/tdutils/td/utils/port/detail/NativeFd.h @@ -9,7 +9,6 @@ #include "td/utils/port/config.h" #include "td/utils/common.h" -#include "td/utils/MovableValue.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" @@ -25,8 +24,6 @@ class NativeFd { using Socket = SOCKET; #endif NativeFd() = default; - NativeFd(NativeFd &&) = default; - NativeFd &operator=(NativeFd &&); explicit NativeFd(Fd fd); NativeFd(Fd fd, bool nolog); #if TD_PORT_WINDOWS @@ -34,12 +31,12 @@ class NativeFd { #endif NativeFd(const NativeFd &) = delete; NativeFd &operator=(const NativeFd &) = delete; + NativeFd(NativeFd &&other); + NativeFd &operator=(NativeFd &&other); ~NativeFd(); explicit operator bool() const; - static Fd empty_fd(); - Fd fd() const; Socket socket() const; @@ -55,10 +52,10 @@ class NativeFd { Status validate() const; private: -#if TD_PORT_POSIX - MovableValue fd_; -#elif TD_PORT_WINDOWS - MovableValue fd_; + static Fd empty_fd(); + + Fd fd_ = empty_fd(); +#if TD_PORT_WINDOWS bool is_socket_{false}; #endif };