Remove illegal MovableValue<void *> usage.
GitOrigin-RevId: 1daee39044131e396183ee20baa589b96ba27eb4
This commit is contained in:
parent
b3d513da55
commit
1313fb1543
@ -104,7 +104,7 @@ FdSet &get_fd_set() {
|
|||||||
|
|
||||||
Status NativeFd::validate() const {
|
Status NativeFd::validate() const {
|
||||||
#if TD_FD_DEBUG
|
#if TD_FD_DEBUG
|
||||||
return get_fd_set().validate(fd_.get());
|
return get_fd_set().validate(fd_);
|
||||||
#else
|
#else
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
#endif
|
#endif
|
||||||
@ -113,13 +113,13 @@ Status NativeFd::validate() const {
|
|||||||
NativeFd::NativeFd(Fd fd) : fd_(fd) {
|
NativeFd::NativeFd(Fd fd) : fd_(fd) {
|
||||||
VLOG(fd) << *this << " create";
|
VLOG(fd) << *this << " create";
|
||||||
#if TD_FD_DEBUG
|
#if TD_FD_DEBUG
|
||||||
get_fd_set().on_create_fd(fd_.get());
|
get_fd_set().on_create_fd(fd_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::NativeFd(Fd fd, bool nolog) : fd_(fd) {
|
NativeFd::NativeFd(Fd fd, bool nolog) : fd_(fd) {
|
||||||
#if TD_FD_DEBUG
|
#if TD_FD_DEBUG
|
||||||
get_fd_set().on_create_fd(fd_.get());
|
get_fd_set().on_create_fd(fd_);
|
||||||
#endif
|
#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) {
|
NativeFd::NativeFd(Socket socket) : fd_(reinterpret_cast<Fd>(socket)), is_socket_(true) {
|
||||||
VLOG(fd) << *this << " create";
|
VLOG(fd) << *this << " create";
|
||||||
#if TD_FD_DEBUG
|
#if TD_FD_DEBUG
|
||||||
get_fd_set().on_create_fd(fd_.get());
|
get_fd_set().on_create_fd(fd_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NativeFd &NativeFd::operator=(NativeFd &&from) {
|
NativeFd::NativeFd(NativeFd &&other) : fd_(other.fd_) {
|
||||||
CHECK(this != &from);
|
|
||||||
close();
|
|
||||||
fd_ = std::move(from.fd_);
|
|
||||||
#if TD_PORT_WINDOWS
|
#if TD_PORT_WINDOWS
|
||||||
is_socket_ = from.is_socket_;
|
is_socket_ = other.is_socket_;
|
||||||
#endif
|
#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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +155,7 @@ NativeFd::~NativeFd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::operator bool() const {
|
NativeFd::operator bool() const {
|
||||||
return fd_.get() != empty_fd();
|
return fd_ != empty_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::Fd NativeFd::empty_fd() {
|
NativeFd::Fd NativeFd::empty_fd() {
|
||||||
@ -159,7 +167,7 @@ NativeFd::Fd NativeFd::empty_fd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::Fd NativeFd::fd() const {
|
NativeFd::Fd NativeFd::fd() const {
|
||||||
return fd_.get();
|
return fd_;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::Socket NativeFd::socket() const {
|
NativeFd::Socket NativeFd::socket() const {
|
||||||
@ -167,7 +175,7 @@ NativeFd::Socket NativeFd::socket() const {
|
|||||||
return fd();
|
return fd();
|
||||||
#elif TD_PORT_WINDOWS
|
#elif TD_PORT_WINDOWS
|
||||||
CHECK(is_socket_);
|
CHECK(is_socket_);
|
||||||
return reinterpret_cast<Socket>(fd_.get());
|
return reinterpret_cast<Socket>(fd_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,13 +239,13 @@ void NativeFd::close() {
|
|||||||
auto error = OS_ERROR("Close fd");
|
auto error = OS_ERROR("Close fd");
|
||||||
LOG(ERROR) << error;
|
LOG(ERROR) << error;
|
||||||
}
|
}
|
||||||
fd_ = {};
|
fd_ = empty_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeFd::Fd NativeFd::release() {
|
NativeFd::Fd NativeFd::release() {
|
||||||
VLOG(fd) << *this << " release";
|
VLOG(fd) << *this << " release";
|
||||||
auto res = fd_.get();
|
auto res = fd_;
|
||||||
fd_ = {};
|
fd_ = empty_fd();
|
||||||
#if TD_FD_DEBUG
|
#if TD_FD_DEBUG
|
||||||
get_fd_set().on_close_fd(res);
|
get_fd_set().on_close_fd(res);
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "td/utils/port/config.h"
|
#include "td/utils/port/config.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/MovableValue.h"
|
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
@ -25,8 +24,6 @@ class NativeFd {
|
|||||||
using Socket = SOCKET;
|
using Socket = SOCKET;
|
||||||
#endif
|
#endif
|
||||||
NativeFd() = default;
|
NativeFd() = default;
|
||||||
NativeFd(NativeFd &&) = default;
|
|
||||||
NativeFd &operator=(NativeFd &&);
|
|
||||||
explicit NativeFd(Fd fd);
|
explicit NativeFd(Fd fd);
|
||||||
NativeFd(Fd fd, bool nolog);
|
NativeFd(Fd fd, bool nolog);
|
||||||
#if TD_PORT_WINDOWS
|
#if TD_PORT_WINDOWS
|
||||||
@ -34,12 +31,12 @@ class NativeFd {
|
|||||||
#endif
|
#endif
|
||||||
NativeFd(const NativeFd &) = delete;
|
NativeFd(const NativeFd &) = delete;
|
||||||
NativeFd &operator=(const NativeFd &) = delete;
|
NativeFd &operator=(const NativeFd &) = delete;
|
||||||
|
NativeFd(NativeFd &&other);
|
||||||
|
NativeFd &operator=(NativeFd &&other);
|
||||||
~NativeFd();
|
~NativeFd();
|
||||||
|
|
||||||
explicit operator bool() const;
|
explicit operator bool() const;
|
||||||
|
|
||||||
static Fd empty_fd();
|
|
||||||
|
|
||||||
Fd fd() const;
|
Fd fd() const;
|
||||||
Socket socket() const;
|
Socket socket() const;
|
||||||
|
|
||||||
@ -55,10 +52,10 @@ class NativeFd {
|
|||||||
Status validate() const;
|
Status validate() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if TD_PORT_POSIX
|
static Fd empty_fd();
|
||||||
MovableValue<Fd, -1> fd_;
|
|
||||||
#elif TD_PORT_WINDOWS
|
Fd fd_ = empty_fd();
|
||||||
MovableValue<Fd, INVALID_HANDLE_VALUE> fd_;
|
#if TD_PORT_WINDOWS
|
||||||
bool is_socket_{false};
|
bool is_socket_{false};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user