New --store-and-forward option (#100), including refactoring several areas to allow PV to run in two passes, and the ability to look at the output pipe buffer utilisation to more accurately reflect the total data transferred to the receiving end, rather than just the total amount written to the output buffer.

This commit is contained in:
Andrew Wood
2024-10-05 16:21:59 +01:00
parent ea3787e393
commit d9a0041870
17 changed files with 700 additions and 331 deletions
+1
View File
@@ -36,6 +36,7 @@ struct opts_s {
/*@keep@*/ /*@null@*/ char *name; /* display name, if any */
/*@keep@*/ /*@null@*/ char *format; /* output format, if any */
/*@keep@*/ /*@null@*/ char *pidfile; /* PID file, if any */
/*@keep@*/ /*@null@*/ char *store_and_forward_file; /* store and forward file, if any */
/*@keep@*/ /*@null@*/ const char **argv; /* array of non-option arguments */
size_t lastwritten; /* show N bytes last written */
off_t rate_limit; /* rate limit, in bytes per second */
+6 -3
View File
@@ -230,13 +230,13 @@ struct pvstate_s {
/* Keep track of progress over last intervals to compute current average rate. */
/*@null@*/ struct { /* state at previous intervals (circular buffer) */
long double elapsed_sec; /* time since start of transfer */
off_t total_written; /* amount transferred by that time */
off_t transferred; /* amount transferred by that time */
} *history;
size_t history_len; /* total size of history array */
size_t history_first; /* index of oldest entry */
size_t history_last; /* index of newest entry */
off_t prev_total_written; /* total amount transferred when called last time */
off_t prev_transferred; /* total amount transferred when called last time */
int percentage; /* transfer percentage completion */
} calc;
@@ -290,7 +290,10 @@ struct pvstate_s {
ssize_t to_write; /* max to write this time around */
ssize_t written; /* bytes sent to stdout this time */
off_t total_written; /* total bytes or lines transferred */
size_t written_but_not_consumed; /* bytes in the output pipe, unread */
off_t total_written; /* total bytes or lines written */
off_t transferred; /* amount transferred (written - unconsumed) */
/*
* While reading from a file descriptor we keep track of how
+6
View File
@@ -27,6 +27,7 @@ extern "C" {
* Exit status bitmask values.
*/
#define PV_ERROREXIT_REMOTE_OR_PID 1
#define PV_ERROREXIT_SAF 1 /* store and forward error */
#define PV_ERROREXIT_ACCESS 2
#define PV_ERROREXIT_OUROBOROS 4
#define PV_ERROREXIT_TRANSITION 8
@@ -163,6 +164,11 @@ void pv_nanosleep(long long);
*/
extern /*@null@*/ /*@only@*/ pvstate_t pv_state_alloc(const char *);
/*
* Clear the calculated parts of a state structure.
*/
extern void pv_state_reset(pvstate_t state);
/*
* Set the formatting string, given a set of old-style formatting options.
*/