diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2012-01-26 17:53:54 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2012-01-26 17:53:54 +0000 |
commit | a1379edbd6f971077e8dd1e70ff4f0e512057551 (patch) | |
tree | 5ad8279fd53feba7bcdbd7b2b25229a023e9a6d5 /usr.bin/tcpbench/tcpbench.c | |
parent | 6fb89bbc70518aa250f7712e13f3352b6ace5579 (diff) |
add a timer to tcpbench as a command-line option (-t) so
that it is possible to stop the tcpbench client after a certain number
of seconds. This makes it easier to use tcpbench as part of a script.
From: Lawrence Teo <lteo at lteo.net>
ok phessler haesbaert and myself
Diffstat (limited to 'usr.bin/tcpbench/tcpbench.c')
-rw-r--r-- | usr.bin/tcpbench/tcpbench.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/usr.bin/tcpbench/tcpbench.c b/usr.bin/tcpbench/tcpbench.c index d5aef6a6773..6cddd5801a5 100644 --- a/usr.bin/tcpbench/tcpbench.c +++ b/usr.bin/tcpbench/tcpbench.c @@ -176,7 +176,7 @@ usage(void) "usage: tcpbench -l\n" " tcpbench [-uv] [-B buf] [-b addr] [-k kvars] [-n connections]\n" " [-p port] [-r interval] [-S space] [-T toskeyword]\n" - " [-V rtable] hostname\n" + " [-t secs] [-V rtable] hostname\n" " tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n" " [-r interval] [-S space] [-T toskeyword] [-V rtable]\n"); exit(1); @@ -967,11 +967,19 @@ map_tos(char *s, int *val) return (0); } +static void +quit(int sig, short event, void *arg) +{ + exit(0); +} + int main(int argc, char **argv) { extern int optind; extern char *optarg; + struct timeval tv; + unsigned int secs; char kerr[_POSIX2_LINE_MAX], *tmp; struct addrinfo *aitop, *aib, hints; @@ -980,7 +988,7 @@ main(int argc, char **argv) int ch, herr, nconn; struct nlist nl[] = { { "_tcbtable" }, { "" } }; const char *host = NULL, *port = DEFAULT_PORT, *srcbind = NULL; - struct event ev_sigint, ev_sigterm, ev_sighup; + struct event ev_sigint, ev_sigterm, ev_sighup, ev_progtimer; struct statctx *udp_sc = NULL; /* Init world */ @@ -994,8 +1002,9 @@ main(int argc, char **argv) ptb->Tflag = -1; nconn = 1; aib = NULL; + secs = 0; - while ((ch = getopt(argc, argv, "b:B:hlk:n:p:r:sS:T:uvV:")) != -1) { + while ((ch = getopt(argc, argv, "b:B:hlk:n:p:r:sS:t:T:uvV:")) != -1) { switch (ch) { case 'b': srcbind = optarg; @@ -1068,6 +1077,12 @@ main(int argc, char **argv) if (ptb->Tflag == -1 || ptb->Tflag > 255 || errstr) errx(1, "illegal tos value %s", optarg); break; + case 't': + secs = strtonum(optarg, 1, UINT_MAX, &errstr); + if (errstr != NULL) + errx(1, "secs is %s: %s", + errstr, optarg); + break; case 'h': default: usage(); @@ -1171,8 +1186,15 @@ main(int argc, char **argv) if (ptb->sflag) server_init(aitop, udp_sc); - else + else { + if (secs > 0) { + timerclear(&tv); + tv.tv_sec = secs + 1; + evtimer_set(&ev_progtimer, quit, NULL); + evtimer_add(&ev_progtimer, &tv); + } client_init(aitop, nconn, udp_sc, aib); + } /* libevent main loop*/ event_dispatch(); |