Pass the othermonitor_* values into the main state, and add TODO markers for next steps (#67).

This commit is contained in:
Andrew Wood
2026-03-29 21:49:47 +01:00
parent 2a54d4edcc
commit 00f06f2b2c
7 changed files with 25 additions and 9 deletions
+3
View File
@@ -201,6 +201,9 @@ struct pvstate_s {
off_t size; /* total size of data */
unsigned int skip_errors; /* skip read errors counter */
int output_fd; /* fd to write output to */
pid_t othermonitor_pid; /* pid of the other monitor, in "-M both" mode */
int othermonitor_read_fd; /* fd to read transfer counts from other monitor */
int othermonitor_write_fd; /* fd to write transfer counts to other monitor */
unsigned int average_rate_window; /* time window in seconds for average rate calculations */
unsigned int history_interval; /* seconds between each average rate calc history entry */
pvdisplay_width_t width; /* screen width */
+1
View File
@@ -239,6 +239,7 @@ extern void pv_state_extra_display_set(pvstate_t, /*@null@*/ const char *);
extern void pv_state_output_set(pvstate_t, int, const char *);
extern void pv_state_average_rate_window_set(pvstate_t, unsigned int);
extern void pv_state_set_terminal_supports_utf8(pvstate_t, bool);
extern void pv_state_othermonitor_set(pvstate_t, pid_t, int, int);
extern void pv_state_inputfiles(pvstate_t, unsigned int, const char **);
extern void pv_state_watchfds(pvstate_t, unsigned int, const pid_t *, const int *);
+2 -9
View File
@@ -286,14 +286,7 @@ static int pv__store_and_forward(pvstate_t state, opts_t opts, bool can_have_eta
* As a side effect, "command_fd" is closed.
*/
static int pv__run_monitor(const char *program_name, pvstate_t state, pvside_t side, int command_fd,
/*@unused@ */
__attribute__((unused)) pid_t othermonitor_pid,
/*@unused@ */
__attribute__((unused))
int othermonitor_read_fd,
/*@unused@ */
__attribute__((unused))
int othermonitor_write_fd)
pid_t othermonitor_pid, int othermonitor_read_fd, int othermonitor_write_fd)
{
const char *dummy_argv[1]; /* flawfinder: ignore */
@@ -325,7 +318,7 @@ static int pv__run_monitor(const char *program_name, pvstate_t state, pvside_t s
fprintf(stderr, "%s: %s\n", program_name, strerror(errno));
}
/* TODO: pass othermonitor_* into the state for ratio display. */
pv_state_othermonitor_set(state, othermonitor_pid, othermonitor_read_fd, othermonitor_write_fd);
/*@-observertrans@ */
dummy_argv[0] = "-";
+1
View File
@@ -1290,6 +1290,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
opts->eta = true;
opts->rate = true;
opts->bytes = true;
/* TODO: add ratio format if "-M both" */
}
/* If -Z was given but not -E, pretend one -E was given too. */
+1
View File
@@ -544,6 +544,7 @@ pvdisplay_bytecount_t pv_formatter_segmentcontent(char *content, pvformatter_arg
{ "{sgr:colour,...}", &pv_formatter_sgr, false },
{ NULL, NULL, false }
};
/* TODO: formatter for ratio, for "-M both" */
return format_component_array;
}
+7
View File
@@ -185,6 +185,10 @@ int pv_main_loop(pvstate_t state)
unsigned int file_idx;
bool output_is_pipe;
/* TODO: treat "-F ''" as "-q" so there's no extra blank line. */
/* TODO: if "-q", turn off "-c", again so there's no blank line. */
/* May need local no_display and cursor flags for this. */
/*
* "written" is ALWAYS bytes written by the last transfer.
*
@@ -338,6 +342,9 @@ int pv_main_loop(pvstate_t state)
pv_elapsedtime_add_nsec(&next_remotecheck, REMOTE_INTERVAL);
}
/* TODO: occasionally check othermonitor_read_fd, calculate ratio */
/* TODO: occasionally send to othermonitor_write_fd */
if (1 == state->flags.trigger_exit)
break;
+10
View File
@@ -191,6 +191,9 @@ pvstate_t pv_state_alloc(void)
state->watchfd.count = 0;
state->control.output_fd = -1;
state->control.othermonitor_pid = 0;
state->control.othermonitor_read_fd = -1;
state->control.othermonitor_write_fd = -1;
#ifdef HAVE_IPC
state->cursor.shmid = -1;
state->cursor.pvcount = 1;
@@ -769,6 +772,13 @@ void pv_state_set_terminal_supports_utf8(pvstate_t state, bool val)
state->status.terminal_supports_utf8 = val;
}
void pv_state_othermonitor_set(pvstate_t state, pid_t pid, int read_fd, int write_fd)
{
state->control.othermonitor_pid = pid;
state->control.othermonitor_read_fd = read_fd;
state->control.othermonitor_write_fd = write_fd;
}
/*
* Set the array of input files.
*/