From 6a752c90cc10d192f7c22af00689f0ec2f9785e6 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 15 Feb 2006 09:58:23 +0100 Subject: [PATCH] [PATCH] blktrace: allow client/server to signal end-of-run properly --- blktrace.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/blktrace.c b/blktrace.c index 2cd1105..56ec07c 100644 --- a/blktrace.c +++ b/blktrace.c @@ -675,6 +675,21 @@ static int net_send_header(struct thread_information *tip, unsigned int len) return write_data_net(net_out_fd, &hdr, sizeof(hdr)); } +/* + * send header with 0 length to signal end-of-run + */ +static void net_client_send_close(void) +{ + struct blktrace_net_hdr hdr; + + hdr.magic = BLK_IO_TRACE_MAGIC; + hdr.cpu = 0; + hdr.max_cpus = ncpus; + hdr.len = 0; + + write_data_net(net_out_fd, &hdr, sizeof(hdr)); +} + static int flush_subbuf_net(struct thread_information *tip, struct tip_subbuf *ts) { @@ -867,6 +882,9 @@ static void wait_for_threads(void) tips_running += !tip->exited; } while (tips_running); } + + if (net_mode == Net_client) + net_client_send_close(); } static void fill_ofname(char *dst, char *buts_name, int cpu) @@ -1223,6 +1241,14 @@ static int net_server_loop(void) bnh.len = be32_to_cpu(bnh.len); } + /* + * len == 0 means that the other end signalled end-of-run + */ + if (!bnh.len) { + fprintf(stderr, "server: end of run\n"); + return 1; + } + tip = net_get_tip(&bnh); if (!tip) return 1; @@ -1270,6 +1296,7 @@ static int net_server(void) return 1; } +repeat: printf("blktrace: waiting for incoming connection...\n"); socklen = sizeof(addr); @@ -1299,7 +1326,11 @@ static int net_server(void) } show_stats(); - return 0; + + if (is_done()) + return 0; + + goto repeat; } /* -- 2.25.1