librsync
2.3.0
|
Go to the source code of this file.
Functions | |
void | rs_scoop_input (rs_job_t *job, size_t len) |
Try to accept a from the input buffer to get LEN bytes in the scoop. More... | |
void | rs_scoop_advance (rs_job_t *job, size_t len) |
Advance the input cursor forward len bytes. More... | |
rs_result | rs_scoop_readahead (rs_job_t *job, size_t len, void **ptr) |
Read from scoop without advancing. More... | |
rs_result | rs_scoop_read (rs_job_t *job, size_t len, void **ptr) |
Read LEN bytes if possible, and remove them from the input scoop. More... | |
rs_result | rs_scoop_read_rest (rs_job_t *job, size_t *len, void **ptr) |
Read whatever data remains in the input stream. More... | |
size_t | rs_scoop_total_avail (rs_job_t *job) |
Return the total number of bytes available including the scoop and input buffer. More... | |
This file deals with readahead from caller-supplied buffers.
Many functions require a certain minimum amount of input to do their processing. For example, to calculate a strong checksum of a block we need at least a block of input.
Since we put the buffers completely under the control of the caller, we can't count on ever getting this much data all in one go. We can't simply wait, because the caller might have a smaller buffer than we require and so we'll never get it. For the same reason we must always accept all the data we're given.
So, stream input data that's required for readahead is put into a special buffer, from which the caller can then read. It's essentially like an internal pipe, which on any given read request may or may not be able to actually supply the data.
As a future optimization, we might try to take data directly from the input buffer if there's already enough there.
Definition in file scoop.c.
void rs_scoop_input | ( | rs_job_t * | job, |
size_t | len | ||
) |
void rs_scoop_advance | ( | rs_job_t * | job, |
size_t | len | ||
) |
Advance the input cursor forward len
bytes.
This is used after doing readahead, when you decide you want to keep it. len
must be no more than the amount of available data, so you can't cheat.
So when creating a delta, we require one block of readahead. But after examining that block, we might decide to advance over all of it (if there is a match), or just one byte (if not).
Read from scoop without advancing.
Ask for LEN bytes of input from the stream. If that much data is available, then return a pointer to it in PTR, advance the stream input pointer over the data, and return RS_DONE. If there's not enough data, then accept whatever is there into a buffer, advance over it, and return RS_BLOCKED.
The data is not actually removed from the input, so this function lets you do readahead. If you want to keep any of the data, you should also call rs_scoop_advance() to skip over it.
Read LEN bytes if possible, and remove them from the input scoop.
*job | An rs_job_t pointer to the job instance. |
len | The length of the data in the ptr buffer. |
**ptr | will be updated to point to a read-only buffer holding the data, if enough is available. |
Read whatever data remains in the input stream.
*job | The rs_job_t instance the job instance. |
*len | will be updated to the length of the available data. |
**ptr | will point at the available data. |