NAME

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

Description

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

Details

IO::Handle class is an abstract class.

See "Well Known Child Classes" about its child classes.

Usage

use IO::Handle;

Details

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

Fields

FD

has FD : protected int;

A file descriptor.

Blocking

has Blocking : protected byte;

A flag for blocking IO.

Class Methods

Instance Methods

init

protected method init : void ($options : object[] = undef);

Initializes fields given the options $options.

Options:

  • FD : Int = -1

    "FD" 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.

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.

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