Skip to content

Loading…

IO Buffering #71

Closed
wants to merge 4 commits into from

4 participants

@ajs

I added two methods for doing buffering of IO handles and turned on line buffering by default on new handles.

@moritz moritz commented on the diff
src/core/IO.pm
@@ -110,6 +111,13 @@ class IO does IO::FileTestable {
Bool::True;
}
+ # XXX - DESTROY is NYI in Rakudo at the time this was written, so
+ # the following has no effect.
+ method DESTROY() {
@moritz Rakudo Perl member
moritz added a note

now implemented in rakudo-moar; but it should be submethod, not a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@labster

Because this PR reaches down into Parrot internals, and Parrot support has been suspended, I'm closing this pull request. If Parrot support returns in the future, this should probably be implemented with nqp op(s).

@labster labster closed this
@ajs

I gave up on this one a long time ago, and am happy to see it closed. Real IO support in Perl6 is going to be a major undertaking, and I don't think that it behooves the language to take it on piecemeal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/core/IO.pm
View
28 src/core/IO.pm
@@ -101,6 +101,7 @@ class IO does IO::FileTestable {
$!path = $path;
$!chomp = $chomp;
$!PIO.encoding($bin ?? 'binary' !! PARROT_ENCODING($encoding));
+ self.buffer_type(:line);
self;
}
@@ -110,6 +111,13 @@ class IO does IO::FileTestable {
Bool::True;
}
+ # XXX - DESTROY is NYI in Rakudo at the time this was written, so
+ # the following has no effect.
+ method DESTROY() {
@moritz Rakudo Perl member
moritz added a note

now implemented in rakudo-moar; but it should be submethod, not a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # It might be correct to self.close(), here, but perhaps not...
+ self.flush();
+ }
+
method eof() {
nqp::p6bool($!PIO.eof);
}
@@ -196,6 +204,26 @@ class IO does IO::FileTestable {
Bool::True
}
+ # Underlying Parrot buffer types:
+ # * unbuffered
+ # * line-buffered
+ # * full-buffered
+ # Returns one of those strings
+ method buffer_type(IO:D: Bool :$unbuffered=False,
+ Bool :$line=False,
+ Bool :$full=False) {
+ my $type = $unbuffered ?? 'unbuffered' !! (
+ $line ?? 'line-buffered' !! (
+ $full ?? 'full-buffered' !!
+ die "buffer_type called without a type"));
+ nqp::p6box_s($!PIO.buffer_type(nqp::unbox_s($type)));
+ }
+
+ method flush(IO:D:) {
+ $!PIO.flush();
+ Bool::True;
+ }
+
multi method say(IO:D: |$) {
my Mu $args := pir::perl6_current_args_rpa__P();
nqp::shift($args);
Something went wrong with that request. Please try again.