blob: b8f91144ccb54a38649dd87ea6df1fc490946a05 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanousd7857202025-01-28 15:32:26 -08003#include <unistd.h>
4
Ed Tanousf51d8632024-05-16 09:14:01 -07005#include <boost/beast/core/file_posix.hpp>
6
7struct DuplicatableFileHandle
8{
9 boost::beast::file_posix fileHandle;
10
11 DuplicatableFileHandle() = default;
12 DuplicatableFileHandle(DuplicatableFileHandle&&) noexcept = default;
13 // Overload copy constructor, because posix doesn't have dup(), but linux
14 // does
15 DuplicatableFileHandle(const DuplicatableFileHandle& other)
16 {
17 fileHandle.native_handle(dup(other.fileHandle.native_handle()));
18 }
19 DuplicatableFileHandle& operator=(const DuplicatableFileHandle& other)
20 {
21 if (this == &other)
22 {
23 return *this;
24 }
25 fileHandle.native_handle(dup(other.fileHandle.native_handle()));
26 return *this;
27 }
28 DuplicatableFileHandle&
29 operator=(DuplicatableFileHandle&& other) noexcept = default;
30 ~DuplicatableFileHandle() = default;
31};