All pastes #142108 Raw Edit

Unnamed

public text v1 · immutable
#142108 ·published 2006-08-21 08:25 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";

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

$SIG{CHLD} = \&REAPER;

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;

for ( ; ; )
{
                my $client = $server->accept();
                die "Could not accept Client: $ERRNO \n" unless $client;
                my $kidpid = fork();
                die('Can\'t fork: ' . $ERRNO) unless defined($kidpid);

                if (!$kidpid)
                {
                     $server->close(SSL_no_shutdown => 1);
                     $client->autoflush(1);
                     # stuff
                     $client->close();
                     exit(0);
                }
                else
                {
                     $client->close();
                }
}