From 298e385dae24fe8f3550927be3835f2f209d7275 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 19 Mar 2019 15:54:31 +0100 Subject: [PATCH] Handle timeout --- src/algo_rr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index 1c613a0..b748948 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -6,8 +6,8 @@ struct waited_pkt { uint16_t id; int link_num; - int timer_fd; uint8_t on; + int timer_fd; }; struct deferred_pkt { @@ -102,6 +102,7 @@ int set_timeout(struct evt_core_ctx* evts, uint64_t micro_sec, struct waited_pkt fdinfo.free_other = NULL; sprintf(fdinfo.url, "timer:%ld:1", micro_sec); evt_core_add_fd (evts, &fdinfo); + return fdinfo.fd; } @@ -130,7 +131,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, rr->wait[idx_waited].on = 1; rr->wait[idx_waited].id = bp->ip.ap.str.id; rr->wait[idx_waited].link_num = bp->ip.ap.str.prevlink; - set_timeout(ctx, timeout, &rr->wait[idx_waited]); + rr->wait[idx_waited].timer_fd = set_timeout(ctx, timeout, &rr->wait[idx_waited]); } // 4. We queue the packet @@ -255,7 +256,14 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { struct algo_ctx* app_ctx = fdinfo->cat->app_ctx; struct rr_ctx* rr = app_ctx->misc; + struct waited_pkt* pkt = fdinfo->other; + pkt->on = 0; + evt_core_rm_fd(ctx, fdinfo->fd); + rr->remote_links &= 0xffff ^ 1 << pkt->link_num; + rr->recv_id = pkt->id; + + rr_pkt_unroll (ctx, app_ctx); return 1; }