Skip to content

Commit

Permalink
remove a layer of indirection, and lots of code related to it
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Oct 19, 2011
1 parent dfbf14d commit a8b3772
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions lib/IO/Select.pm
Expand Up @@ -2,15 +2,12 @@ pir::loadlib__Ps('select');


class IO::Select { class IO::Select {
has $!pmc; has $!pmc;
has $!iter = 'FH1';
has %!handles;


submethod BUILD { submethod BUILD {
$!pmc := pir::new__Ps('Select'); $!pmc := pir::new__Ps('Select');
} }


method add($handle) { method add($handle) {
%!handles{$!iter} = $handle;
my Mu $fh := nqp::getattr( my Mu $fh := nqp::getattr(
pir::perl6_decontainerize__PP($handle), $handle.WHAT, '$!PIO' pir::perl6_decontainerize__PP($handle), $handle.WHAT, '$!PIO'
); );
Expand All @@ -24,30 +21,14 @@ class IO::Select {
# XXX No idea how to obtain an actual fd or any other unique # XXX No idea how to obtain an actual fd or any other unique
# identifier, so I'll just assign consequent letters of alphabet # identifier, so I'll just assign consequent letters of alphabet
# to each one # to each one
$!pmc.update($fh, nqp::unbox_s($!iter), nqp::unbox_i($mode)); $!pmc.update($fh, $handle, nqp::unbox_i($mode));
$!iter.=succ;
} }


method can_read($timeout as Num) { method can_read($timeout as Num) {
my @parcel := $!pmc.can_read(nqp::unbox_n($timeout)); $!pmc.can_read(nqp::unbox_n($timeout));
return self.get_handles(@parcel);
} }


method can_write($timeout as Num) { method can_write($timeout as Num) {
my @parcel := $!pmc.can_write(nqp::unbox_n($timeout)); $!pmc.can_write(nqp::unbox_n($timeout));
return self.get_handles(@parcel);
}

method get_handles(@parcel) {
my Mu $ids := nqp::getattr(
@parcel, Parcel, '$!storage'
);
my int $elems = pir::elements($ids);
my @res;
loop (my int $i = 0; $i < $elems; $i = $i + 1) {
my Str $item := nqp::p6box_s(nqp::atpos($ids, $i));
@res.push: %!handles{$item};
}
return @res;
} }
} }

0 comments on commit a8b3772

Please sign in to comment.