libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit 75028910f9e794ced6d97bb31f977a808e0b72e1
parent ce235dc3c86e16ce041a209277ebfa9cc50848d2
Author: z3bra <contactatz3bradotorg>
Date:   Fri Jul  6 08:22:43 +0200

Add glch_piececount() to the API

Diffstat:
libeech.c | 11+++++++++++
libeech.h | 1+
torrent.c | 6+++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/libeech.c b/libeech.c @@ -987,3 +987,14 @@ glch_leech(struct torrent *t, int timeout) { return netloop(t, timeout); } + +/* Return the number of currently downloaded pieces */ +long +glch_piececount(struct torrent *t) +{ + long i, n; + for (i = n = 0; i < t->npiece; i++) + n += bit(t->bf, i); + + return n; +} diff --git a/libeech.h b/libeech.h @@ -66,3 +66,4 @@ struct torrent { int glch_loadtorrent(struct torrent *, char *, size_t); int glch_addpeer(struct torrent *, struct peer *, char *, int); int glch_leech(struct torrent *, int); +long glch_piececount(struct torrent *); diff --git a/torrent.c b/torrent.c @@ -83,8 +83,12 @@ main(int argc, char *argv[]) printf("\t%s\n", t.files[i].path); glch_addpeer(&t, &peer, h, p); - for (;;) + while (glch_piececount(&t) < t.npiece) { glch_leech(&t, 5000); + printf("\rDownload: %2d%%", (100 * glch_piececount(&t)) / t.npiece); + fflush(stdout); + } + puts("\rDownload finished!"); return 0; }