From ef49d07dd9a1114486169dcb01c4ad393986026f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 19 Mar 2019 16:42:54 +0100 Subject: [PATCH] Better loop to choose links --- src/algo_rr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index d54e165..df665c2 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -293,17 +293,21 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { bp->ip.ap.str.bitfield = rr->remote_links; bp->ip.ap.str.prevlink = rr->current_link; - do { + int max = 10; + while(1) { + if (max-- < 0) break; rr->current_link = (rr->current_link) + 1 % 10; - } while (!(rr->my_links & (1 << rr->current_link))); + if (!(rr->my_links & (1 << rr->current_link))) continue; + sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + rr->current_link); //@FIXME Hardcoded + to_fdinfo = evt_core_get_from_url (ctx, url); + if (to_fdinfo != NULL) break; + } rr->emit_time = curr; rr->sent_id++; // 4. A whole packet has been read, we will find someone to write it - sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + rr->current_link); //@FIXME Hardcoded - to_fdinfo = evt_core_get_from_url (ctx, url); if (to_fdinfo == NULL) { - fprintf(stderr, "No fd for URL %s in udp-read. Dropping packet :( \n", url); + fprintf(stderr, "No fd for URL %s in udp-read. Dropping packet :( \n", fdinfo->url); mv_buffer_wtor (app_ctx, fdinfo, bp); return 1; }