1 #ifndef LIBFILEZILLA_AIO_WRITER_HEADER
2 #define LIBFILEZILLA_AIO_WRITER_HEADER
11 #include "../buffer.hpp"
12 #include "../file.hpp"
13 #include "../thread_pool.hpp"
86 , progress_cb_(std::move(progress_cb))
87 , max_buffers_(max_buffers ? max_buffers : 1)
93 , progress_cb_(std::move(progress_cb))
94 , max_buffers_(max_buffers ? max_buffers : 1)
97 virtual void do_close(scoped_lock &) {}
100 aio_buffer_pool & buffer_pool_;
102 std::wstring
const name_;
104 progress_cb_t progress_cb_;
106 size_t const max_buffers_{};
107 std::list<buffer_lease> buffers_;
110 uint8_t finalizing_{};
121 : name_(std::move(name))
127 virtual std::unique_ptr<writer_factory>
clone()
const = 0;
138 std::wstring
const& name()
const {
return name_; }
144 virtual uint64_t
size()
const {
return writer_base::nosize; }
153 virtual size_t preferred_buffer_count()
const {
return 1; }
166 std::wstring
const name_;
189 explicit operator bool()
const {
return impl_.operator bool(); }
191 std::wstring name()
const {
return impl_ ? impl_->name() : std::wstring(); }
193 uint64_t size()
const {
return impl_ ? impl_->size() : aio_base::nosize; }
196 std::unique_ptr<writer_factory> impl_;
207 using writer_base::writer_base;
242 virtual void FZ_PRIVATE_SYMBOL do_close(
scoped_lock & l)
override;
245 void FZ_PRIVATE_SYMBOL entry();
250 bool preallocated_{};
253 enum class file_writer_flags : unsigned {
255 permissions_current_user_only = 0x02,
256 permissions_current_user_and_admins_only = 0x04
258 inline bool operator&(file_writer_flags lhs, file_writer_flags rhs) {
259 return (
static_cast<std::underlying_type_t<file_writer_flags>
>(lhs) &
static_cast<std::underlying_type_t<file_writer_flags>
>(rhs)) != 0;
261 inline file_writer_flags operator|(file_writer_flags lhs, file_writer_flags rhs) {
262 return static_cast<file_writer_flags
>(
static_cast<std::underlying_type_t<file_writer_flags>
>(lhs) |
static_cast<std::underlying_type_t<file_writer_flags>
>(rhs));
272 virtual std::unique_ptr<writer_factory>
clone()
const override;
276 virtual uint64_t
size()
const override;
277 virtual datetime mtime()
const override;
283 virtual size_t preferred_buffer_count()
const override {
return 4; }
286 thread_pool & thread_pool_;
287 file_writer_flags flags_{};
308 size_t size_limit_{};
323 virtual std::unique_ptr<writer_factory>
clone()
const override;
327 size_t size_limit_{};
Buffer management and wait machinery for asynchronous I/O.
A buffer pool for use with async readers/writers.
Definition: aio.hpp:132
Handle for asynchronous tasks.
Definition: thread_pool.hpp:24
Definition: writer.hpp:318
virtual std::unique_ptr< writer_base > open(aio_buffer_pool &pool, uint64_t offset, writer_base::progress_cb_t progress_cb=nullptr, size_t max_buffers=0) override
Creates a writer.
virtual std::unique_ptr< writer_factory > clone() const override
Clones the factory.
Definition: writer.hpp:297
virtual aio_result preallocate(uint64_t size) override
Instructs writer to preallocate storage. May be a noop.
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition: buffer.hpp:27
Waitable condition variable.
Definition: mutex.hpp:196
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:41
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:55
Factory for.
Definition: writer.hpp:267
virtual bool multiple_buffer_usage() const override
Whether the writer can benefit from multiple buffers.
Definition: writer.hpp:281
virtual bool set_mtime(datetime const &t) override
Sets the mtime of the target.
virtual std::unique_ptr< writer_base > open(aio_buffer_pool &pool, uint64_t offset, writer_base::progress_cb_t progress_cb=nullptr, size_t max_buffers=0) override
Creates a writer.
virtual bool offsetable() const override
If true, writer can be opened from any position, not just the beginning, such as file_writer.
Definition: writer.hpp:274
virtual std::unique_ptr< writer_factory > clone() const override
Clones the factory.
virtual uint64_t size() const override
Some writers, e.g. for files, may have a pre-existing size.
File writer.
Definition: writer.hpp:230
virtual aio_result preallocate(uint64_t size) override
Instructs writer to preallocate storage. May be a noop.
virtual bool set_mtime(datetime const &) override
Must be finalized already.
Lean class for file access.
Definition: file.hpp:29
A simple scoped lock.
Definition: mutex.hpp:93
A dumb thread-pool for asynchronous tasks.
Definition: thread_pool.hpp:64
Base class for threaded writer.
Definition: writer.hpp:205
Base class for all writers.
Definition: writer.hpp:28
virtual aio_result preallocate(uint64_t)
Instructs writer to preallocate storage. May be a noop.
Definition: writer.hpp:34
aio_result add_buffer(buffer_lease &&b, aio_waiter &h)
Pass a buffer to be written out.
std::function< void(writer_base const *, uint64_t written)> progress_cb_t
Definition: writer.hpp:77
virtual bool set_mtime(datetime const &)
Must be finalized already.
Definition: writer.hpp:63
aio_result finalize(aio_waiter &h)
Finalizes the writer.
Definition: writer.hpp:170
A writer factory.
Definition: writer.hpp:115
virtual size_t min_buffer_usage() const
The writer requires at least this many buffers.
Definition: writer.hpp:148
virtual uint64_t size() const
Some writers, e.g. for files, may have a pre-existing size.
Definition: writer.hpp:144
virtual std::unique_ptr< writer_factory > clone() const =0
Clones the factory.
virtual std::unique_ptr< writer_base > open(aio_buffer_pool &pool, uint64_t offset=0, writer_base::progress_cb_t progress_cb=nullptr, size_t max_buffers=0)=0
Creates a writer.
virtual bool multiple_buffer_usage() const
Whether the writer can benefit from multiple buffers.
Definition: writer.hpp:151
virtual bool offsetable() const
If true, writer can be opened from any position, not just the beginning, such as file_writer.
Definition: writer.hpp:141
virtual bool set_mtime(datetime const &)
Sets the mtime of the target.
Definition: writer.hpp:160
The namespace used by libfilezilla.
Definition: apply.hpp:17
aio_result
Result of aio operations.
Definition: aio.hpp:213
@ error
Operationf failed.