Commit 9eee5a01 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(last_progress_status): New variable.

(parse_async): Fixed off-by-one parse error.  Report parse errors
	more verbosely.
(report_progress): New function.  Report progress, but print
	nothing unless we have received a new reply from the server
	since the last time we were called.
(longopts): New constant.
(main): Use getopt_long to parse the arguments.  Enable progress
	report.  Fixed a broken printf format string.
parent 3af3df0f
......@@ -57,6 +57,7 @@
#include "s-string.h"
#include "isc.h"
#include "getopt.h"
#include "linkansi.h"
#include "unused.h"
......@@ -70,12 +71,16 @@ static long rcvd_requests = 0;
static long rcvd_bytes = 0;
static int server;
static int writing_to_server;
static long last_progress_status = 0;
static oop_call_fd read_stdin;
static oop_call_fd read_server;
static oop_call_fd write_server;
static oop_call_time report_stats;
static oop_call_time report_progress;
static oop_call_time end_it;
static void
......@@ -175,6 +180,8 @@ parse_async(const char *beg,
return NULL;
hunt += len;
}
else
hunt--;
}
else if (*hunt == '\n')
return hunt + 1;
......@@ -188,7 +195,11 @@ parse_async(const char *beg,
case '*':
break;
default:
fprintf(stderr, "unexpected char from server: %c\n", *hunt);
fprintf(stderr, "unexpected char from server in async: %c\n",
*hunt);
fprintf(stderr, "Current block looks like this (%d chars):\n",
(int)(end - beg));
fprintf(stderr, "%.*s\n", (int)(end - beg), beg);
exit(1);
}
}
......@@ -366,6 +377,21 @@ report_stats(oop_source *source,
return OOP_CONTINUE;
}
static void *
report_progress(oop_source *source,
struct timeval UNUSED(tv),
void *user)
{
if (rcvd_requests > last_progress_status)
{
last_progress_status = rcvd_requests;
printf("Progress: %ld pending reqs\n", sent_requests - rcvd_requests);
fflush(stdout);
}
arm_timer(source, 2, 0, report_progress, user);
return OOP_CONTINUE;
}
static void *
end_it(oop_source *UNUSED(source),
struct timeval UNUSED(tv),
......@@ -394,14 +420,25 @@ limit_it(oop_source *oop,
return OOP_CONTINUE;
}
static struct option longopts[] = {
{"verbose", 0, 0, 'v'},
{"silent", 0, 0, 's'},
{"time-abort", 0, 0, 'a'},
{"time-limit", 0, 0, 'l'},
{ 0, 0, 0, 0 }
};
int
main(int argc,
char **argv)
{
int optc;
int oldflags;
ssize_t rv;
oop_source_sys *sys;
oop_source *oop;
struct timeval progress_timer;
struct timeval report_timer;
struct timeval end_timer;
char buf[8192];
......@@ -411,30 +448,36 @@ main(int argc,
int do_abort_time = 0;
int verbose = 0;
if (argc != 5)
fail("usage");
if (!strcmp(argv[1], "--verbose"))
verbose = 1;
else if (!strcmp(argv[1], "--silent"))
verbose = 0;
else
while ((optc = getopt_long(argc, argv, "valp",
longopts, (int *) 0)) != EOF)
{
fprintf(stderr, "usage error\n");
exit(1);
}
switch (optc)
{
case 'v':
verbose = 1;
break;
if (!strcmp(argv[2], "--time-abort"))
do_abort_time = 1;
else if (!strcmp(argv[2], "--time-limit"))
do_limit_time = 1;
else
{
fprintf(stderr, "usage error\n");
exit(1);
case 's':
verbose = 0;
break;
case 'a':
do_abort_time = 1;
break;
case 'l':
do_limit_time = 1;
break;
case '?':
fail("usage");
}
}
if (optind + 2 != argc)
fail("usage");
server = tcp_connect(argv[3], argv[4]);
server = tcp_connect(argv[optind], argv[optind + 1]);
puts("connected");
if (write(server, "A3Hfoo\n", 7) != 7)
fail("write");
......@@ -447,7 +490,7 @@ main(int argc,
}
if (rv != 7 || strncmp(buf, "LysKOM\n", 7) != 0)
{
fprintf(stderr, "Got bad handshake ``%*s'' from the server\n",
fprintf(stderr, "Got bad handshake ``%.*s'' from the server\n",
(int)rv, buf);
exit(1);
}
......@@ -473,6 +516,8 @@ main(int argc,
if (verbose)
arm_timer(oop, 0, 0, report_stats, &report_timer);
arm_timer(oop, 0, 500000, report_progress, &progress_timer);
if (do_limit_time)
arm_timer(oop, 5, 0, limit_it, &end_timer);
else if (do_abort_time)
......@@ -483,6 +528,9 @@ main(int argc,
if (verbose)
oop->cancel_time(oop, report_timer, report_stats, &report_timer);
printf("End of progress reports\n");
oop->cancel_time(oop, progress_timer, report_progress, &progress_timer);
do_report_stats();
oop->cancel_fd(oop, 0, OOP_READ);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment