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 | |
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
-rw-r--r-- | usr.bin/tcpbench/tcpbench.1 | 9 | ||||
-rw-r--r-- | usr.bin/tcpbench/tcpbench.c | 30 |
2 files changed, 33 insertions, 6 deletions
diff --git a/usr.bin/tcpbench/tcpbench.1 b/usr.bin/tcpbench/tcpbench.1 index dd59a1690a4..96d604a7f47 100644 --- a/usr.bin/tcpbench/tcpbench.1 +++ b/usr.bin/tcpbench/tcpbench.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tcpbench.1,v 1.16 2011/12/18 01:19:07 haesbaert Exp $ +.\" $OpenBSD: tcpbench.1,v 1.17 2012/01/26 17:53:53 henning Exp $ .\" .\" Copyright (c) 2008 Damien Miller <djm@mindrot.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 18 2011 $ +.Dd $Mdocdate: January 26 2012 $ .Dt TCPBENCH 1 .Os .Sh NAME @@ -33,6 +33,7 @@ .Op Fl r Ar interval .Op Fl S Ar space .Op Fl T Ar toskeyword +.Op Fl t Ar secs .Op Fl V Ar rtable .Ar hostname .Nm @@ -125,6 +126,10 @@ or one of the DiffServ Code Points: .Ar af11 ... af43 , .Ar cs0 ... cs7 ; or a number in either hex or decimal. +.It Fl t Ar secs +Stop after +.Ar secs +seconds. .It Fl u Use UDP instead of TCP; this must be specified on both the client and the server. 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(); |