Created
September 29, 2017 08:44
-
-
Save ryanerwin/0fc42aa60ff363cfd34545fe6ae85b24 to your computer and use it in GitHub Desktop.
P6-React-Async-Listen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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