libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
file.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2#pragma once
3
4#include <sshpp/config.hpp>
7#include <sshpp/export.hpp>
8#include <sshpp/result.hpp>
10#include <sshpp/types.hpp>
11
12#include <cstdint>
13#include <deque>
14#include <vector>
15
16namespace sshpp::sftp {
17
18class Sftp;
19
21class SSHPP_API File {
22public:
23 File() = default;
24 ~File();
25 File(File&&) noexcept;
26 File& operator=(File&&) noexcept;
27 File(const File&) = delete;
28
29 explicit operator bool() const noexcept { return native_ != nullptr; }
30 native_sftp_file native_handle() const noexcept { return native_; }
31 const RemotePath& path() const noexcept { return path_; }
32
34 Result<void> try_read_exact(MutableByteView);
36 Result<void> try_write_all(ByteView);
37
38 Result<std::uint64_t> try_tell() const;
39 Result<void> try_seek(std::uint64_t offset);
40 Result<void> try_rewind();
41 Result<Attributes> try_stat() const;
42 Result<void> try_truncate(std::uint64_t size);
43 Result<void> try_close();
44
45 class ReadAhead;
46 class WriteBehind;
47
48private:
49 friend class Sftp;
51 : native_(n), sftp_(sftp), core_(std::move(core)), path_(std::move(path)) {}
52
53 native_sftp_file native_ = nullptr;
54 native_sftp sftp_ = nullptr;
56 RemotePath path_;
57};
58
62class SSHPP_API File::ReadAhead {
63public:
64 explicit ReadAhead(File& file, std::size_t chunk = 0, std::size_t depth = 0);
66 ReadAhead(const ReadAhead&) = delete;
67 ReadAhead(ReadAhead&&) = delete;
68
72
73private:
74#if SSHPP_HAS_SFTP_AIO
75 Result<void> submit_one();
76 std::deque<native_sftp_aio> inflight_;
77#endif
78 File* file_;
79 std::size_t chunk_;
80 std::size_t depth_;
81 std::vector<std::byte> buffer_;
82 bool reached_eof_ = false;
83};
84
86class SSHPP_API File::WriteBehind {
87public:
88 explicit WriteBehind(File& file, std::size_t chunk = 0, std::size_t depth = 0);
90 WriteBehind(const WriteBehind&) = delete;
91 WriteBehind(WriteBehind&&) = delete;
92
97
98private:
99#if SSHPP_HAS_SFTP_AIO
100 Result<void> drain_one();
101 std::deque<native_sftp_aio> inflight_;
102#endif
103 File* file_;
104 std::size_t chunk_;
105 std::size_t depth_;
106};
107
108} // namespace sshpp::sftp
109
110#if SSHPP_HEADER_ONLY
111#include <sshpp/detail/file.ipp>
112#endif
Input byte range. Implicitly constructible from std::string_view / std::vector<std::byte>.
Definition types.hpp:54
Output byte range (caller-owned, mutable buffer to write into).
Definition types.hpp:67
Definition types.hpp:76
Definition result.hpp:16
A single open SFTP file handle. See docs/design/06 §6.3.
Definition file.hpp:21
ReadAhead(File &file, std::size_t chunk=0, std::size_t depth=0)
WriteBehind(File &file, std::size_t chunk=0, std::size_t depth=0)
Result< void > try_write(ByteView data)
Result< ByteView > try_next()
ReadAhead(ReadAhead &&)=delete
const RemotePath & path() const noexcept
Definition file.hpp:31
ReadAhead(const ReadAhead &)=delete
Result< void > try_flush()
WriteBehind(const WriteBehind &)=delete
native_sftp_file native_handle() const noexcept
Definition file.hpp:30
WriteBehind(WriteBehind &&)=delete
The SFTP subsystem session. See docs/design/06 §6.2.
Definition sftp.hpp:45
std::shared_ptr< SessionCore > SessionCorePtr
Definition session_core.hpp:43
Definition algorithms.ipp:10
::sftp_session_struct * native_sftp
Definition native_fwd.hpp:31
::sftp_file_struct * native_sftp_file
Definition native_fwd.hpp:32
Definition error.hpp:110
std::filesystem::path path
Definition server_sftp_subsystem.ipp:38