diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-11-03 17:20:41 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-11-03 17:20:41 +0000 |
| commit | db7f22db73d6ab55cd283c73c12328e9e0325ab9 (patch) | |
| tree | 15f9a8340535c5dcd6ad20935ac6399f6c8526f7 | |
| parent | ebef96d5f8482d9b2e945f3f68c3867063b7efb5 (diff) | |
| download | btpd-db7f22db73d6ab55cd283c73c12328e9e0325ab9.tar.gz btpd-db7f22db73d6ab55cd283c73c12328e9e0325ab9.zip | |
Avoid unnecessary operations on tracker stop. Use STOP_ERRORS constant
for the number of tracker errors to tolerate when we're stopping.
| -rw-r--r-- | btpd/tracker_req.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c index 72f1ebd..57d4471 100644 --- a/btpd/tracker_req.c +++ b/btpd/tracker_req.c @@ -5,6 +5,7 @@ #include "tracker_req.h" #define REQ_DELAY 1 +#define STOP_ERRORS 5 #define REQ_TIMEOUT (& (struct timeval) { 120, 0 }) #define RETRY_WAIT (& (struct timeval) { rand_between(35, 70), 0 }) @@ -140,7 +141,10 @@ tr_result(struct torrent *tp, enum tr_res res, int interval) { struct tracker *tr = tp->tr; tr->req = NULL; - if (res == TR_RES_OK) { + if (tr->event == TR_EV_STOPPED && + (res == TR_RES_OK || tr->nerrors >= STOP_ERRORS - 1)) + tr_set_stopped(tp); + else if (res == TR_RES_OK) { good_url(tr); tr->interval = interval; tr->nerrors = 0; @@ -152,8 +156,6 @@ tr_result(struct torrent *tp, enum tr_res res, int interval) btpd_ev_add(&tr->timer, RETRY_WAIT); next_url(tr); } - if (tr->event == TR_EV_STOPPED && (tr->nerrors == 0 || tr->nerrors >= 5)) - tr_set_stopped(tp); } static void @@ -166,7 +168,7 @@ timer_cb(int fd, short type, void *arg) btpd_log(BTPD_L_ERROR, "Tracker request timed out for '%s'.\n", torrent_name(tp)); tr->nerrors++; - if (tr->event == TR_EV_STOPPED && tr->nerrors >= 5) { + if (tr->event == TR_EV_STOPPED && tr->nerrors >= STOP_ERRORS) { tr_set_stopped(tp); break; } |