Branch data Line data Source code
1 : : #include "linux_file_descriptor.hpp" 2 : : 3 : : #include <unistd.h> 4 : : 5 : : #include <utility> 6 : : 7 : : namespace Linux 8 : : { 9 : : 10 : 1 : FileDescriptor::FileDescriptor(FileDescriptor&& other) noexcept 11 : 1 : : handle_(other.ReleaseNativeHandle()) 12 : : { 13 : 1 : } 14 : : 15 : 1 : auto FileDescriptor::operator=(FileDescriptor&& other) noexcept -> FileDescriptor& 16 : : { 17 : 1 : if (this == &other) { 18 : 0 : return *this; 19 : : } 20 : : 21 : 1 : if (handle_ != -1) { 22 : 0 : ::close(handle_); 23 : : } 24 : : 25 : 1 : handle_ = other.ReleaseNativeHandle(); 26 : : 27 : 1 : return *this; 28 : : } 29 : : 30 : 4 : FileDescriptor::~FileDescriptor() 31 : : { 32 : 4 : if (handle_ != -1) { 33 : 0 : ::close(handle_); 34 : : } 35 : 4 : } 36 : : 37 : 1 : FileDescriptor::FileDescriptor(int handle) 38 : 1 : : handle_(handle) 39 : : { 40 : 1 : } 41 : : 42 : 8 : auto FileDescriptor::GetNativeHandle() const noexcept -> int 43 : : { 44 : 8 : return handle_; 45 : : } 46 : : 47 : 8 : auto FileDescriptor::CheckNativeHandle() const noexcept -> bool 48 : : { 49 : 8 : return handle_ != -1; 50 : : } 51 : : 52 : 5 : auto FileDescriptor::ReleaseNativeHandle() noexcept -> int 53 : : { 54 : 5 : return std::exchange(handle_, -1); 55 : : } 56 : : 57 : : } // namespace Linux