1#ifndef LIBFILEZILLA_AIO_WRITER_HEADER
2#define LIBFILEZILLA_AIO_WRITER_HEADER
95 virtual void do_close(scoped_lock &) {}
98 aio_buffer_pool & buffer_pool_;
100 std::wstring
const name_;
102 progress_cb_t progress_cb_;
104 size_t const max_buffers_{};
105 std::list<buffer_lease> buffers_;
119 : name_(std::move(name))
125 virtual std::unique_ptr<writer_factory>
clone()
const = 0;
136 std::wstring
const& name()
const {
return name_; }
151 virtual size_t preferred_buffer_count()
const {
return 1; }
164 std::wstring
const name_;
187 explicit operator bool()
const {
return impl_.operator
bool(); }
189 std::wstring name()
const {
return impl_ ? impl_->name() : std::wstring(); }
191 uint64_t size()
const {
return impl_ ? impl_->size() : aio_base::nosize; }
194 std::unique_ptr<writer_factory> impl_;
205 using writer_base::writer_base;
248 bool preallocated_{};
251enum class file_writer_flags :
unsigned {
253 permissions_current_user_only = 0x02,
254 permissions_current_user_and_admins_only = 0x04
256inline bool operator&(file_writer_flags
lhs, file_writer_flags
rhs) {
257 return (
static_cast<std::underlying_type_t<file_writer_flags>
>(
lhs) &
static_cast<std::underlying_type_t<file_writer_flags>
>(
rhs)) != 0;
259inline file_writer_flags operator|(file_writer_flags
lhs, file_writer_flags
rhs) {
260 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));
270 virtual std::unique_ptr<writer_factory>
clone()
const override;
275 virtual datetime mtime()
const override;
281 virtual size_t preferred_buffer_count()
const override {
return 4; }
284 thread_pool & thread_pool_;
285 file_writer_flags flags_{};
306 size_t size_limit_{};
321 virtual std::unique_ptr<writer_factory>
clone()
const override;
325 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:107
Handle for asynchronous tasks.
Definition thread_pool.hpp:24
Definition writer.hpp:316
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:295
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:265
virtual bool multiple_buffer_usage() const override
Whether the writer can benefit from multiple buffers.
Definition writer.hpp:279
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 set_mtime(datetime const &t) override
Sets the mtime of the target.
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:272
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:228
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:203
Base class for all writers.
Definition writer.hpp:28
aio_result finalize(event_handler &h)
Finalizes the writer.
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, event_handler &h)
Pass a buffer to be written out.
std::function< void(writer_base const *, uint64_t written)> progress_cb_t
Definition writer.hpp:75
virtual bool set_mtime(datetime const &)
Must be finalized already.
Definition writer.hpp:61
Definition writer.hpp:168
A writer factory.
Definition writer.hpp:113
virtual std::unique_ptr< writer_factory > clone() const =0
Clones the factory.
virtual size_t min_buffer_usage() const
The writer requires at least this many buffers.
Definition writer.hpp:146
virtual uint64_t size() const
Some writers, e.g. for files, may have a pre-existing size.
Definition writer.hpp:142
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:149
virtual bool offsetable() const
If true, writer can be opened from any position, not just the beginning, such as file_writer.
Definition writer.hpp:139
virtual bool set_mtime(datetime const &)
Sets the mtime of the target.
Definition writer.hpp:158
The namespace used by libfilezilla.
Definition apply.hpp:17
aio_result
Result of aio operations.
Definition aio.hpp:190
@ error
Operationf failed.
bool dispatch(event_base const &ev, F &&f)
Dispatch for simple_event<> based events to simple functors.
Definition event_handler.hpp:199
Declares thread_pool and async_task.