in reply to Kill a child nicely
Here's another suggestion - no fork, no signals.
Works on my Linux system - I don't have a Windows system to test on...
#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11154445 use warnings; use IO::Socket; use IO::Select; my $port = shift // 3333; # FIXME my $listen = IO::Socket::INET->new( LocalPort => $port, Listen => 100, ReusePort => 1,) or die $&; my $sel = IO::Select->new( $listen, *STDIN ); print "Hit <ENTER> to quit\n"; for( my $more = 1; $more; ) { for my $handle ( $sel->can_read ) { if( $handle eq *STDIN ) { $more = 0; print "operator wants me to go away\n"; } else { my $live_socket = $listen->accept; while( <$live_socket> ) { # process stuff here print "GOT: $_"; /^\r?\n\z/ and shutdown $live_socket, 1; # NOTE because testin +g with GET } close $live_socket; } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Kill a child nicely
by afoken (Chancellor) on Sep 16, 2023 at 22:11 UTC |