diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 20:55:02 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 20:55:02 +0000 |
| commit | cd1164ef0227c57b16771c84ffc2abbdfbc966f6 (patch) | |
| tree | 2b28abbe2e73dd3083f3720649fc9a11e2f2b2aa | |
| parent | 9decd35436f4e14234ab83ad2ffac2306a35724f (diff) | |
| download | btpd-cd1164ef0227c57b16771c84ffc2abbdfbc966f6.tar.gz btpd-cd1164ef0227c57b16771c84ffc2abbdfbc966f6.zip | |
Be careful not to stop the sub struct if they haven't been started. Also
be careful so that we don't operate on a dead torrent.
| -rw-r--r-- | btpd/torrent.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/btpd/torrent.c b/btpd/torrent.c index 4d40c3d..db4f7dc 100644 --- a/btpd/torrent.c +++ b/btpd/torrent.c @@ -145,29 +145,12 @@ torrent_start(const uint8_t *hash) return error; } -void -torrent_stop(struct torrent *tp) -{ - switch (tp->state) { - case T_STARTING: - case T_ACTIVE: - tp->state = T_STOPPING; - tr_stop(tp); - net_stop(tp); - cm_stop(tp); - break; - case T_STOPPING: - if (tr_active(tp)) - tr_stop(tp); - break; - } -} - static void torrent_kill(struct torrent *tp) { btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", torrent_name(tp)); assert(m_ntorrents > 0); + assert(!(tr_active(tp) || net_active(tp) || cm_active(tp))); m_ntorrents--; BTPDQ_REMOVE(&m_torrents, tp, entry); clear_metainfo(&tp->meta); @@ -180,6 +163,32 @@ torrent_kill(struct torrent *tp) } void +torrent_stop(struct torrent *tp) +{ + int tra, cma; + switch (tp->state) { + case T_STARTING: + case T_ACTIVE: + tp->state = T_STOPPING; + if (net_active(tp)) + net_stop(tp); + tra = tr_active(tp); + cma = cm_active(tp); + if (tra) + tr_stop(tp); + if (cma) + cm_stop(tp); + if (!(tra || cma)) + torrent_kill(tp); + break; + case T_STOPPING: + if (tr_active(tp)) + tr_stop(tp); + break; + } +} + +void torrent_on_cm_started(struct torrent *tp) { tp->state = T_ACTIVE; |