Commits

Palmer, 2E0EOL committed 1b109a1 Draft Merge

Experimental merge of forking code.

Comments (0)

Files changed (2)

 	return $uri_parts[-1];
 }
 
-sub ReadFeed($$$)
+sub ReadFeed($$)
 {
 	my @entries = ( );
-	my ( $Feeds, $Url, $Name ) = @_;
+	my ( $Feeds, $Feed ) = @_;
+	my ( $Url, $Name ) = ( $Feed->{rss}, $Feed->{name} );
 	my $feed = XML::Feed->parse(URI->new($Url));
 	if ( !$feed ) {
 		printf(STDERR "Stream %s error: %s\n", $Name, $@);
 	return $V;
 }
 
+sub Child($$)
+{
+	my ( $Feeds, $Feed ) = @_;
+	my @entries = ReadFeed($Feeds, $Feed);
+	foreach my $entry ( @entries ) {
+		print STDERR 'Processing entry: ' . Dumper $entry if ( $Debug );
+		DownloadStream($Feeds, $entry, $Feed->{name});
+	}
+}
+
 sub main()
 {
 	my $conf;
 	my @defKeys;
 	my %feeds = ( );
 	my %opts = ( );
+	my @pids;
 	my $confSeen = 0;
 	my @confFiles = (
 		'dlpodget.rc',
 		my $feed = $feeds{$feedName};
 		next if ( !$feed->{enable} );
 		next if ( !$feed->{download} );
-		@entries = ReadFeed(\%feeds, $feed->{rss}, $feedName);
-		foreach my $entry ( @entries ) {
-			print STDERR 'Processing entry: ' . Dumper $entry if ( $Debug );
-			DownloadStream(\%feeds, $entry, $feedName);
+		$feed->{name} = $feedName;
+		if ( scalar(@pids) < $feeds{_main}->{MAXCHILDREN} ) {
+			my $pid = fork();
+			die "cannot fork: $!" if ( !defined($pid) );
+			if ( $pid == 0 ) { # Child process
+				Child(\%feeds, $feed);
+				exit(0); # Children should not return
+			} else {
+				push(@pids, $pid);
+			}
+		} else {
+			warn "Not enough children";
+			Child(\%feeds, $feed);
 		}
 	}
 
 enable    = 1
 noop      = 0
 debug     = 0
+maxchildren  = 5
 
 [paths]
 root      = $HOME/podcasts
 localpath = $POLITICS/infowars
 rss       = http://xml.nfowars.net/Alex.rss
 check     = 1
-download  = 1
+download  = 0
 enable    = 1
 
 [bsec]