diff options
author | Ryo Hashimoto <hashimoto@google.com> | 2018-04-24 19:45:11 +0900 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-25 14:40:49 -0700 |
commit | a1880bb77cc066656d60af99bf1ba44eb522f08a (patch) | |
tree | 9ef13f6a5917503e43c4cc1dcaa5c6dbad87382a | |
parent | 7859c4ff82e9e42eeb59ff000c379e293a721ed7 (diff) | |
download | platform_external_libbrillo-a1880bb77cc066656d60af99bf1ba44eb522f08a.tar.gz platform_external_libbrillo-a1880bb77cc066656d60af99bf1ba44eb522f08a.tar.bz2 platform_external_libbrillo-a1880bb77cc066656d60af99bf1ba44eb522f08a.zip |
libbrillo: Add a way to construct FileDescriptor without duping FD
Add FileDescriptor(base::ScopedFD&&) and operator=(base::ScopedFD&&) to
create FileDescriptor without calling dup().
Also add release() to take the ownership of the FD without calling
dup().
BUG=None
TEST=build
Change-Id: Id96c3dc76e180bf11b674ad08d7d19f75f854c98
Reviewed-on: https://chromium-review.googlesource.com/1025332
Commit-Ready: Ryo Hashimoto <hashimoto@chromium.org>
Tested-by: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
-rw-r--r-- | brillo/dbus/file_descriptor.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/brillo/dbus/file_descriptor.h b/brillo/dbus/file_descriptor.h index 2c4a01b..f7be44f 100644 --- a/brillo/dbus/file_descriptor.h +++ b/brillo/dbus/file_descriptor.h @@ -24,6 +24,7 @@ struct FileDescriptor { FileDescriptor() = default; FileDescriptor(int fd) : fd(dup(fd)) {} FileDescriptor(FileDescriptor&& other) : fd(std::move(other.fd)) {} + FileDescriptor(base::ScopedFD&& other) : fd(std::move(other)) {} inline FileDescriptor& operator=(int new_fd) { fd.reset(dup(new_fd)); @@ -35,6 +36,13 @@ struct FileDescriptor { return *this; } + FileDescriptor& operator=(base::ScopedFD&& other) { + fd = std::move(other); + return *this; + } + + int release() { return fd.release(); } + int get() const { return fd.get(); } private: |