Allow "-L 0" to be propagated with "-R" so that a remote process can have its rate limiting turned off as well as on; and update the manual to note this (#193).

This commit is contained in:
Andrew Wood
2026-05-08 21:07:29 +01:00
parent eae06cf3c0
commit e7087b101d
9 changed files with 30 additions and 9 deletions
+3
View File
@@ -267,6 +267,9 @@ If the file already exists, it will be truncated.
.BI \-L\ RATE \fR,\ \fB\-\-rate-limit\ RATE
Limit the transfer to a maximum of \fIRATE\fR bytes per second.
The same suffixes as \*(lq\fB\-\-size\fR\*(rq can be used.
Decimal values are allowed.
Specifying 0 will turn off rate limiting, which is useful with
\*(lq\fB\-\-remote\fR\*(rq.
.TP
.BI \-B\ BYTES \fR,\ \fB\-\-buffer-size\ BYTES
Use a transfer buffer size of \fIBYTES\fR bytes.
+3 -1
View File
@@ -276,7 +276,9 @@ are explicitly switched on will be shown.
**-L RATE, \--rate-limit RATE**
: Limit the transfer to a maximum of *RATE* bytes per second. The same
suffixes as "**\--size**" can be used.
suffixes as "**\--size**" can be used. Decimal values are allowed.
Specifying 0 will turn off rate limiting, which is useful with
"**\--remote**".
**-B BYTES, \--buffer-size BYTES**
+2 -1
View File
@@ -114,7 +114,8 @@ struct opts_s {
bool show_stats; /* set to write statistics at the end */
bool width_set_manually; /* width was set manually, not detected */
bool height_set_manually; /* height was set manually, not detected */
bool rate_limit_active; /* whether a rate limit was set */
bool rate_limit_specified; /* whether a rate limit value was given */
bool rate_limit_active; /* whether rate limiting is in effect (>0) */
};
/*@-exportlocal@*/
+2 -1
View File
@@ -237,7 +237,8 @@ struct pvstate_s {
bool show_stats; /* show statistics on exit */
bool width_set_manually; /* width was set manually, not detected */
bool height_set_manually; /* height was set manually, not detected */
bool rate_limit_active; /* whether a rate limit is in effect */
bool rate_limit_specified; /* whether a rate limit value was given */
bool rate_limit_active; /* whether a rate limit is in effect (>0) */
} control;
/*******************
+1 -1
View File
@@ -266,7 +266,7 @@ extern void pv_state_stop_at_size_set(pvstate_t, bool);
extern void pv_state_sync_after_write_set(pvstate_t, bool);
extern void pv_state_direct_io_set(pvstate_t, bool);
extern void pv_state_sparse_output_set(pvstate_t, bool);
extern void pv_state_rate_limit_set(pvstate_t, long double, bool);
extern void pv_state_rate_limit_set(pvstate_t, long double, bool, bool);
extern void pv_state_target_buffer_size_set(pvstate_t, size_t);
extern void pv_state_no_splice_set(pvstate_t, bool);
extern void pv_state_pipe_buffer_size_set(pvstate_t, size_t);
+1 -1
View File
@@ -903,7 +903,7 @@ int main(int argc, char **argv)
pv_state_sync_after_write_set(state, opts->sync_after_write);
pv_state_direct_io_set(state, opts->direct_io);
pv_state_discard_input_set(state, opts->discard_input);
pv_state_rate_limit_set(state, opts->rate_limit, opts->rate_limit_active);
pv_state_rate_limit_set(state, opts->rate_limit, opts->rate_limit_specified, opts->rate_limit_active);
pv_state_target_buffer_size_set(state, opts->buffer_size);
pv_state_no_splice_set(state, opts->no_splice);
pv_state_pipe_buffer_size_set(state, opts->pipe_buffer_size);
+2
View File
@@ -801,6 +801,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
opts->width_set_manually = false;
opts->height_set_manually = false;
opts->rate_limit_specified = false;
do {
#ifdef HAVE_GETOPT_LONG
@@ -1058,6 +1059,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
break;
case 'L':
(void) pv_getnum_size(optarg, opts->decimal_units, &(opts->rate_limit));
opts->rate_limit_specified = true;
#if HAVE_MATH_H
/*@-unrecog@ *//* splint doesn't know nextafterl(). */
if (opts->rate_limit < nextafterl(0, INFINITY)) {
+6 -3
View File
@@ -42,7 +42,8 @@ struct remote_msg {
unsigned int height; /* screen height */
bool width_set_manually; /* width was set manually, not detected */
bool height_set_manually; /* height was set manually, not detected */
bool rate_limit_active; /* whether rate limiting is in effect */
bool rate_limit_specified; /* whether a rate limit value was set */
bool rate_limit_active; /* whether rate limiting is in effect (>0) */
char name[256]; /* flawfinder: ignore */
char format[256]; /* flawfinder: ignore */
char extra_display[256]; /* flawfinder: ignore */
@@ -107,6 +108,7 @@ int pv_remote_set(pvstate_t state, pid_t remote)
msgbuf.bufpercent = state->control.format_option.bufpercent;
msgbuf.lastwritten = state->control.format_option.lastwritten;
msgbuf.rate_limit = state->control.rate_limit;
msgbuf.rate_limit_specified = state->control.rate_limit_specified;
msgbuf.rate_limit_active = state->control.rate_limit_active;
msgbuf.buffer_size = state->control.target_buffer_size;
msgbuf.size = state->control.size;
@@ -324,8 +326,9 @@ static bool pv__rxsignal_usr2(pvstate_t state)
pv_state_set_format_options(state, format_options);
if (msgbuf.rate_limit_active)
pv_state_rate_limit_set(state, msgbuf.rate_limit, msgbuf.rate_limit_active);
if (msgbuf.rate_limit_specified)
pv_state_rate_limit_set(state, msgbuf.rate_limit, msgbuf.rate_limit_specified,
msgbuf.rate_limit_active);
if (msgbuf.buffer_size > 0) {
pv_state_target_buffer_size_set(state, msgbuf.buffer_size);
}
+10 -1
View File
@@ -649,9 +649,18 @@ void pv_state_discard_input_set(pvstate_t state, bool val)
state->control.discard_input = val;
}
void pv_state_rate_limit_set(pvstate_t state, long double val, bool is_active)
/*
* If "was_specified" is true, the limit was specified on the command line.
* This is used with --remote to determine whether to affect the remote
* process's rate limit settings.
*
* if "is_active" is true, the limit ("val") is not zero so rate limiting is
* active.
*/
void pv_state_rate_limit_set(pvstate_t state, long double val, bool was_specified, bool is_active)
{
state->control.rate_limit = val;
state->control.rate_limit_specified = was_specified;
state->control.rate_limit_active = is_active;
}