in torrent_stop rather than torrent_kill. The data doesn't change but there may be some time between the two events.master
@@ -25,7 +25,7 @@ grace_cb(int fd, short type, void *arg) | |||||
{ | { | ||||
struct torrent *tp; | struct torrent *tp; | ||||
BTPDQ_FOREACH(tp, torrent_get_all(), entry) | BTPDQ_FOREACH(tp, torrent_get_all(), entry) | ||||
torrent_stop(tp); | |||||
torrent_stop(tp, 0); | |||||
} | } | ||||
void | void | ||||
@@ -38,7 +38,7 @@ btpd_shutdown(int grace_seconds) | |||||
m_shutdown = 1; | m_shutdown = 1; | ||||
BTPDQ_FOREACH(tp, torrent_get_all(), entry) | BTPDQ_FOREACH(tp, torrent_get_all(), entry) | ||||
if (tp->state != T_STOPPING) | if (tp->state != T_STOPPING) | ||||
torrent_stop(tp); | |||||
torrent_stop(tp, 0); | |||||
if (grace_seconds >= 0) { | if (grace_seconds >= 0) { | ||||
if (event_once(-1, EV_TIMEOUT, grace_cb, NULL, | if (event_once(-1, EV_TIMEOUT, grace_cb, NULL, | ||||
(& (struct timeval) { grace_seconds, 0 })) != 0) | (& (struct timeval) { grace_seconds, 0 })) != 0) | ||||
@@ -286,10 +286,9 @@ cmd_del(struct cli *cli, int argc, const char *args) | |||||
ret = write_code_buffer(cli, IPC_ENOTENT); | ret = write_code_buffer(cli, IPC_ENOTENT); | ||||
else { | else { | ||||
ret = write_code_buffer(cli, IPC_OK); | 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); | 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. | // Stopping a torrent may trigger exit so we need to reply before. | ||||
int ret = write_code_buffer(cli, IPC_OK); | int ret = write_code_buffer(cli, IPC_OK); | ||||
active_del(tl->hash); | active_del(tl->hash); | ||||
torrent_stop(tl->tp); | |||||
torrent_stop(tl->tp, 0); | |||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
@@ -358,7 +357,7 @@ cmd_stop_all(struct cli *cli, int argc, const char *args) | |||||
active_clear(); | active_clear(); | ||||
BTPDQ_FOREACH(tp, torrent_get_all(), entry) | BTPDQ_FOREACH(tp, torrent_get_all(), entry) | ||||
if (tp->state != T_STOPPING) | if (tp->state != T_STOPPING) | ||||
torrent_stop(tp); | |||||
torrent_stop(tp, 0); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -130,8 +130,6 @@ torrent_kill(struct torrent *tp) | |||||
assert(!(tr_active(tp) || net_active(tp) || cm_active(tp))); | 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); | ||||
if (!tp->delete) | |||||
tlib_update_info(tp->tl); | |||||
tp->tl->tp = NULL; | tp->tl->tp = NULL; | ||||
if (tp->delete) | if (tp->delete) | ||||
tlib_del(tp->tl); | tlib_del(tp->tl); | ||||
@@ -143,8 +141,10 @@ torrent_kill(struct torrent *tp) | |||||
} | } | ||||
void | void | ||||
torrent_stop(struct torrent *tp) | |||||
torrent_stop(struct torrent *tp, int delete) | |||||
{ | { | ||||
if (delete) | |||||
tp->delete = 1; | |||||
switch (tp->state) { | switch (tp->state) { | ||||
case T_LEECH: | case T_LEECH: | ||||
case T_SEED: | case T_SEED: | ||||
@@ -156,6 +156,8 @@ torrent_stop(struct torrent *tp) | |||||
tr_stop(tp); | tr_stop(tp); | ||||
if (cm_active(tp)) | if (cm_active(tp)) | ||||
cm_stop(tp); | cm_stop(tp); | ||||
if (!delete) | |||||
tlib_update_info(tp->tl); | |||||
break; | break; | ||||
case T_STOPPING: | case T_STOPPING: | ||||
if (tr_active(tp)) | if (tr_active(tp)) | ||||
@@ -168,7 +170,7 @@ void | |||||
torrent_on_tick(struct torrent *tp) | torrent_on_tick(struct torrent *tp) | ||||
{ | { | ||||
if (tp->state != T_STOPPING && cm_error(tp)) | if (tp->state != T_STOPPING && cm_error(tp)) | ||||
torrent_stop(tp); | |||||
torrent_stop(tp, 0); | |||||
switch (tp->state) { | switch (tp->state) { | ||||
case T_STARTING: | case T_STARTING: | ||||
if (cm_started(tp)) { | if (cm_started(tp)) { | ||||
@@ -39,7 +39,7 @@ struct torrent *torrent_by_num(unsigned num); | |||||
struct torrent *torrent_by_hash(const uint8_t *hash); | struct torrent *torrent_by_hash(const uint8_t *hash); | ||||
enum ipc_err torrent_start(struct tlib *tl); | 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); | off_t torrent_piece_size(struct torrent *tp, uint32_t piece); | ||||
uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece); | uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece); | ||||