diff --git a/docs/pv.1 b/docs/pv.1 index c9730e8..d42f5d8 100644 --- a/docs/pv.1 +++ b/docs/pv.1 @@ -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. diff --git a/docs/pv.1.md b/docs/pv.1.md index 750e7ad..687cc70 100644 --- a/docs/pv.1.md +++ b/docs/pv.1.md @@ -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** diff --git a/src/include/options.h b/src/include/options.h index 36d25c8..5c27f59 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -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@*/ diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 268b310..730e6c7 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -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; /******************* diff --git a/src/include/pv.h b/src/include/pv.h index a65d405..c6d8abd 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -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); diff --git a/src/main/main.c b/src/main/main.c index 4c95137..31613af 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -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); diff --git a/src/main/options.c b/src/main/options.c index 89d1abb..67012ae 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -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)) { diff --git a/src/pv/remote.c b/src/pv/remote.c index 6f07d98..2733967 100644 --- a/src/pv/remote.c +++ b/src/pv/remote.c @@ -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); } diff --git a/src/pv/state.c b/src/pv/state.c index c325c8f..6e957b8 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -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; }