All pastes #132782 Raw Edit

Something

public text v1 · immutable
#132782 ·published 2006-08-15 13:16 UTC
rendered paste body
#!/usr/bin/perl -w

use Net::SSLeay;
use Socket;
use IO::Socket;
use IO::Socket::INET;
use IO::Socket::SSL qw(debug4);
use English;
use POSIX ":sys_wait_h";

my $server = new IO::Socket::SSL(
                                        LocalPort => '2345',
                                        Proto => 'tcp',
                                        Listen => SOMAXCONN,
                                        Reuse => 1,
                                        SSL_key_file => '/etc/ssl/my.key',
                                        SSL_cert_file => '/etc/ssl/my.pem',
                                 );

die "Could not create socket: $ERRNO \n" unless $server;

sub REAPER {
        my $child;
        while (($child = waitpid(-1, WNOHANG)) > 0) {  }
        $SIG{CHLD} = \&REAPER;
}

$SIG{CHLD} = \&REAPER;

while (my $client = $server -> accept())
{
        my $kidpid = fork();
        die('Can\'t fork: ' . $ERRNO) unless defined($kidpid);

        if (!$kidpid)
        {
                $server->close();
                $client->autoflush(1);
                my $command = <$client>;
                
                # all the stuff that makes the client happy
                
                $client->close(SSL_no_shutdown =>1);
                exit(0);
        }
        else
        {
                $client->close(SSL_no_shutdown => 1);
        }
}