瀏覽代碼

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.
master
Richard Nyberg 19 年之前
父節點
當前提交
cd1164ef02
共有 1 個檔案被更改,包括 27 行新增18 行删除
  1. +27
    -18
      btpd/torrent.c

+ 27
- 18
btpd/torrent.c 查看文件

@@ -145,29 +145,12 @@ torrent_start(const uint8_t *hash)
return error; 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 static void
torrent_kill(struct torrent *tp) torrent_kill(struct torrent *tp)
{ {
btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", torrent_name(tp)); btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", torrent_name(tp));
assert(m_ntorrents > 0); assert(m_ntorrents > 0);
assert(!(tr_active(tp) || net_active(tp) || cm_active(tp)));
m_ntorrents--; m_ntorrents--;
BTPDQ_REMOVE(&m_torrents, tp, entry); BTPDQ_REMOVE(&m_torrents, tp, entry);
clear_metainfo(&tp->meta); clear_metainfo(&tp->meta);
@@ -179,6 +162,32 @@ torrent_kill(struct torrent *tp)
btpd_on_no_torrents(); btpd_on_no_torrents();
} }


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 void
torrent_on_cm_started(struct torrent *tp) torrent_on_cm_started(struct torrent *tp)
{ {


||||||
x
 
000:0
Loading…
取消
儲存