summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-04-20 22:47:39 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-04-20 22:47:39 +0200
commitc04297587cb045b010f6c2f642b1079d336ff27b (patch)
treeb69848de40d4d49930a1d17642890b3c292a44d1 /sys
parentc31c4ca7b37ae113e9df810f03157c2fe7bb2708 (diff)
ip/torrent: use NPROC processes in parallel for calculating initial piece hashes
Diffstat (limited to 'sys')
-rw-r--r--sys/src/cmd/ip/torrent.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/sys/src/cmd/ip/torrent.c b/sys/src/cmd/ip/torrent.c
index 7526b8428..a8b6f8c40 100644
--- a/sys/src/cmd/ip/torrent.c
+++ b/sys/src/cmd/ip/torrent.c
@@ -49,6 +49,7 @@ enum {
};
int debug;
+int nproc = 1;
int killgroup = -1;
int port = 6881;
char *deftrack = "http://exodus.desync.com/announce";
@@ -1197,6 +1198,12 @@ main(int argc, char *argv[])
usage();
} ARGEND;
+ if((s = getenv("NPROC")) != 0){
+ if((nproc = atoi(s)) <= 0)
+ nproc = 1;
+ free(s);
+ }
+
fd = 0;
if(*argv)
if((fd = open(*argv, OREAD)) < 0)
@@ -1301,8 +1308,18 @@ main(int argc, char *argv[])
if(len)
sysfatal("pieces do not match file length");
- for(i = 0; i<npieces; i++)
- havepiece(i);
+ for(i=0; i<nproc; i++){
+ switch(rfork(RFPROC|RFMEM)){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ for(; i<npieces; i+=nproc)
+ havepiece(i);
+ exits(0);
+ }
+ }
+ while(waitpid() >= 0)
+ ;
srand(time(0));
atnotify(catch, 1);