From: Andre Noll Date: Sat, 4 Jan 2014 05:38:23 +0000 (+0000) Subject: gui: Execute stat command in status_post_select(). X-Git-Tag: v0.5.3~12^2~11 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=405a66cac091943206ea466455638b876942fe1d;p=paraslash.git gui: Execute stat command in status_post_select(). pre_select methods should only deal with fd sets and select timeouts, so the part of status_pre_select() which restarts the status command belongs to status_post_select(). Unfortunately, after this change both status_pre_select() and status_post_select() need to know when to restart the stat command. Therefore we had to add a new global variable next_exec. The patch also moves status_pre_select() up so that the two functions are close to each other. --- diff --git a/gui.c b/gui.c index 40e93b0c..894fc2f8 100644 --- a/gui.c +++ b/gui.c @@ -644,15 +644,50 @@ static void clear_all_items(void) } } +static struct timeval next_exec; + +static void status_pre_select(fd_set *rfds, int *max_fileno, struct timeval *tv) +{ + struct timeval atm, diff; + + if (stat_pipe >= 0) + return para_fd_set(stat_pipe, rfds, max_fileno); + gettimeofday(&atm, NULL); + if (tv_diff(&next_exec, &atm, &diff) > 0) { + *tv = diff; + return; + } + tv->tv_sec = tv->tv_usec = 0; /* min delay */ +} + static void status_post_select(fd_set *rfds) { static char *buf; static int bufsize, loaded; - int ret, ret2; size_t sz; + pid_t pid; + int ret, ret2; - if (stat_pipe < 0) + if (stat_pipe < 0) { + struct timeval atm; + int fds[3] = {0, 1, 0}; + /* Avoid busy loop */ + gettimeofday(&atm, NULL); + if (tv_diff(&next_exec, &atm, NULL) > 0) + return; + next_exec.tv_sec = atm.tv_sec + 2; + ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds); + if (ret < 0) + return; + ret = mark_fd_nonblocking(fds[1]); + if (ret < 0) { + close(fds[1]); + return; + } + stat_pipe = fds[1]; return; + } + if (loaded >= bufsize) { if (bufsize > 1000 * 1000) { loaded = 0; @@ -954,35 +989,6 @@ static void signal_post_select(fd_set *rfds) } } -static void status_pre_select(fd_set *rfds, int *max_fileno, struct timeval *tv) -{ - static struct timeval next_exec, atm, diff; - int ret, fds[3] = {0, 1, 0}; - pid_t pid; - - if (stat_pipe >= 0) - goto success; - /* Avoid busy loop */ - gettimeofday(&atm, NULL); - if (tv_diff(&next_exec, &atm, &diff) > 0) { - if (tv_diff(&diff, tv, NULL) < 0) - *tv = diff; - return; - } - next_exec.tv_sec = atm.tv_sec + 2; - ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds); - if (ret < 0) - return; - ret = mark_fd_nonblocking(fds[1]); - if (ret < 0) { - close(fds[1]); - return; - } - stat_pipe = fds[1]; -success: - para_fd_set(stat_pipe, rfds, max_fileno); -} - #define COMMAND_BUF_SIZE 32768 static enum cmd_status cmd_status(void)