The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Sys::Poll::PollfdArray - Array of struct pollfd in the C language

Description

Sys::Poll::PollfdArray class in SPVM represents the array of struct pollfd in the C language.

Usage

  use Sys::Poll::PollfdArray;
  use Sys::Poll::Constant as POLL;
  
  my $pollfds = Sys::Poll::PollfdArray->new;
  
  # Add
  my $fd = 1;
  $pollfds->push($fd);
  
  # Get
  my $fd = $pollfds->fd($index);
  my $event = $pollfds->events($index);
  my $revent = $pollfds->revents($index);
  
  # Event Constant Values
  my $event = POLL->POLLIN;
  my $event = POLL->POLLOUT;
  
  # Set
  $pollfds->set_fd($index, $fd);
  $pollfds->set_events($index, $event);
  $pollfds->set_revents($index, $revent);
  
  # Remove
  $pollfds->remove($index);
  
  # Length
  my $length = $pollfds->length;

Details

This class is a pointer class. The pointer is set to an struct pollfd array.

Fields

length

has length : ro int;

The length of the array of struct pollfd data.

capacity

has capacity : ro int;

The capacity of the array of struct pollfd data.

Class Methods

new

static method new : Sys::Poll::PollfdArray ($length : int = 0, $capacity : int = -1);

Creates a new Sys::Poll::PollfdArray object given the length $lenth and the capacity $capacity.

If $capacity is a negative value, $capacity is set to $length. And if $capacity is 0, $capacity is set to 1.

A struct pollfd array is created and the pointer is set to it.

Instance Methods

DESTROY

method DESTROY : void ();

The destructor. The struct pollfd array is released.

fd

method fd : int ($index : int);

Returns fd of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

set_fd

method set_fd : void ($index : int, $fd : int);

Sets fd of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

events

method events : int ($index : int);

Returns events of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

set_events

method set_events : void ($index : int, $events : int);

Sets events of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

See Sys::Poll::Constant about constant values given to $revents.

events

method revents : int ($index : int);

Returns revents of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

set_revents

method set_revents : void ($index : int, $revents : int);

Sets revents of the array of struct pollfd data at the index $index.

Excetpions:

$index must be greater than or equal to 0. Otherwise an exception is thrown.

$index must be less than the length of the file descripters. Otherwise an exception is thrown.

See Sys::Poll::Constant about constant values given to $revents.

push

method push : void ($fd : int);

Adds an struct pollfd data with the file descriptoer $fd to the end of the struct pollfd array.

If the capacity stored in "capacity" fields is not enough, it is extended to about twice its capacity.

remove

method remove : void ($index : int);

Removes an struct pollfd data at the index $index.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License