6 size_t Server_File::remote_pread(
char *data,
size_t size, int64_t offset)
const
14 Channel_Lock lock(channel);
21 for (
size_t read = 0; read < returned_size;)
22 read += lock.read_some(data + read, returned_size - read);
28 void Server_File::write_to_body_error()
31 throw Exception(
"Cannot write to Server_File body");
35 void Server_File::write_checkpoint()
49 tail_offset(server_checkpoint)
58 int64_t Server_File::pull
61 std::chrono::milliseconds wait,
65 if (tail.get_size() > 0)
66 throw Exception(
"Server_File: pulling with non-empty tail");
70 tail_offset = server_checkpoint;
72 return server_checkpoint;
83 if (&client_journal.get_file() !=
this)
84 throw Exception(
"Server_File: wrong file");
85 return server_checkpoint;
89 int64_t Server_File::pull
93 std::chrono::milliseconds wait
96 return pull(wait,
'i');
104 std::chrono::milliseconds wait
107 return pull(wait,
'l');
115 const int64_t server_position,
116 const int64_t until_position,
117 const bool unlock_after
128 if (server_checkpoint == get_size())
130 tail_offset = server_checkpoint;
134 throw Exception(
"Server_File could not truncate tail after push");
136 return server_checkpoint;
144 return head.pread(data, size, offset);
146 if (offset < tail_offset)
147 return remote_pread(data, size, offset);
149 return tail.pread(data, size, offset - tail_offset);
159 write_to_body_error();
161 head.
pwrite(data, size, offset);
163 else if (offset >= tail_offset)
164 tail.
pwrite(data, size, offset - tail_offset);
166 write_to_body_error();
173 if (blob.get_position() >= tail_offset)
189 file.
resize(
size_t(size));
191 download(writer, lock, size);
193 return file.move_data();
int64_t get_position() const noexcept
void set_position(int64_t position)
void write(const char *data, size_t size)
void read(char *data, size_t size)
void pwrite(const char *buffer, size_t size, int64_t offset) override
static constexpr int64_t checkpoint_offset
static constexpr int64_t header_size
int64_t server_checkpoint
int64_t pull(Writable_Journal *client_journal, std::chrono::milliseconds wait, char pull_type)
int64_t push_until(Readonly_Journal &client_journal, int64_t server_position, int64_t until_position, bool unlock_after) override
Push new data to the connection.
int64_t handshake(Readonly_Journal &client_journal, bool content_check) override
Called during Client construction.
int64_t lock_pull(Writable_Journal &client_journal, std::chrono::milliseconds wait) override
Fused lock_pull, executed at the start of a write transaction.
std::string read_blob_data(Blob blob) const override
size_t pread(char *data, size_t size, int64_t offset) const override
void pwrite(const char *data, size_t size, int64_t offset) override
int64_t push_until(Readonly_Journal &client_journal, int64_t server_position, int64_t until_position, bool unlock_after) override
Push new data to the connection.
@ write_existing
fails if does not exist or locked, locks the file for writing