ip/torrent: use NPROC processes in parallel for calculating initial piece hashes

This commit is contained in:
cinap_lenrek 2013-04-20 22:47:39 +02:00
parent c31c4ca7b3
commit c04297587c

View file

@ -49,6 +49,7 @@ enum {
}; };
int debug; int debug;
int nproc = 1;
int killgroup = -1; int killgroup = -1;
int port = 6881; int port = 6881;
char *deftrack = "http://exodus.desync.com/announce"; char *deftrack = "http://exodus.desync.com/announce";
@ -1197,6 +1198,12 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if((s = getenv("NPROC")) != 0){
if((nproc = atoi(s)) <= 0)
nproc = 1;
free(s);
}
fd = 0; fd = 0;
if(*argv) if(*argv)
if((fd = open(*argv, OREAD)) < 0) if((fd = open(*argv, OREAD)) < 0)
@ -1301,8 +1308,18 @@ main(int argc, char *argv[])
if(len) if(len)
sysfatal("pieces do not match file length"); sysfatal("pieces do not match file length");
for(i = 0; i<npieces; i++) for(i=0; i<nproc; i++){
havepiece(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)); srand(time(0));
atnotify(catch, 1); atnotify(catch, 1);