Skip to content

Commit

Permalink
Merge pull request #86 from dparrish/revert-80-dev/regular-cb-improve
Browse files Browse the repository at this point in the history
Revert "Regular callback improvements"
  • Loading branch information
RobSanders authored Dec 2, 2022
2 parents 589c718 + b983098 commit 3034c77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
17 changes: 6 additions & 11 deletions libcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ int cli_loop(struct cli_def *cli, int sockfd) {

// Set the last action now so we don't time immediately
if (cli->idle_timeout) time(&cli->last_action);
if (cli->regular_callback) time(&cli->last_regular);

// Start off in unprivileged mode
cli_set_privilege(cli, PRIVILEGE_UNPRIVILEGED);
Expand Down Expand Up @@ -1187,16 +1186,6 @@ int cli_loop(struct cli_def *cli, int sockfd) {
cli->showprompt = 0;
}

if (cli->regular_callback) {
if (time(NULL) - cli->last_regular >= cli->timeout_tm.tv_sec) {
if (cli->regular_callback(cli) != CLI_OK) {
l = -1;
break;
}
time(&cli->last_regular);
}
}

if ((sr = cli_socket_wait(sockfd, &tm)) < 0) {
if (errno == EINTR) continue;
perror(CLI_SOCKET_WAIT_PERROR);
Expand All @@ -1205,6 +1194,12 @@ int cli_loop(struct cli_def *cli, int sockfd) {
}

if (sr == 0) {
// Timeout every second
if (cli->regular_callback && cli->regular_callback(cli) != CLI_OK) {
l = -1;
break;
}

if (cli->idle_timeout) {
if (time(NULL) - cli->last_action >= cli->idle_timeout) {
if (cli->idle_timeout_callback) {
Expand Down
1 change: 0 additions & 1 deletion libcli.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct cli_def {
time_t idle_timeout;
int (*idle_timeout_callback)(struct cli_def *);
time_t last_action;
time_t last_regular;
int telnet_protocol;
void *user_context;
struct cli_optarg_pair *found_optargs;
Expand Down

0 comments on commit 3034c77

Please sign in to comment.