1 #pragma once 2 3 // SPDX-License-Identifier: Apache-2.0 4 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 5 #include <unistd.h> 6 7 #include <boost/beast/core/file_posix.hpp> 8 9 struct DuplicatableFileHandle 10 { 11 boost::beast::file_posix fileHandle; 12 13 DuplicatableFileHandle() = default; 14 DuplicatableFileHandle(DuplicatableFileHandle&&) noexcept = default; 15 // Overload copy constructor, because posix doesn't have dup(), but linux 16 // does DuplicatableFileHandleDuplicatableFileHandle17 DuplicatableFileHandle(const DuplicatableFileHandle& other) 18 { 19 fileHandle.native_handle(dup(other.fileHandle.native_handle())); 20 } operator =DuplicatableFileHandle21 DuplicatableFileHandle& operator=(const DuplicatableFileHandle& other) 22 { 23 if (this == &other) 24 { 25 return *this; 26 } 27 fileHandle.native_handle(dup(other.fileHandle.native_handle())); 28 return *this; 29 } 30 DuplicatableFileHandle& operator=(DuplicatableFileHandle&& other) noexcept = 31 default; 32 ~DuplicatableFileHandle() = default; 33 }; 34