From 9c826f6f1a652edce0c8bb15b0cf94e259296e53 Mon Sep 17 00:00:00 2001 From: Thomas Albers Raviola Date: Mon, 28 Aug 2023 22:08:46 +0200 Subject: Add delay between attempts --- cmd.c | 6 +++++- serial.c | 6 ++++++ zup.c | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd.c b/cmd.c index a460808..29bc8c9 100644 --- a/cmd.c +++ b/cmd.c @@ -195,7 +195,11 @@ cmd_write(int fd, const struct command *cmd, int argc, char **args) } } - puts("\nDone!"); + putchar('\n'); + + if (!err) + puts("Done!"); + fclose(fp); } else if (param.human_readable) { do { diff --git a/serial.c b/serial.c index 5f7548c..82a5abd 100644 --- a/serial.c +++ b/serial.c @@ -206,6 +206,9 @@ read_buf(int fd, size_t len, void *_buf) } else { write_ack(fd, NACK); } + + /* Wait 2 ms between attempts */ + usleep(2000); } err = ERR_NACK; @@ -249,6 +252,9 @@ write_buf(int fd, size_t len, const void *_buf) if (err != NACK) goto error; + + /* Wait 2 ms between attempts */ + usleep(2000); } error: diff --git a/zup.c b/zup.c index 5fe1e61..e7f8fe6 100644 --- a/zup.c +++ b/zup.c @@ -128,7 +128,7 @@ parse_options(int argc, char *const argv[]) case 'a': errno = 0; param.max_attempts = strtoul(optarg, NULL, 10); - if (errno) { + if (errno || !optarg || strlen(optarg) == 0) { perror("Invalid attempts number\n"); exit(EXIT_FAILURE); } @@ -232,7 +232,8 @@ struct param param = { .verbose = 0, .human_readable = 0, .repl = 0, - .show_progress = 0 + .show_progress = 0, + .max_attempts = 5 }; // TODO: Support stdin/stdout -- cgit v1.2.3