Fix timer bug + comment some logs

This commit is contained in:
Quentin Dufour 2019-03-27 17:46:10 +01:00
parent 283dfd82e1
commit c6f7199bf6

View file

@ -133,7 +133,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo,
url_get_port (buffer, fdinfo->url);
int link_num = atoi(buffer) - 7500; // @FIXME Hardcoded
printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id);
//printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id);
// 0. Update remote links
if (ring_lt(rr->recv_id_late, bp->ip.ap.str.id) && !(rr->remote_links & 1 << link_num)) {
@ -198,27 +198,18 @@ void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct
// 2. Get the buffer
struct buffer_packet* bp = get_app_buffer (app_ctx, &dp->idx);
printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id);
//printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id);
// 3. We update our cursor
rr->recv_id = bp->ip.ap.str.id;
// 4. We check that we don't have a running timeout
// We want to keep timer until the end to allow link update on multi receive
/*int idx_real = bp->ip.ap.str.id % PACKET_BUFFER_SIZE;
if (rr->wait[idx_real].on) {
rr->wait[idx_real].on = 0;
evt_core_rm_fd (ctx, rr->wait[idx_real].timer_fd);
printf("Removed timer for packet %d\n",bp->ip.ap.str.id);
}*/
// 5. We free the buffer if it's a control packet and quit
// 4. We free the buffer if it's a control packet and quit
if (bp->ip.ap.str.flags & PKT_CONTROL) {
mv_buffer_atof (app_ctx, &dp->idx);
return;
}
// 6. Find its target
// 5. Find its target
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);
to_fdinfo = evt_core_get_from_url (ctx, url);
if (to_fdinfo == NULL) {
@ -227,7 +218,7 @@ void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct
mv_buffer_atof (app_ctx, &dp->idx);
}
// 4. We move the buffer and notify the target
// 6. We move the buffer and notify the target
//mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo, bp);
mv_buffer_atow (app_ctx, &dp->idx, to_fdinfo);
rr_on_udp_write(ctx, to_fdinfo);
@ -239,7 +230,7 @@ void rr_pkt_unroll(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx) {
struct buffer_packet* bp = NULL;
while(1) {
printf("Trying to deliver %d\n", rr->recv_id+1);
//printf("Trying to deliver %d\n", rr->recv_id+1);
struct deferred_pkt* def = &rr->real[(rr->recv_id+1) % PACKET_BUFFER_SIZE];
if (!def->on) break;
fdinfo = evt_core_get_from_fd (ctx, def->link_fd);
@ -250,7 +241,7 @@ void rr_pkt_unroll(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx) {
}
rr_deliver(ctx, fdinfo, def);
printf("Delivered %d\n", rr->recv_id);
//printf("Delivered %d\n", rr->recv_id);
}
}
@ -343,7 +334,7 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
bp->ip.ap.str.deltat = mili_sec;
bp->ip.ap.str.bitfield = rr->remote_links;
bp->ip.ap.str.prevlink = rr->current_link;
printf("Will send packet id=%d\n", bp->ip.ap.str.id);
//printf("Will send packet id=%d\n", bp->ip.ap.str.id);
rr->emit_time = curr;
rr->sent_id++;
@ -419,7 +410,7 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
struct waited_pkt* pkt = fdinfo->other;
pkt->on = 0;
if (ring_gt (pkt->id, rr->recv_id_late)) rr->recv_id_late = pkt->id;
if (ring_le (pkt->id, rr->recv_id)) return 1;
if (ring_le (pkt->id, rr->recv_id)) goto end;
printf("Timer reached for packet %d\n", pkt->id);
@ -433,6 +424,7 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
rr_pkt_unroll (ctx, app_ctx);
}
end:
evt_core_rm_fd(ctx, fdinfo->fd);
return 1;
}