6 void Server_File::write_to_body_error()
9 throw Exception(
"Cannot write to Server_File body");
13 void Server_File::write_checkpoint()
25 tail_offset(connection->server_checkpoint)
40 std::chrono::milliseconds wait
43 if (tail.get_size() > 0)
44 throw Exception(
"Server_File: pulling with non-empty tail");
55 client_journal.pull();
56 tail_offset = connection->server_checkpoint;
58 return connection->server_checkpoint;
69 if (&client_journal.get_file() !=
this)
70 throw Exception(
"Server_File: wrong file");
71 return connection->server_checkpoint;
79 const int64_t server_position,
80 const int64_t until_position,
92 if (connection->server_checkpoint == get_size())
94 tail_offset = connection->server_checkpoint;
98 throw Exception(
"Server_File could not truncate tail after push");
100 return connection->server_checkpoint;
108 return head.pread(data, size, offset);
110 if (offset < tail_offset)
113 return tail.pread(data, size, offset - tail_offset);
123 write_to_body_error();
125 head.
pwrite(data, size, offset);
127 else if (offset >= tail_offset)
128 tail.
pwrite(data, size, offset - tail_offset);
130 write_to_body_error();
Used by Robust_Connection to reconnect after an error.
void pwrite(const char *buffer, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
Server_Connection that automatically reconnects on error
int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait) override
Pull from the connection.
std::unique_ptr< Server_Connection > connection
size_t pread(char *data, size_t size, int64_t offset) const
int64_t push(const Readonly_Journal &client_journal, int64_t from_checkpoint, int64_t until_checkpoint, Unlock_Action unlock_action) override
Push new data to the connection.
size_t pread(char *data, size_t size, int64_t offset) const override
Read a range of bytes.
int64_t push(const Readonly_Journal &client_journal, int64_t server_position, int64_t until_position, Unlock_Action unlock_action) override
Push new data to the connection.
int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait) override
Pull from the connection.
void pwrite(const char *data, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
Server_File(const Connector &connector, std::ostream *log=nullptr)
int64_t handshake(const Readonly_Journal &client_journal, Content_Check content_check) override
Called during Client construction.
@ write_existing
fails if does not exist or locked, locks the file for writing