Skip to content

Commit

Permalink
Implement .native-descriptor for async sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiepi committed Oct 19, 2018
1 parent a1a95e0 commit 865b1f3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/core/IO/Socket/Async.pm6
Expand Up @@ -122,7 +122,7 @@ my class IO::Socket::Async {
nqp::decont($!buf), SocketCancellation);
$tap := Tap.new({ nqp::cancel($cancellation) });
tap($tap);
};
}

$!close-promise.then: {
$lock.protect: {
Expand Down Expand Up @@ -195,8 +195,8 @@ my class IO::Socket::Async {
if err {
$v.break: err;
} else {
my \client = nqp::create(self);
my $encoding = Encoding::Registry.find($enc);
my \client = nqp::create(self);
my $encoding = Encoding::Registry.find($enc);
nqp::bindattr(client, IO::Socket::Async, '$!VMIO', client-socket);
nqp::bindattr(client, IO::Socket::Async, '$!enc', $encoding.name);
nqp::bindattr(client, IO::Socket::Async, '$!encoder', $encoding.encoder());
Expand All @@ -219,9 +219,13 @@ my class IO::Socket::Async {

submethod BUILD(Mu :$!VMIO, Promise :$!socket-host, Promise :$!socket-port) { }

method new(&on-close, Mu :$VMIO, Promise :$socket-host, Promise :$socket-port) {
method new(&on-close!, Mu :$VMIO!, Promise :$socket-host!, Promise :$socket-port!) {
self.bless: :&on-close, :$VMIO, :$socket-host, :$socket-port;
}

method native-descriptor(--> Int) {
nqp::filenofh(nqp::decont($!VMIO))
}
}

my class SocketListenerTappable does Tappable {
Expand Down Expand Up @@ -298,9 +302,8 @@ my class IO::Socket::Async {

CATCH {
default {
$tap = ListenSocket.new({ Nil }, :$VMIO,
tap($tap = ListenSocket.new: { Nil }, :$VMIO,
:$socket-host, :$socket-port) unless $tap;
tap($tap);
quit($_);
}
}
Expand All @@ -327,6 +330,10 @@ my class IO::Socket::Async {
nqp::bindattr(socket, IO::Socket::Async, '$!close-vow', $p.vow);
}

method native-descriptor(--> Int) {
nqp::filenofh(nqp::decont($!VMIO))
}

#?if moar
method udp(IO::Socket::Async:U: :$broadcast, :$enc = 'utf-8', :$scheduler = $*SCHEDULER) {
my $p = Promise.new;
Expand Down

0 comments on commit 865b1f3

Please sign in to comment.