aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-02-18 14:07:37 -0700
committerJens Axboe <axboe@kernel.dk>2024-02-18 14:07:37 -0700
commit264ef157a3efa0d5b908b679bcf5fa598e40c654 (patch)
treec7212bd8f9f2ef64afa878e10f754682cc300784
parent0b71b396bc504c963c7aafa6ea5e487a9296c310 (diff)
downloadliburing-264ef157a3efa0d5b908b679bcf5fa598e40c654.tar.gz
examples/proxy: ensure end_time is valid when used
If connections are closed by terminating proxy, then end_time will never have been set for the connections. Ensure it's set before printing stats, if needed. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/proxy.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/examples/proxy.c b/examples/proxy.c
index e01fdbb5..fa8883f2 100644
--- a/examples/proxy.c
+++ b/examples/proxy.c
@@ -119,6 +119,7 @@ enum {
CONN_F_DISCONNECTED = 2,
CONN_F_PENDING_SHUTDOWN = 4,
CONN_F_STATS_SHOWN = 8,
+ CONN_F_END_TIME = 16,
};
#define NR_BUF_RINGS 2
@@ -286,6 +287,9 @@ static void __show_stats(struct conn *c)
if (c->flags & CONN_F_STATS_SHOWN)
return;
+ if (!(c->flags & CONN_F_END_TIME))
+ gettimeofday(&c->end_time, NULL);
+
msec = (c->end_time.tv_sec - c->start_time.tv_sec) * 1000;
msec += (c->end_time.tv_usec - c->start_time.tv_usec) / 1000;
@@ -565,7 +569,7 @@ static void close_cd(struct conn *c, struct conn_dir *cd)
cd->pending_shutdown = 1;
if (!(c->flags & CONN_F_PENDING_SHUTDOWN)) {
gettimeofday(&c->end_time, NULL);
- c->flags |= CONN_F_PENDING_SHUTDOWN;
+ c->flags |= CONN_F_PENDING_SHUTDOWN | CONN_F_END_TIME;
}
}