summaryrefslogtreecommitdiff
path: root/include/duplicatable_file_handle.hpp
blob: f1994857d0d0378d84daeff3aff7b58f0584220f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include <unistd.h>

#include <boost/beast/core/file_posix.hpp>

struct DuplicatableFileHandle
{
    boost::beast::file_posix fileHandle;

    DuplicatableFileHandle() = default;
    DuplicatableFileHandle(DuplicatableFileHandle&&) noexcept = default;
    // Overload copy constructor, because posix doesn't have dup(), but linux
    // does
    DuplicatableFileHandle(const DuplicatableFileHandle& other)
    {
        fileHandle.native_handle(dup(other.fileHandle.native_handle()));
    }
    DuplicatableFileHandle& operator=(const DuplicatableFileHandle& other)
    {
        if (this == &other)
        {
            return *this;
        }
        fileHandle.native_handle(dup(other.fileHandle.native_handle()));
        return *this;
    }
    DuplicatableFileHandle& operator=(DuplicatableFileHandle&& other) noexcept =
        default;
    ~DuplicatableFileHandle() = default;
};