From d0846b910e0cbbbf8d443b85d8281ab03d480b6a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 4 Jan 2013 16:42:45 +0100 Subject: [PATCH] trafgen: Move common duplicate calls from xmit_*_or_die to main_loop Also call xmit_precheck before accessing ctx (when calling compile_packets). Signed-off-by: Tobias Klauser --- src/trafgen.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/trafgen.c b/src/trafgen.c index 33ea012b..9d1252d2 100644 --- a/src/trafgen.c +++ b/src/trafgen.c @@ -281,10 +281,6 @@ static void xmit_slowpath_or_die(struct ctx *ctx) .sll_halen = ETH_ALEN, }; - xmit_precheck(ctx); - - sock = pf_socket(); - if (ctx->rfraw) { ctx->device_trans = xstrdup(ctx->device); xfree(ctx->device); @@ -348,7 +344,6 @@ static void xmit_slowpath_or_die(struct ctx *ctx) printf("\r%12lu bytes outgoing\n", ctx->tx_bytes); printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec); - close(sock); } static void xmit_fastpath_or_die(struct ctx *ctx) @@ -361,10 +356,6 @@ static void xmit_fastpath_or_die(struct ctx *ctx) struct frame_map *hdr; struct timeval start, end, diff; - xmit_precheck(ctx); - - sock = pf_socket(); - if (ctx->rfraw) { ctx->device_trans = xstrdup(ctx->device); xfree(ctx->device); @@ -472,19 +463,22 @@ static void xmit_fastpath_or_die(struct ctx *ctx) printf("\r%12lu frames outgoing\n", ctx->tx_packets); printf("\r%12lu bytes outgoing\n", ctx->tx_bytes); printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec); - - close(sock); } static void main_loop(struct ctx *ctx, char *confname, bool slow) { + xmit_precheck(ctx); compile_packets(confname, ctx->verbose); + sock = pf_socket(); + if (slow) xmit_slowpath_or_die(ctx); else xmit_fastpath_or_die(ctx); + close(sock); + cleanup_packets(); } -- 2.11.4.GIT