Skip to content

Instantly share code, notes, and snippets.

@ryanerwin
Created September 29, 2017 08:44
Show Gist options
  • Save ryanerwin/0fc42aa60ff363cfd34545fe6ae85b24 to your computer and use it in GitHub Desktop.
Save ryanerwin/0fc42aa60ff363cfd34545fe6ae85b24 to your computer and use it in GitHub Desktop.
P6-React-Async-Listen
unit class SMTPd;
use IO::Socket::Async::SSL;
has $.port;
has $.debug;
has $.raw;
has $.socket;
has $.tls;
has $.ssl;
has $.plain;
method new(:$port = 587, :$raw, :$debug, :$ssl, :$starttls, :$plain, :$socket = IO::Socket::Async ) {
say "Port: $port";
if ( $port <= 1024 ) {
die "Sadly, Privileged Port $port Requires Root" unless $*USER.Numeric == 0;
}
react {
whenever IO::Socket::Async.listen('0.0.0.0', '2525' ) -> $conn {
whenever $coonn {
whenever $conn.print: "OK\r\n" { $conn.close; }
}
}
}
}
use v6;
use Test;
plan 1;
use SMTPd;
my $port = 2525;
ok True, "module loaded";
my $smtpd = SMTPd.new(:$port, :debug(1) );
# since the constructor contains react { listen {...
# execution never returns here...
# i never see "object initialized...
ok True, "object initialized";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment