I've changed the code to this, It's better but still not correct.

1) curl with http hangs and must be terminated with Ctrl+C

2) the code now restarts the server socket, which I also dont expect to happen.


use v6;
use IO::Socket::Async::SSL;

sub auto-restart(Supply $incoming) {
    supply {
        sub run() {
            whenever $incoming {
                QUIT {
                    default {
                        say "quit inside auto-restart";
                        .note;
                        run();
                    }
                }
            }
        }
        run();
    }
}

my %ssl-config =
        certificate-file => 'cert.pem',
        private-key-file => 'key.pem';

my $listener = IO::Socket::Async::SSL.listen('localhost', 4433, |%ssl-config );
my $supply   = supply {
    whenever $listener -> $conn {
        handle($conn);
    }
}

sub handle($conn) {
    my $req = '';

    # QUIT { say "this is quit inside whenever"}
    whenever $conn {
        $req ~= $_;
        if $req.contains("\r\n\r\n") {
            say $req.lines[0];
            try await $conn.print(
                "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n" ~
                "<strong>Hello from a Perl 6 HTTP server</strong>\n");
            $conn.close;
        }
    }
};


auto-restart($supply).tap: -> {};
react {
    whenever signal(SIGINT) { done };
}


Am 16.10.2017 um 12:54 schrieb Timo Paulssen:
It took me a while, but I just found jnthn's automatic retry code for
supply-based things again.

It's in these slides
http://jnthn.net/papers/2017-perl6-concurrency-pcp.pdf on page 83

You'll want to use "supply" instead of "react" for your server and pass
that to the auto-retry function.

Reply via email to