librsync  2.3.4
Functions
tube.c File Reference

A somewhat elastic but fairly small buffer for data passing through a stream. More...

Include dependency graph for tube.c:

Go to the source code of this file.

Functions

static void rs_tube_catchup_write (rs_job_t *job)
 
static void rs_tube_catchup_copy (rs_job_t *job)
 Catch up on an outstanding copy command. More...
 
rs_result rs_tube_catchup (rs_job_t *job)
 Put whatever will fit from the tube into the output of the stream. More...
 
int rs_tube_is_idle (rs_job_t const *job)
 
void rs_tube_copy (rs_job_t *job, size_t len)
 Queue up a request to copy through len bytes from the input to the output of the stream. More...
 
void rs_tube_write (rs_job_t *job, const void *buf, size_t len)
 Push some data into the tube for storage. More...
 

Detailed Description

A somewhat elastic but fairly small buffer for data passing through a stream.

In most cases the iter can adjust to send just as much data will fit. In some cases that would be too complicated, because it has to transmit an integer or something similar. So in that case we stick whatever won't fit into a small buffer.

A tube can contain some literal data to go out (typically command bytes), and also an instruction to copy data from the stream's input or from some other location. Both literal data and a copy command can be queued at the same time, but only in that order and at most one of each.

Todo:
As an optimization, write it directly to the stream if possible. But for simplicity don't do that yet.
Todo:
I think our current copy code will lock up if the application only ever calls us with either input or output buffers, and not both. So I guess in that case we might need to copy into some temporary buffer space, and then back out again later.

Definition in file tube.c.

Function Documentation

◆ rs_tube_catchup_write()

static void rs_tube_catchup_write ( rs_job_t job)
static

Definition at line 63 of file tube.c.

◆ rs_tube_catchup_copy()

static void rs_tube_catchup_copy ( rs_job_t job)
static

Catch up on an outstanding copy command.

Takes data from the scoop and writes as much as will fit to the output, up to the limit of the outstanding copy.

Definition at line 88 of file tube.c.

◆ rs_tube_catchup()

rs_result rs_tube_catchup ( rs_job_t job)

Put whatever will fit from the tube into the output of the stream.

Returns
RS_DONE if the tube is now empty and ready to accept another command, RS_BLOCKED if there is still stuff waiting to go out.

Definition at line 120 of file tube.c.

◆ rs_tube_is_idle()

int rs_tube_is_idle ( rs_job_t const *  job)

Definition at line 144 of file tube.c.

◆ rs_tube_copy()

void rs_tube_copy ( rs_job_t job,
size_t  len 
)

Queue up a request to copy through len bytes from the input to the output of the stream.

The data is copied from the scoop (if there is anything there) or from the input, on the next call to rs_tube_write().

We can only accept this request if there is no copy command already pending.

Todo:
Try to do the copy immediately, and return a result. Then, people can try to continue if possible. Is this really required? Callers can just go out and back in again after flushing the tube.

Definition at line 160 of file tube.c.

◆ rs_tube_write()

void rs_tube_write ( rs_job_t job,
const void *  buf,
size_t  len 
)

Push some data into the tube for storage.

The tube's never supposed to get very big, so this will just pop loudly if you do that.

We can't accept write data if there's already a copy command in the tube, because the write data comes out first.

Definition at line 174 of file tube.c.