Remove illegal MovableValue<void *> usage.

GitOrigin-RevId: 1daee39044131e396183ee20baa589b96ba27eb4
This commit is contained in:
levlam 2020-01-30 22:11:04 +03:00
parent b3d513da55
commit 1313fb1543
2 changed files with 29 additions and 24 deletions

View File

@ -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<Fd>(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<Socket>(fd_.get());
return reinterpret_cast<Socket>(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

View File

@ -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, -1> fd_;
#elif TD_PORT_WINDOWS
MovableValue<Fd, INVALID_HANDLE_VALUE> fd_;
static Fd empty_fd();
Fd fd_ = empty_fd();
#if TD_PORT_WINDOWS
bool is_socket_{false};
#endif
};