Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide async server sockets on MoarVM.
  • Loading branch information
jnthn committed Apr 20, 2014
1 parent 25e2ff4 commit c4efc57
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/core/IO/Socket/Async.pm
Expand Up @@ -87,4 +87,23 @@ my class IO::Socket::Async {
$host, $port, SocketCancellation);
$p
}

method listen(IO::Socket::Async:U: $host as Str, $port as Int,
:$scheduler = $*SCHEDULER) {
my $s = Supply.new;
nqp::asynclisten(
$scheduler.queue,
-> Mu \socket, Mu \err {
if err {
$s.quit(err);
}
else {
my $client_socket := nqp::create(self);
nqp::bindattr($client_socket, IO::Socket::Async, '$!VMIO', socket);
$s.more($client_socket);
}
},
$host, $port, SocketCancellation);
$s
}
}

0 comments on commit c4efc57

Please sign in to comment.