diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c index 3f3a8be..61425cb 100644 --- a/btpd/tracker_req.c +++ b/btpd/tracker_req.c @@ -97,6 +97,16 @@ tr_cancel(struct tracker *tr) tr->req = NULL; } +static void +tr_set_stopped(struct torrent *tp) +{ + struct tracker *tr = tp->tr; + btpd_ev_del(&tr->timer); + tr->ttype = TIMER_NONE; + if (tr->req != NULL) + tr_cancel(tr); +} + static void tr_send(struct torrent *tp, enum tr_event event) { @@ -117,8 +127,12 @@ tr_send(struct torrent *tp, enum tr_event event) if ((op == NULL || (tr->req = op->request(tp, event, get_url(tr))) == NULL)) { - next_url(tr); tr->nerrors++; + if (tr->event == TR_EV_STOPPED && tr->nerrors >= STOP_ERRORS) { + tr_set_stopped(tp); + return; + } + next_url(tr); tr->ttype = TIMER_RETRY; btpd_ev_add(&tr->timer, (& (struct timeval) { 5, 0 })); } else { @@ -128,16 +142,6 @@ tr_send(struct torrent *tp, enum tr_event event) } } -static void -tr_set_stopped(struct torrent *tp) -{ - struct tracker *tr = tp->tr; - btpd_ev_del(&tr->timer); - tr->ttype = TIMER_NONE; - if (tr->req != NULL) - tr_cancel(tr); -} - void tr_result(struct torrent *tp, enum tr_res res, int interval) {