- Timestamp:
- 2008-10-15T17:45:08+13:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/downloaders/WgetDownload.pm
r17537 r17547 100 100 close($chld_in); 101 101 102 #print STDOUT "Received termination signal: $termination_signal\n";102 print STDOUT "Received termination signal: $termination_signal\n"; 103 103 104 104 # Send TERM signal to child process to terminate it. Sending the INT signal doesn't work … … 240 240 } 241 241 else { # wget finished, terminate naturally 242 #print STD ERR"\nPerl: open2 command, input stream closed. Wget terminated naturally.\n";242 #print STDOUT "\nPerl: open2 command, input stream closed. Wget terminated naturally.\n"; 243 243 close($chld_in); 244 244 close($chld_out); … … 269 269 print $client "Talked to ServerSocket (port $port). Connection accepted\n"; 270 270 271 # Read from the client (getting rid of t railing newline)271 # Read from the client (getting rid of the trailing newline) 272 272 # Has the client sent the <<STOP>> signal? 273 273 my $signal = <$client>; … … 275 275 if($signal eq "<<STOP>>") { 276 276 print $client "Perl received STOP signal (on port $port): stopping wget\n"; 277 $loop = 0; 277 278 278 $loop = 0; 279 close($chld_in); 280 close($chld_out); 281 kill("TERM", $childpid); 282 283 $childpid = undef; 284 285 # Stop monitoring the read_handle 286 # close the serverSocket (the Java end will close the client socket that Java opened) 287 $read_set->remove($rh); #$read_set->remove($serverSocket); 288 close($rh); #close($serverSocket); 289 #print $client "Perl is about to exit\n"; 290 last; 279 # Sometimes the wget process takes some time to start up. If the STOP signal 280 # was sent, don't try to terminate the process until we know it is running. 281 # Otherwise wget may start running after we tried to kill it. Wait 5 seconds 282 # for it to start up, checking for whether it is running in order to kill it. 283 for(my $seconds = 1; $seconds <= 5; $seconds++) { 284 if(kill(0, $childpid)) { 285 # If kill(0, $childpid) returns true, then the process is running 286 # and we need to kill it. 287 close($chld_in); 288 close($chld_out); 289 kill("TERM", $childpid); 290 291 $childpid = undef; 292 293 # Stop monitoring the read_handle and close the serverSocket 294 # (the Java end will close the client socket that Java opened) 295 $read_set->remove($rh); #$read_set->remove($serverSocket); 296 close($rh); #close($serverSocket); 297 print $client "Perl terminated wget and is about to exit\n"; 298 } 299 else { # the process may just be starting up, wait 300 sleep(1); 301 } 302 } 303 last; # we're done here 291 304 } 292 305 } … … 410 423 if($signal eq "<<STOP>>") { 411 424 print $client "Perl received STOP signal (on port $port): stopping wget\n"; 425 $loop = 0; 412 426 413 $loop = 0; 414 close($chld_in); 415 close($chld_out); 416 kill("TERM", $childpid); 417 418 $childpid = undef; 419 420 # Stop monitoring the read_handle 421 # close the serverSocket (the Java end will close the client socket that Java opened) 422 $read_set->remove($rh); #$read_set->remove($serverSocket); 423 close($rh); #close($serverSocket); 424 #print $client "Perl is about to exit\n"; 425 last; 427 # Sometimes the wget process takes some time to start up. If the STOP signal 428 # was sent, don't try to terminate the process until we know it is running. 429 # Otherwise wget may start running after we tried to kill it. Wait 5 seconds 430 # for it to start up, checking for whether it is running in order to kill it. 431 for(my $seconds = 1; $seconds <= 5; $seconds++) { 432 if(kill(0, $childpid)) { 433 # If kill(0, $childpid) returns true, then the process is running 434 # and we need to kill it. 435 close($chld_in); 436 close($chld_out); 437 kill("TERM", $childpid); 438 439 $childpid = undef; 440 441 # Stop monitoring the read_handle and close the serverSocket 442 # (the Java end will close the client socket that Java opened) 443 $read_set->remove($rh); #$read_set->remove($serverSocket); 444 close($rh); #close($serverSocket); 445 print $client "Perl terminated wget and is about to exit\n"; 446 } 447 else { # the process may just be starting up, wait 448 sleep(1); 449 } 450 } 451 last; # we're done here 426 452 } 427 453 }
Note:
See TracChangeset
for help on using the changeset viewer.