Created
May 30, 2014 21:45
-
-
Save tony-o/b11e87e582d56b1a1979 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env perl6 | |
class REST::Server { | |
has $.host = '127.0.0.1'; | |
has $.port = 8080; | |
has %.options is rw; | |
has $.debug = 1; | |
has Supply $!scheduler; | |
method listen() { | |
$!scheduler = IO::Socket::Async.listen( | |
$.host, | |
$.port, | |
); | |
my $num = 0; | |
$!scheduler.tap(sub ($connection) { | |
my $snum = $num++; | |
"accepted connection $snum".say if $.debug; | |
$connection.send("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 6\r\n\r\nstring"); | |
"closing connection $snum".say if $.debug; | |
$connection.close; | |
}); | |
sleep 50; | |
} | |
}; | |
my $s = REST::Server.new; | |
$s.listen; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment