Skip to content

Commit

Permalink
add move constructor to FdWrapper
Browse files Browse the repository at this point in the history
Summary: ^

Differential Revision: D64544295
  • Loading branch information
Alston Tang authored and facebook-github-bot committed Oct 21, 2024
1 parent 7527cb4 commit ea8672b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hbt/src/common/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ namespace facebook::hbt {

struct FdWrapper {
FdWrapper(const FdWrapper&) = delete;
FdWrapper(FdWrapper&&) = delete;
FdWrapper(FdWrapper&& other) noexcept {
fd = other.fd;
close_on_destruction = other.close_on_destruction;

other.fd = -1;
other.close_on_destruction = false;
}

explicit FdWrapper() {}

explicit FdWrapper(int fd) : fd{fd} {}
explicit FdWrapper(int fd) : FdWrapper(fd, false) {}

explicit FdWrapper(int fd, bool close_on_destruction)
: fd{fd}, close_on_destruction(close_on_destruction) {}

explicit FdWrapper(const std::string& path, int flags = O_RDONLY) {
fd = ::open(path.c_str(), flags);
Expand Down

0 comments on commit ea8672b

Please sign in to comment.