about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--btpd/tracker_req.c26
1 files changed, 15 insertions, 11 deletions
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
@@ -98,6 +98,16 @@ tr_cancel(struct tracker *tr)
 }
 
 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)
 {
     struct tracker *tr = tp->tr;
@@ -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)
 {