2 * Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_FILE_DESCRIPTOR_HPP
9 #define LTTNG_FILE_DESCRIPTOR_HPP
15 /* RAII wrapper around a UNIX file descriptor. */
16 class file_descriptor {
18 file_descriptor() noexcept;
20 explicit file_descriptor(int raw_fd) noexcept;
21 file_descriptor(const file_descriptor&) = delete;
22 file_descriptor& operator=(const file_descriptor&) = delete;
24 file_descriptor(file_descriptor&& other) noexcept;
26 file_descriptor& operator=(file_descriptor&& other) noexcept;
28 ~file_descriptor() noexcept;
31 * Read `size` bytes from the underlying file descriptor, assuming
32 * raw_fd behaves as a blocking device.
34 * Throws an exception if the requested amount of bytes couldn't be read.
36 void read(void *buffer, std::size_t size);
38 * Write `size` bytes to the underlying file descriptor, assuming
39 * raw_fd behaves as a blocking device.
41 * Throws an exception if the requested amount of bytes couldn't be written.
43 void write(const void *buffer, std::size_t size);
45 int fd() const noexcept;
47 void _cleanup() noexcept;
53 } /* namespace lttng */
55 #endif /* LTTNG_FILE_DESCRIPTOR_HPP */