Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
pipe.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7#include <string>
8
10
11namespace contur {
12
16 class Pipe final : public IIpcChannel
17 {
18 public:
22 explicit Pipe(std::string name, std::size_t capacity = 1024);
23
25 ~Pipe() override;
26
28 Pipe(const Pipe &) = delete;
29
31 Pipe &operator=(const Pipe &) = delete;
33 Pipe(Pipe &&) noexcept;
34
36 Pipe &operator=(Pipe &&) noexcept;
37
41 [[nodiscard]] Result<std::size_t> write(std::span<const std::byte> data) override;
42
46 [[nodiscard]] Result<std::size_t> read(std::span<std::byte> buffer) override;
47
49 void close() override;
50
52 [[nodiscard]] bool isOpen() const noexcept override;
53
55 [[nodiscard]] std::string_view name() const noexcept override;
56
58 [[nodiscard]] std::size_t capacity() const noexcept;
59
61 [[nodiscard]] std::size_t size() const noexcept;
62
63 private:
64 struct Impl;
65 std::unique_ptr<Impl> impl_;
66 };
67
68} // namespace contur
Common interface for IPC channels.
Pipe & operator=(const Pipe &)=delete
Copy assignment is disabled.
std::string_view name() const noexcept override
Pipe name.
bool isOpen() const noexcept override
Returns whether the pipe is open.
Pipe(std::string name, std::size_t capacity=1024)
Creates a pipe with a logical name and capacity.
Result< std::size_t > write(std::span< const std::byte > data) override
Writes bytes into the pipe buffer.
void close() override
Closes the pipe and clears buffered data.
Result< std::size_t > read(std::span< std::byte > buffer) override
Reads bytes from the pipe buffer in FIFO order.
~Pipe() override
Destroys pipe channel.
std::unique_ptr< Impl > impl_
Definition pipe.h:65
std::size_t size() const noexcept
Current number of buffered bytes.
Pipe(const Pipe &)=delete
Copy construction is disabled.
Pipe(Pipe &&) noexcept
Move-constructs pipe state.
std::size_t capacity() const noexcept
Maximum number of bytes that can be buffered.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
IIpcChannel interface for inter-process communication channels.
Definition block.h:15