StormByte-Network 4.0.0
C++26 networking module of the StormByte suite
Loading...
Searching...
No Matches
remote_file.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Network.
5 *
6 * StormByte-Network original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Network source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte Buffer tree), which
23 * remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Network is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Network. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
43#include <StormByte/buffer/io/buffered_location_reader.hxx>
44#include <StormByte/buffer/io/buffered_location_writer.hxx>
46#include <StormByte/safe/optional.hxx>
47#include <StormByte/safe/pointers.hxx>
48#include <StormByte/safe/string.hxx>
49
54namespace StormByte {
59 namespace Network {
64 namespace Detail::RemoteFile {
69 class DataPlane;
70 }
71
81 public:
88
95
103
111
116 ~BufferedRemoteFileReader() noexcept override;
117
118 protected:
123 StormByte::Safe::Shared<StormByte::System::Device> OriginDevice() const override;
124
130 bool OriginDeviceUsable(const StormByte::Safe::Shared<StormByte::System::Device>& device) const noexcept override;
131
136 Buffer::IO::Result OriginOpen() override;
137
142 Buffer::IO::Result OriginClose() override;
143
150 Buffer::IO::Result OriginPull(StormByte::ByteSize count, Buffer::FIFO& destination) override;
151
158 Buffer::IO::Result OriginSeek(std::ptrdiff_t offset, Buffer::Position mode) override;
159
164 StormByte::Safe::Optional<StormByte::ByteSize> OriginSize() const noexcept override;
165
166 private:
173 BufferedRemoteFileReader(StormByte::Safe::String locator,
174 StormByte::Safe::Weak<Detail::RemoteFile::DataPlane> plane, RemoteFileMount::ChannelToken token);
175
179 void MarkFailed() noexcept;
180
185 bool ReleaseToken() noexcept;
186
190 StormByte::Safe::Weak<Detail::RemoteFile::DataPlane> m_plane;
191
195 RemoteFileMount::ChannelToken m_token{};
196
200 StormByte::ByteSize m_offset{0};
201
205 bool m_token_released{false};
206
210 friend class Client;
211
220 template<class T, class... Args>
222 };
223
230 public:
237
244
252
260
265 ~BufferedRemoteFileWriter() noexcept override;
266
267 protected:
272 StormByte::Safe::Shared<StormByte::System::Device> OriginDevice() const override;
273
279 bool OriginDeviceUsable(const StormByte::Safe::Shared<StormByte::System::Device>& device) const noexcept override;
280
285 Buffer::IO::Result OriginOpen() override;
286
291 Buffer::IO::Result OriginClose() override;
292
298 Buffer::IO::Result OriginPush(std::span<const std::byte> data) override;
299
304 Buffer::IO::Result OriginFlush() override;
305
311 Buffer::IO::Result OriginTruncate() override;
312
318 Buffer::IO::Result OriginSeek(StormByte::ByteSize absolute) override;
319
324 StormByte::ByteSize OriginSize() const noexcept override;
325
326 private:
333 BufferedRemoteFileWriter(StormByte::Safe::String locator,
334 StormByte::Safe::Weak<Detail::RemoteFile::DataPlane> plane, RemoteFileMount::ChannelToken token);
335
339 void MarkFailed() noexcept;
340
345 bool ReleaseToken() noexcept;
346
350 StormByte::Safe::Weak<Detail::RemoteFile::DataPlane> m_plane;
351
355 RemoteFileMount::ChannelToken m_token{};
356
360 StormByte::ByteSize m_offset{0};
361
365 bool m_token_released{false};
366
370 friend class Client;
371
380 template<class T, class... Args>
382 };
383
388
393 }
394}
395
397
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Peer-scoped multiplexed request transport.
StormByte::Safe::Shared< StormByte::System::Device > Device() const
StormByte::Safe::Shared< StormByte::System::Device > Device() const
File-like buffered reader backed by a peer DataPlane and mount token.
Definition remote_file.hxx:80
StormByte::Safe::Shared< StormByte::System::Device > OriginDevice() const override
Network-interface snapshot for this connected origin.
Buffer::IO::Result OriginSeek(std::ptrdiff_t offset, Buffer::Position mode) override
Move only this Buffer leaf's logical cursor.
~BufferedRemoteFileReader() noexcept override
Release this leaf's token before base destruction.
Buffer::IO::Result OriginOpen() override
Open the token's server-side reader handle.
friend class Client
Client may construct mounted reader leaves.
Definition remote_file.hxx:210
StormByte::Safe::Optional< StormByte::ByteSize > OriginSize() const noexcept override
Query the server-side file length.
BufferedRemoteFileReader & operator=(BufferedRemoteFileReader &&)=delete
Move assignment is disabled while a mount token is registered.
BufferedRemoteFileReader & operator=(const BufferedRemoteFileReader &)=delete
Copy assignment is disabled.
BufferedRemoteFileReader(BufferedRemoteFileReader &&)=delete
Move construction is disabled while a mount token is registered.
Buffer::IO::Result OriginPull(StormByte::ByteSize count, Buffer::FIFO &destination) override
Pull one protocol-bounded segment at this leaf's absolute logical offset.
bool OriginDeviceUsable(const StormByte::Safe::Shared< StormByte::System::Device > &device) const noexcept override
Accept the network device without probing its accessor as a filesystem path.
Buffer::IO::Result OriginClose() override
Release this reader token without closing the peer plane.
BufferedRemoteFileReader(const BufferedRemoteFileReader &)=delete
Copy construction is disabled.
File-like buffered writer with an exclusive server-side mount.
Definition remote_file.hxx:229
Buffer::IO::Result OriginFlush() override
Flush the server-side writer handle.
~BufferedRemoteFileWriter() noexcept override
Release this leaf's token before base destruction.
BufferedRemoteFileWriter(BufferedRemoteFileWriter &&)=delete
Move construction is disabled while a mount token is registered.
Buffer::IO::Result OriginClose() override
Release this writer token without closing the peer plane.
Buffer::IO::Result OriginOpen() override
Open this writer token on the peer plane.
Buffer::IO::Result OriginPush(std::span< const std::byte > data) override
Write one protocol-bounded segment at this leaf's absolute logical offset.
BufferedRemoteFileWriter & operator=(const BufferedRemoteFileWriter &)=delete
Copy assignment is disabled.
friend class Client
Client may construct mounted writer leaves.
Definition remote_file.hxx:370
bool OriginDeviceUsable(const StormByte::Safe::Shared< StormByte::System::Device > &device) const noexcept override
Accept the network device without probing its accessor as a filesystem path.
Buffer::IO::Result OriginTruncate() override
Truncate the server-side file to zero bytes.
BufferedRemoteFileWriter(const BufferedRemoteFileWriter &)=delete
Copy construction is disabled.
StormByte::ByteSize OriginSize() const noexcept override
Query the greater of the server file length and accepted logical write position.
StormByte::Safe::Shared< StormByte::System::Device > OriginDevice() const override
Network-interface snapshot for this connected origin.
BufferedRemoteFileWriter & operator=(BufferedRemoteFileWriter &&)=delete
Move assignment is disabled while a mount token is registered.
Buffer::IO::Result OriginSeek(StormByte::ByteSize absolute) override
Set this Buffer leaf's local writer offset.
Public, validated descriptor for attaching to one remote file channel.
Definition remote_file_mount.hxx:69
Private remote-file implementation namespace.
Network module of the StormByte suite.
StormByte::Safe::Unique< BufferedRemoteFileReader > RemoteFileReaderHandle
Base-heap owner movable to Unique<Buffer::IO::BufferedLocationReader> without slicing.
Definition remote_file.hxx:387
StormByte::Safe::Unique< BufferedRemoteFileWriter > RemoteFileWriterHandle
Base-heap owner movable to Unique<Buffer::IO::BufferedLocationWriter> without slicing.
Definition remote_file.hxx:392
Unique< T > MakeUnique(Args &&... args)
Root namespace of the StormByte suite.
STL namespace.
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:51