瀏覽代碼

Missed this file in the last commit. Simplify some interfaces by polling

for state changes when appropriate instead of being called directly at any
time.
master
Richard Nyberg 19 年之前
父節點
當前提交
ebef96d5f8
共有 1 個檔案被更改,包括 23 行新增26 行删除
  1. +23
    -26
      btpd/torrent.c

+ 23
- 26
btpd/torrent.c 查看文件

@@ -141,7 +141,7 @@ torrent_start(struct tlib *tl)
btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", torrent_name(tp)); btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", torrent_name(tp));
if (tr_create(tp, mi) == 0) { if (tr_create(tp, mi) == 0) {
net_create(tp); net_create(tp);
cm_create(tp); cm_create(tp, mi);
BTPDQ_INSERT_TAIL(&m_torrents, tp, entry); BTPDQ_INSERT_TAIL(&m_torrents, tp, entry);
m_ntorrents++; m_ntorrents++;
cm_start(tp); cm_start(tp);
@@ -174,28 +174,21 @@ torrent_kill(struct torrent *tp)
cm_kill(tp); cm_kill(tp);
mi_free_files(tp->nfiles, tp->files); mi_free_files(tp->nfiles, tp->files);
free(tp); free(tp);
if (m_ntorrents == 0)
btpd_on_no_torrents();
} }


void void
torrent_stop(struct torrent *tp) torrent_stop(struct torrent *tp)
{ {
int tra, cma;
switch (tp->state) { switch (tp->state) {
case T_ACTIVE: case T_ACTIVE:
case T_STARTING: case T_STARTING:
tp->state = T_STOPPING; tp->state = T_STOPPING;
if (net_active(tp)) if (net_active(tp))
net_stop(tp); net_stop(tp);
tra = tr_active(tp); if (tr_active(tp))
cma = cm_active(tp);
if (tra)
tr_stop(tp); tr_stop(tp);
if (cma) if (cm_active(tp))
cm_stop(tp); cm_stop(tp);
if (!(tra || cma))
torrent_kill(tp);
break; break;
case T_STOPPING: case T_STOPPING:
if (tr_active(tp)) if (tr_active(tp))
@@ -205,25 +198,29 @@ torrent_stop(struct torrent *tp)
} }


void void
torrent_on_cm_started(struct torrent *tp) torrent_on_tick(struct torrent *tp)
{
tp->state = T_ACTIVE;
net_start(tp);
tr_start(tp);
}

void
torrent_on_cm_stopped(struct torrent *tp)
{ {
assert(tp->state == T_STOPPING); switch (tp->state) {
if (!tr_active(tp)) case T_STARTING:
torrent_kill(tp); if (cm_started(tp)) {
tp->state = T_ACTIVE;
net_start(tp);
tr_start(tp);
}
break;
case T_STOPPING:
if (!(cm_active(tp) || tr_active(tp)))
torrent_kill(tp);
break;
default:
break;
}
} }


void void
torrent_on_tr_stopped(struct torrent *tp) torrent_on_tick_all(void)
{ {
assert(tp->state == T_STOPPING); struct torrent *tp, *next;
if (!cm_active(tp)) BTPDQ_FOREACH_MUTABLE(tp, &m_torrents, entry, next)
torrent_kill(tp); torrent_on_tick(tp);
} }

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