blob: 5401e7600b814ab773a90b043a476ff34df67705 [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 }
Patrick Williams504af5a2025-02-03 14:29:03 -050028 DuplicatableFileHandle& operator=(DuplicatableFileHandle&& other) noexcept =
29 default;
Ed Tanousf51d8632024-05-16 09:14:01 -070030 ~DuplicatableFileHandle() = default;
31};