blob: f1994857d0d0378d84daeff3aff7b58f0584220f [file] [log] [blame]
Ed Tanousf2cd7662025-02-08 15:10:24 -08001#pragma once
2
Ed Tanous40e9b922024-09-10 13:50:16 -07003// SPDX-License-Identifier: Apache-2.0
4// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanousd7857202025-01-28 15:32:26 -08005#include <unistd.h>
6
Ed Tanousf51d8632024-05-16 09:14:01 -07007#include <boost/beast/core/file_posix.hpp>
8
9struct 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
17 DuplicatableFileHandle(const DuplicatableFileHandle& other)
18 {
19 fileHandle.native_handle(dup(other.fileHandle.native_handle()));
20 }
21 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 }
Patrick Williams504af5a2025-02-03 14:29:03 -050030 DuplicatableFileHandle& operator=(DuplicatableFileHandle&& other) noexcept =
31 default;
Ed Tanousf51d8632024-05-16 09:14:01 -070032 ~DuplicatableFileHandle() = default;
33};