浏览代码

Set torrent deletion flag as parameter to torrent_stop. Update torrent info

in torrent_stop rather than torrent_kill. The data doesn't change but there
may be some time between the two events.
master
Richard Nyberg 17 年前
父节点
当前提交
3c59bb01e2
共有 4 个文件被更改,包括 14 次插入13 次删除
  1. +2
    -2
      btpd/btpd.c
  2. +5
    -6
      btpd/cli_if.c
  3. +6
    -4
      btpd/torrent.c
  4. +1
    -1
      btpd/torrent.h

+ 2
- 2
btpd/btpd.c 查看文件

@@ -25,7 +25,7 @@ grace_cb(int fd, short type, void *arg)
{
struct torrent *tp;
BTPDQ_FOREACH(tp, torrent_get_all(), entry)
torrent_stop(tp);
torrent_stop(tp, 0);
}

void
@@ -38,7 +38,7 @@ btpd_shutdown(int grace_seconds)
m_shutdown = 1;
BTPDQ_FOREACH(tp, torrent_get_all(), entry)
if (tp->state != T_STOPPING)
torrent_stop(tp);
torrent_stop(tp, 0);
if (grace_seconds >= 0) {
if (event_once(-1, EV_TIMEOUT, grace_cb, NULL,
(& (struct timeval) { grace_seconds, 0 })) != 0)


+ 5
- 6
btpd/cli_if.c 查看文件

@@ -286,10 +286,9 @@ cmd_del(struct cli *cli, int argc, const char *args)
ret = write_code_buffer(cli, IPC_ENOTENT);
else {
ret = write_code_buffer(cli, IPC_OK);
if (tl->tp != NULL) {
tl->tp->delete = 1;
torrent_stop(tl->tp);
} else
if (tl->tp != NULL)
torrent_stop(tl->tp, 1);
else
tlib_del(tl);
}

@@ -345,7 +344,7 @@ cmd_stop(struct cli *cli, int argc, const char *args)
// Stopping a torrent may trigger exit so we need to reply before.
int ret = write_code_buffer(cli, IPC_OK);
active_del(tl->hash);
torrent_stop(tl->tp);
torrent_stop(tl->tp, 0);
return ret;
}
}
@@ -358,7 +357,7 @@ cmd_stop_all(struct cli *cli, int argc, const char *args)
active_clear();
BTPDQ_FOREACH(tp, torrent_get_all(), entry)
if (tp->state != T_STOPPING)
torrent_stop(tp);
torrent_stop(tp, 0);
return ret;
}



+ 6
- 4
btpd/torrent.c 查看文件

@@ -130,8 +130,6 @@ torrent_kill(struct torrent *tp)
assert(!(tr_active(tp) || net_active(tp) || cm_active(tp)));
m_ntorrents--;
BTPDQ_REMOVE(&m_torrents, tp, entry);
if (!tp->delete)
tlib_update_info(tp->tl);
tp->tl->tp = NULL;
if (tp->delete)
tlib_del(tp->tl);
@@ -143,8 +141,10 @@ torrent_kill(struct torrent *tp)
}

void
torrent_stop(struct torrent *tp)
torrent_stop(struct torrent *tp, int delete)
{
if (delete)
tp->delete = 1;
switch (tp->state) {
case T_LEECH:
case T_SEED:
@@ -156,6 +156,8 @@ torrent_stop(struct torrent *tp)
tr_stop(tp);
if (cm_active(tp))
cm_stop(tp);
if (!delete)
tlib_update_info(tp->tl);
break;
case T_STOPPING:
if (tr_active(tp))
@@ -168,7 +170,7 @@ void
torrent_on_tick(struct torrent *tp)
{
if (tp->state != T_STOPPING && cm_error(tp))
torrent_stop(tp);
torrent_stop(tp, 0);
switch (tp->state) {
case T_STARTING:
if (cm_started(tp)) {


+ 1
- 1
btpd/torrent.h 查看文件

@@ -39,7 +39,7 @@ struct torrent *torrent_by_num(unsigned num);
struct torrent *torrent_by_hash(const uint8_t *hash);

enum ipc_err torrent_start(struct tlib *tl);
void torrent_stop(struct torrent *tp);
void torrent_stop(struct torrent *tp, int delete);

off_t torrent_piece_size(struct torrent *tp, uint32_t piece);
uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece);


正在加载...
取消
保存