Просмотр исходного кода

Add command to stop all active torrents. The command is sent by

'btcli stop -a'.
master
Richard Nyberg 18 лет назад
Родитель
Сommit
ba9ae40fe7
4 измененных файлов: 57 добавлений и 5 удалений
  1. +14
    -0
      btpd/cli_if.c
  2. +34
    -5
      cli/stop.c
  3. +8
    -0
      misc/btpd_if.c
  4. +1
    -0
      misc/btpd_if.h

+ 14
- 0
btpd/cli_if.c Просмотреть файл

@@ -356,6 +356,19 @@ cmd_stop(struct cli *cli, int argc, const char *args)
}
}

static int
cmd_stop_all(struct cli *cli, int argc, const char *args)
{
struct torrent *tp;
int ret = write_code_buffer(cli, IPC_OK);
active_clear();
BTPDQ_FOREACH(tp, torrent_get_all(), entry)
if (tp->state != T_STOPPING) {
torrent_stop(tp);
}
return ret;
}

static int
cmd_die(struct cli *cli, int argc, const char *args)
{
@@ -380,6 +393,7 @@ static struct {
{ "die", 3, cmd_die },
{ "start", 5, cmd_start },
{ "stop", 4, cmd_stop },
{ "stop-all", 8, cmd_stop_all},
{ "tget", 4, cmd_tget }
};



+ 34
- 5
cli/stop.c Просмотреть файл

@@ -6,22 +6,51 @@ usage_stop(void)
printf(
"Stop torrents.\n"
"\n"
"Usage: stop torrent ...\n"
"Usage: stop -a\n"
" stop torrent ...\n"
"\n"
"Options:\n"
"-a\n"
"\tStop all active torrents.\n"
"\n"
);
exit(1);
}

static struct option stop_opts [] = {
{ "help", no_argument, NULL, 'H' },
{NULL, 0, NULL, 0}
};

void
cmd_stop(int argc, char **argv)
{
int ch, all = 0;
struct ipc_torrent t;

if (argc < 2)
while ((ch = getopt_long(argc, argv, "a", stop_opts, NULL)) != -1) {
switch (ch) {
case 'a':
all = 1;
break;
default:
usage_stop();
}
}
argc -= optind;
argv += optind;

if ((argc == 0 && !all) || (all && argc != 0))
usage_stop();

btpd_connect();
for (int i = 1; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_stop(ipc, &t), "stop", argv[i]);
if (all) {
enum ipc_err code = btpd_stop_all(ipc);
if (code != IPC_OK)
errx(1, "%s", ipc_strerror(code));
} else {
for (int i = 0; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_stop(ipc, &t), "stop", argv[i]);
}
}

+ 8
- 0
misc/btpd_if.c Просмотреть файл

@@ -311,3 +311,11 @@ btpd_stop(struct ipc *ipc, struct ipc_torrent *tp)
{
return simple_treq(ipc, "stop", tp);
}

enum ipc_err
btpd_stop_all(struct ipc *ipc)
{
struct io_buffer iob = buf_init(16);
buf_swrite(&iob, "l8:stop-alle");
return ipc_buf_req_code(ipc, &iob);
}

+ 1
- 0
misc/btpd_if.h Просмотреть файл

@@ -79,6 +79,7 @@ enum ipc_err btpd_add(struct ipc *ipc, const char *mi, size_t mi_size,
enum ipc_err btpd_del(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_start(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_stop(struct ipc *ipc, struct ipc_torrent *tp);
enum ipc_err btpd_stop_all(struct ipc *ipc);
enum ipc_err btpd_die(struct ipc *ipc, int seconds);
enum ipc_err btpd_get(struct ipc *ipc, enum ipc_dval *keys, size_t nkeys,
tget_cb_t cb, void *arg);


Загрузка…
Отмена
Сохранить