Ed Tanous | f2cd766 | 2025-02-08 15:10:24 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 5 | #include <unistd.h> |
| 6 | |
Ed Tanous | f51d863 | 2024-05-16 09:14:01 -0700 | [diff] [blame] | 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 |
| 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 Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 30 | DuplicatableFileHandle& operator=(DuplicatableFileHandle&& other) noexcept = |
| 31 | default; |
Ed Tanous | f51d863 | 2024-05-16 09:14:01 -0700 | [diff] [blame] | 32 | ~DuplicatableFileHandle() = default; |
| 33 | }; |