Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement start all (btcli start -a) functionality.

Closes GH-7
  • Loading branch information...
commit fd18baa9e62f6defd4a285425bd087a4b27c82d3 1 parent b1d891c
@queueRAM queueRAM authored
Showing with 59 additions and 7 deletions.
  1. +26 −0 btpd/cli_if.c
  2. +24 −7 cli/start.c
  3. +8 −0 misc/btpd_if.c
  4. +1 −0  misc/btpd_if.h
View
26 btpd/cli_if.c
@@ -324,6 +324,30 @@ cmd_start(struct cli *cli, int argc, const char *args)
}
static int
+cmd_start_all(struct cli *cli, int argc, const char *args)
+{
+ struct htbl_iter it;
+ struct tlib *tl;
+ enum ipc_err last_code, ret_code= IPC_OK;
+
+ if (btpd_is_stopping())
+ return write_code_buffer(cli, IPC_ESHUTDOWN);
+
+ for (tl = tlib_iter_first(&it); tl != NULL; tl = tlib_iter_next(&it)) {
+ if (torrent_startable(tl)) {
+ if ((last_code = torrent_start(tl)) == IPC_OK) {
+ active_add(tl->hash);
+ } else {
+ btpd_err("torrent_start(%d) failed.\n", tl->num);
+ ret_code = last_code;
+ }
+ }
+ }
+
+ return write_code_buffer(cli, ret_code);
+}
+
+static int
cmd_stop(struct cli *cli, int argc, const char *args)
{
if (argc != 1)
@@ -355,6 +379,7 @@ cmd_stop_all(struct cli *cli, int argc, const char *args)
{
struct torrent *tp, *next;
int ret = write_code_buffer(cli, IPC_OK);
+
active_clear();
BTPDQ_FOREACH_MUTABLE(tp, torrent_get_all(), entry, next)
torrent_stop(tp, 0);
@@ -381,6 +406,7 @@ static struct {
{ "del", 3, cmd_del },
{ "die", 3, cmd_die },
{ "start", 5, cmd_start },
+ { "start-all", 9, cmd_start_all},
{ "stop", 4, cmd_stop },
{ "stop-all", 8, cmd_stop_all},
{ "tget", 4, cmd_tget }
View
31 cli/start.c
@@ -12,6 +12,10 @@ usage_start(void)
"torrent ...\n"
"\tThe torrents to activate.\n"
"\n"
+ "Options:\n"
+ "-a\n"
+ "\tActivate all inactive torrents.\n"
+ "\n"
);
exit(1);
}
@@ -24,19 +28,32 @@ static struct option start_opts [] = {
void
cmd_start(int argc, char **argv)
{
- int ch;
+ int ch, all = 0;
struct ipc_torrent t;
- while ((ch = getopt_long(argc, argv, "", start_opts, NULL)) != -1)
- usage_start();
+ while ((ch = getopt_long(argc, argv, "a", start_opts, NULL)) != -1) {
+ switch (ch) {
+ case 'a':
+ all = 1;
+ break;
+ default:
+ usage_start();
+ }
+ }
argc -= optind;
argv += optind;
- if (argc < 1)
+ if ((argc == 0 && !all) || (all && argc != 0))
usage_start();
btpd_connect();
- for (int i = 0; i < argc; i++)
- if (torrent_spec(argv[i], &t))
- handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]);
+ if (all) {
+ enum ipc_err code = btpd_start_all(ipc);
+ if (code != IPC_OK)
+ diemsg("command failed (%s).\n", ipc_strerror(code));
+ } else {
+ for (int i = 0; i < argc; i++)
+ if (torrent_spec(argv[i], &t))
+ handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]);
+ }
}
View
8 misc/btpd_if.c
@@ -303,6 +303,14 @@ btpd_start(struct ipc *ipc, struct ipc_torrent *tp)
}
enum ipc_err
+btpd_start_all(struct ipc *ipc)
+{
+ struct iobuf iob = iobuf_init(16);
+ iobuf_swrite(&iob, "l9:start-alle");
+ return ipc_buf_req_code(ipc, &iob);
+}
+
+enum ipc_err
btpd_stop(struct ipc *ipc, struct ipc_torrent *tp)
{
return simple_treq(ipc, "stop", tp);
View
1  misc/btpd_if.h
@@ -78,6 +78,7 @@ enum ipc_err btpd_add(struct ipc *ipc, const char *mi, size_t mi_size,
const char *content, const char *name);
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_start_all(struct ipc *ipc);
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);
Please sign in to comment.
Something went wrong with that request. Please try again.