From 05ad600483c7aca0c82866169e1e605c6f594c44 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Tue, 1 Nov 2005 09:50:11 +0000 Subject: [PATCH] added --repeat to test closing connection after request count is exhausted --- org.glite.lb.server-bones/examples/cnt_example.c | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/org.glite.lb.server-bones/examples/cnt_example.c b/org.glite.lb.server-bones/examples/cnt_example.c index 5f73a23..80b6af3 100644 --- a/org.glite.lb.server-bones/examples/cnt_example.c +++ b/org.glite.lb.server-bones/examples/cnt_example.c @@ -21,6 +21,7 @@ static struct option opts[] = { { "debug", no_argument, NULL, 'd'}, { "msg", required_argument, NULL, 'm'}, { "port", required_argument, NULL, 'p'}, + { "repeat", required_argument, NULL, 'r'}, }; int debug = 0; @@ -49,11 +50,11 @@ int main(int argc, char **argv) int opt, sock, n; - + int repeat = 1; me = strrchr(argv[0], '/'); if ( me ) me++; else me = argv[0]; - while ( (opt = getopt_long(argc, argv,"p:m:hd", opts, NULL)) != EOF ) + while ( (opt = getopt_long(argc, argv,"p:m:hdr:", opts, NULL)) != EOF ) { switch ( opt ) { @@ -64,6 +65,7 @@ int main(int argc, char **argv) port = atoi(optarg); break; case 'd': debug = 1; break; + case 'r': repeat = atoi(optarg); break; case 'h': usage(me); return 0; case '?': usage(me); return 1; } @@ -84,19 +86,21 @@ int main(int argc, char **argv) exit(1); } n = strlen(msg? msg: DEF_MSG); - if ( writen(sock, msg? msg: DEF_MSG, n) != n ) - { - dprintf(("error writing message\n")); - exit(1); - } - printf("reply: "); fflush(stdout); - n = readln(sock, buff); - if ( n < 0 ) - { - perror("read() reply error"); - return 1; + for (;repeat; repeat--) { + if ( writen(sock, msg? msg: DEF_MSG, n) != n ) + { + dprintf(("error writing message\n")); + exit(1); + } + printf("reply: "); fflush(stdout); + n = readln(sock, buff); + if ( n < 0 ) + { + perror("read() reply error"); + return 1; + } + writen(0, buff, n); } - writen(0, buff, n); close(sock); return 0; -- 1.8.2.3