NAME

SPVM::IO::Handle - I/O Handling

Description

IO::Handle class in SPVM has methods to handle file handles.

Usage

use IO::Handle;
my $handle = IO::Handle->new;

Details

This class is a Perl's IO::Handle porting.

Fields

FD

has FD : protected int;

A file descriptor.

AutoFlush

has AutoFlush : protected byte;

A flag for auto flush.

Blocking

has Blocking : protected byte;

A flag for blocking IO.

Class Methods

new

static method new : IO::Handle ($options : object[]);

Creates a new IO::Handle object, and returns it.

Options:

  • FD : Int = -1

    "FD" field is set to this value.

  • AutoFlush : Int = 0

    "AutoFlush" field is set to this value.

  • Blocking : Int = 1

    "Blocking" field is set to this value.

    If this value is 0, "set_blocking" method is called with 0.

Instance Methods

fileno

method fileno : int ();

Returns the value of "FD" field.

opened

method opened : int ();

If "FD" is greater than or equal to 0, returns 1. Otherwise returns 0.

autoflush

method autoflush : int ();

Returns the value of "AutoFlush" field.

set_autoflush

method set_autoflush : void ($autoflush : int);

Sets "AutoFlush" field to $autoflush.

blocking

method blocking : int ();

Retruns the value of "Blocking" field.

set_blocking

method set_blocking : void ($blocking : int);

If $blocking is a false value and "Blocking" field is a true value, enables the non-blocking mode of the file descriptor "FD".

If $blocking is a true value and "Blocking" field is a false value, disables the non-blocking mode of the file descriptor "FD".

And sets "Blocking" field to $blocking.

close

method close : int ();

Closes the stream associated with the file descriptoer "FD".

This method is implemented in a child class.

read

method read : int ($string : mutable string, $length : int = -1, $offset : int = 0);

Reads the length $length of data from the stream associated with the file descriptoer "FD" and store it to the offset $offset position of the string $string.

And returns the read length.

This method is implemented in a child class.

write

method write : int ($string : string, $length : int = -1, $offset : int = 0);

Writes the length $length from the offset $offset of the string $string to the stream associated with the file descriptoer "FD".

And returns the write length.

This method is implemented in a child class.

print

method print : void ($string : string);

Outputs the string $string to the stream associated with the file descriptoer "FD".

Same as the following method call.

$handle->write($string);

printf

method printf : void ($format : string, $args : object[]...);

Outputs a string fomatted with the format $format and its parameters $args to the stream associated with the file descriptoer "FD".

Same as the following method call.

my $formated_string = Format->sprintf($format, $args);
$handle->print($formated_string);

say

method say : void ($string : string);

Outputs the string $string and \n to the stream associated with the file descriptoer "FD".

Same as the following method call.

$handle->print($string);
$handle->print("\n");

stat

method stat : Sys::IO::Stat ();

Calls Sys#stat method with the file descriptor "FD", and returns the return value.

fcntl

method fcntl : int ($command : int, $command_arg : object = undef of Int|Sys::IO::Flock|object);

Calls Sys#fcntl method with the file descriptor "FD", and returns the return value.

ioctl

static method ioctl : int ($fd : int, $request : int, $request_arg_ref : object of byte[]|short[]|int[]|long[]|float[]|double[]|object = undef);

Calls Sys#ioctl method with the file descriptor "FD", and returns the return value.

sync

method sync : void ();

Syncs the stream associated with the file descriptoer "FD".

This method is implemented in a child class.

truncate

method truncate : void ($legnth : long);

Trancates the stream associated with the file descriptoer "FD".

This method is implemented in a child class.

Well Known Child Classes

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License