Name

SPVM::Sys - System Calls for File IO, Sockets, Time, Process, Signals, Users

Description

Sys class in SPVM has methods to call system calls for file IO, sockets, user manipulation, process manipulation, and time.

Usage

use Sys;

my $fd_ref = [(Sys::IO::FileStream)undef];
my $file = "a.txt";
Sys->open($fd_ref, "<", $file);

Sys->mkdir("foo");

Sys->rmdir("foo");

my $env_path = Sys->env("PATH");

my $process_id = Sys->process_id;

Class Methods

STDIN

static method STDIN : Sys::IO::FileStream ();

Returns the stdin opened by the SPVM language.

STDOUT

static method STDOUT : Sys::IO::FileStream ();

Returns the stdout opened by the SPVM language.

STDERR

static method STDERR : Sys::IO::FileStream ();

Returns the stderr opened by the SPVM language.

open

static method open : void ($stream_ref : Sys::IO::FileStream[], $open_mode : string, $file : string);

Opens a file given the open mode $open_mode and the file name $file.

The opened file stream is set to $stream_ref at index 0.

The open mode $open_mode is replaced to a representation of the fopen function before calling the fopen function.

[$open_mode]   [The mode of the fopen function]
<              rb
>              wb
>>             wa
+<             r+b
+>             w+b
+>>            a+b

If the system supports FD_CLOEXEC, this flag is set to the opened file's file descriptor using "fcntl".

Exceptions:

$stream_ref must be defined. Otherwise an exception is thrown.

The length of $stream_ref must be equal to 1. Otherwise an exception is thrown.

Exceptions thrown by Sys::IO#fopen method could be thrown.

fdopen

static method fdopen : void ($stream_ref : Sys::IO::FileStream[], $open_mode : string, $fd : int);

Same as "open" method except that this method takes the file descriptor $fd instead of the file name .

fileno

static method fileno : int ($stream : Sys::IO::FileStream);

Return the file descriptor of the file stream $stream.

This method calls Sys::IO#fileno method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#fileno method could be thrown.

read

static method read : int ($stream : Sys::IO::FileStream, $buffer : mutable string, $length : int, $buffer_offset : int = 0);

Reads data from the file stream $stream by the $length, and saves it to the buffer $buffer at offset $buffer_offset.

This method calls Sys::IO#fread method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#fread method could be thrown.

eof

static method eof : int ($stream : Sys::IO::FileStream);

Checks if the file stream $stream reasches the end of the file.

If it does, returns 1, otherwise returns 0.

This method calls Sys::IO#feof method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#feof method could be thrown.

readline

static method readline : mutable string ($stream : Sys::IO::FileStream);

Reads a line from th file stream $stream and returns it.

This method calls Sys::IO#feof method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by the "getc" method could be thrown.

getc

static method getc : int ($stream : Sys::IO::FileStream);

Gets a charactor from the file stream $stream and returns it.

This method calls Sys::IO#getc method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#getc method could be thrown.

print

static method print : void ($stream : Sys::IO::FileStream, $string : string);

Prints the string $string to the file stream $stream.

This method calls Sys::IO#fwrite method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#fwrite method could be thrown.

printf

static method printf : void ($stream, $format : string, $args : object[])

Prints the format string $string given the arguments $args to the file stream $stream.

Exceptions thrown by the "print" method class could be thrown.

say

static method say : void ($stream : Sys::IO::FileStream, $string : string);

Prints the string $string and "\n" to the file stream $stream.

Exceptions:

Exceptions thrown by the "print" method class could be thrown.

close

static method close : void ($stream : Sys::IO::FileStream);

Closes the file stream $stream.

This method calls Sys::IO#fclose method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#fclose method could be thrown.

seek

static method seek : void ($stream : Sys::IO::FileStream, $offset : long, $whence : int);

Moves the read/write position pointed to by the file stream $stream to the offset $offset given $whence.

See Sys::IO::Constant about constant values given to $whence.

This method calls Sys::IO#fseek method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#fseek method could be thrown.

tell

static method tell : long ($stream : Sys::IO::FileStream);

Returns the read/write position pointed to by the file stream $stream.

This method calls Sys::IO#ftell method.

Exceptions:

The file stream $stream must be defined. Otherwise an exception is thrown.

If the file stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#ftell method could be thrown.

sysopen

static method sysopen : void ($fd_ref : int*, $file : string, $flags : int, $mode : int = 0);

Opens a file given, the file path $file, the mode $flags and the mode $mode.

The file descriptor of the opened file is set to the value reffered by $fd_ref.

See Sys::IO::Constant about constant values given to the flags $flags and the mode $mode.

Exceptions:

Exceptions thrown by Sys::IO#open method could be thrown.

sysread

static method sysread : int ($fd : int, $buffer : mutable string, $length : int, $buffer_offset : int = 0);

Reads data from the file stream $stream by the $length, and saves it to the buffer $buffer from the offset $buffer_offset.

Exceptions:

Exceptions thrown by Sys::IO#read method could be thrown.

syswrite

static method syswrite : int ($fd : int, $buffer : string, $length : int = -1, $buffer_offset : int = 0);

Writes data to the file stream $stream by the $length from the buffer $buffer at offset $buffer_offset.

Exceptions:

Exceptions thrown by Sys::IO#write method could be thrown.

sysseek

static method sysseek : long ($fd : int, $offset : long, $whence : int);

Moves the read/write position pointed to by the file descriptor $fd to the offset $offset given $whence.

See Sys::IO::Constant about constant values given to $whence.

Exceptions:

Exceptions thrown by Sys::IO#lseek method could be thrown.

fcntl

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

Calls Sys::IO#fcntl method and its return value.

Exceptions:

Exceptions thrown by Sys::IO#fcntl method could be thrown.

flock

static method flock : void ($fd : int, $operation : int);

Locks the file specified by the file descriptor $fd given the operation $operation.

See Sys::IO::Constant about constant values given to the operation $operation.

Exceptions:

Exceptions thrown by Sys::IO#flock method could be thrown.

mkdir

static method mkdir : void ($dir : string, $mode : int);

Creates the directory given the path $dir and the mode $mode.

The permissions of the created directory are ($mode & ~umask & 0777).

In Windows, the mode $mode is ignored.

Exceptions:

Exceptions thrown by Sys::IO#mkdir method could be thrown.

umask

static method umask : int ($mode : int);

Sets the umask for the process to the mode $mode and returns the previous value.

Exceptions:

Exceptions thrown by Sys::IO#umask method could be thrown.

static method unlink : void ($file : string);

Deletes a file.

In Windows, this method calls Sys::IO::Windows#unlink method , otherwise calls Sys::IO#unlink method.

Exceptions:

Exceptions thrown by the Sys::IO::Windows#unlink method or Sys::IO#unlink method could be thrown.

rename

static method rename : void ($old_path : string, $new_path : string);

Raname the file name from the old name $old_path to the new name $new_path.

In Windows, this method calls Sys::IO::Windows#rename method , otherwise calls Sys::IO#rename method.

Exceptions:

Exceptions thrown by the Sys::IO::Windows#rename method or Sys::IO#rename method could be thrown.

rmdir

static method rmdir : void ($dir : string);

Deletes the directory given the path $dir.

Exceptions:

Exceptions thrown by Sys::IO#rmdir method could be thrown.

chdir

static method chdir : void ($dir : string);

Changes the working directory to the path $dir.

Exceptions:

Exceptions thrown by Sys::IO#chdir method could be thrown.

chmod

static method chmod : void ($mode :int, $file : string);

Changes the permissions of the file $file to the permission $mode.

Exceptions:

Exceptions thrown by Sys::IO#chmod method could be thrown.

chown

static method chown : void ($owner : int, $group : int, $file : string);

Changes the owner and the group of the file $file to $owner and $group.

Exceptions:

Exceptions thrown by Sys::IO#chown method could be thrown.

static method readlink : int ($file : string);

Returns the content of the symbolic link file $file.

In Windows thie method calls Sys::IO::Windows#readlink method , otherwise calls Sys::IO#readlink method .

Exceptions:

Exceptions thrown by Sys::IO#readlink method or Sys::IO::Windows#readlink method could be thrown.

static method symlink : int ($old_path : string, $new_path : string);

Creates a path $new_path symbolically linked to the path $old_path.

In Windows thie method calls Sys::IO::Windows#symlink method , otherwise calls Sys::IO#symlink method .

Exceptions:

Exceptions thrown by Sys::IO#symlink method or Sys::IO::Windows#symlink method could be thrown.

truncate

static method truncate : void ($fd : int, $legnth : long);

Truncates the file referenced by the file descriptor $fd to a size of precisely length bytes $legnth.

Exceptions:

Exceptions thrown by Sys::IO#ftruncate method could be thrown.

opendir

static method opendir : void ($dir_stream_ref : Sys::IO::DirStream[], $dir : string);

Opens the directory stream given the directory $dir.

The opened directory stream is set to $dir_stream_ref at index 0.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

This method calls Sys::IO#opendir method.

Exceptions thrown by Sys::IO#opendir method could be thrown.

closedir

static method closedir : void ($dir_stream : Sys::IO::DirStream);

Closes the directory stream given the directory stream $dir_stream.

This method calls Sys::IO#closedir method.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#closedir method could be thrown.

readdir

static method readdir : Sys::IO::Dirent ($dir_stream : Sys::IO::DirStream);

Reads a directory entry from the dirctory stream $dir_stream.

This method calls Sys::IO#readdir method.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#readdir method could be thrown.

rewinddir

static method rewinddir : void ($dir_stream : Sys::IO::DirStream);

Resets the position of the directory stream $dir_stream to the beginning of the directory.

This method calls Sys::IO#rewinddir method.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#rewinddir method could be thrown.

seekdir

static method seekdir : void ($dir_stream : Sys::IO::DirStream, $offset : long);

Sets the current location associated with the directory stream $dir_stream to the offset $offset.

This method calls Sys::IO#seekdir method.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#seekdir method could be thrown.

telldir

static method telldir : long ($dir_stream : Sys::IO::DirStream);

Returns the current location associated with the directory stream $dir_stream.

This method calls Sys::IO#telldir method.

Exceptions:

If the directory stream \$dir_stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#telldir method could be thrown.

popen

static method popen : void ($stream_ref : Sys::IO::FileStream[], $open_mode : string, $command : string);

Opens a file stream that joins a process by creating a pipe given the command $command and the open mode $open_mode.

The opened file stream is set to $stream_ref at index 0.

The open mode $open_mode is replaced to a representation of the fopen function before calling the fopen function.

[$open_mode]   [The mode of the fopen function]
|-             wb
-|             rb

If the system supports FD_CLOEXEC, this flag is set to the opened file's file descriptor using "fcntl".

Exceptions:

Exceptions thrown by Sys::IO#popen method or Sys::IO#_popen method could be thrown.

pclose

static method pclose : void ($stream : Sys::IO::FileStream);

Closes the file stream $stream created by the "popen" method.

This method calls Sys::IO#pclose method or Sys::IO#_pclose.

Exceptions:

The pipe stream $stream must be defined. Otherwise an exception is thrown.

If the pipe stream $stream is already closed, an exception is thrown.

Exceptions thrown by Sys::IO#pclose method or Sys::IO#_pclose method could be thrown.

select

static method select : int ($read_fds : Sys::Select::Fd_set, $write_fds : Sys::Select::Fd_set, $except_fds : Sys::Select::Fd_set, $timeout : double = 0);

Calls Sys::Select#select method and returns its return value.

If $timeout is greter than or equal to 0, it is converted to a Sys::Time::Timeval object. Otherwise is converted to undef.

$nfds is set to 1024.

Exceptions:

Exceptions thrown by Sys::Select#select method method could be thrown.

ioctl

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

Windows:

Calls Sys::Ioctl#ioctlsocket method and returns its return value.

OSs other than Windows:

Calls Sys::Ioctl#ioctl method and returns its return value.

Exceptions:

Exceptions thrown by the Sys::Ioctl#ioctl method or Sys::Ioctl#ioctlsocket method could be thrown.

A

static method A : double ($file : string);

Returns script start time minus file access time of the file $file, in days.

This method corresponds to Perl's -A.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

The exceptions thrown by "stat" method could be thrown.

C

static method C : double ($file : string);

Returns script start time minus file inode change time of the file $file, in days.

This method corresponds to Perl's -C.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

The exceptions thrown by "stat" method could be thrown.

M

static method M : double ($file : string);

Returns script start time minus file modification time of the file $file, in days.

This method corresponds to Perl's -M.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

The exceptions thrown by "stat" method could be thrown.

O

static method O : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Othersize if the file $file is owned by real uid, returns 1, otherwise returns 0.

This method corresponds to Perl's -O.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

R

static method R : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is readable by real uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -R.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

S

static method S : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a socket, returns 1, otherwise returns 0.

This method corresponds to Perl's -S.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

W

static method W : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is writable by real uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -W.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

X

static method X : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is executable by real uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -X.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

b

static method b : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a block special file, returns 1, otherwise returns 0.

This method corresponds to Perl's -b.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

c

static method c : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a character special file, returns 1, otherwise returns 0.

This method corresponds to Perl's -c.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

d

static method d : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a directory, returns 1, otherwise returns 0.

This method corresponds to Perl's -d.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

e

static method e : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

This method corresponds to Perl's -e.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

f

static method f : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a plain file, returns 1, otherwise returns 0.

This method corresponds to Perl's -f.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

g

static method g : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file has setgid bit set, returns 1, otherwise returns 0.

This method corresponds to Perl's -g.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

k

static method k : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file has sticky bit set, returns 1, otherwise returns 0.

This method corresponds to Perl's -k.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

l

static method l : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by the "lstat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a symbolic link (false if symlinks aren't supported by the file system), returns 1, otherwise returns 0.

This method corresponds to Perl's -l.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

o

static method o : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is owned by effective uid, returns 1, otherwise returns 0.

This method corresponds to Perl's -l.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

p

static method p : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is a named pipe (FIFO), or Filehandle is a pipe, returns 1, otherwise returns 0.

This method corresponds to Perl's -p.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

r

static method r : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is readable by effective uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -r.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

s

static method s : long ($file : string);

If the file $file has nonzero size, returns its size in bytes, otherwise returns 0.

This method corresponds to Perl's -s.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

The exceptions thrown by "stat" method could be thrown.

u

static method u : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file has setuid bit set, returns 1, otherwise returns 0.

This method corresponds to Perl's -u.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

w

static method w : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is writable by effective uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -u.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

x

static method x : int ($file : string);

If If the file doesn't exist or can't be examined(These checks are done by "stat" method), returns 0 and errno is set to a positive value.

Otherwise if the file $file is executable by effective uid/gid, returns 1, otherwise returns 0.

This method corresponds to Perl's -x.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

z

static method z : int ($file : string);

If the file $file has zero size (is empty), returns 1, otherwise returns 0.

This method corresponds to Perl's -z.

Exceptions:

$file must be defined. Otherwise an exception is thrown.

The exceptions thrown by "stat" method could be thrown.

time

static method time : long ();

Returns the current epoch time.

localtime

static method localtime : Sys::Time::Tm ($epoch : long = -1, $allow_minus = 0);

Converts the epoch time $epoch to a Sys::Time::Tm object, and returns it.

The return value is localized for the local time zone.

If $allow_minus is 0 and $epoch is less than 0, $epoch is set to the current epoch time.

gmtime

static method gmtime : Sys::Time::Tm ($epoch : long = -1, $allow_minus = 0);

Works just like "localtime", but the returned values are for the UTC time zone.

utime

static method utime : void ($atime : long, $mtime : long, $file : string);

Changes the access time and the modification time of the inode specified by the file $file given the access time $atime and the modification time $mtime.

If $atime < 0 and $mtime < 0, changes the access time and the modification time to the current time..

Exceptions:

Exceptions thrown by Sys::Time#utime method could be thrown.

stat

static method stat : Sys::IO::Stat ($file : string);

Returns information about a file $file.

Exceptions:

Exceptions thrown by Sys::IO::Stat#stat method could be thrown.

lstat

static method lstat : Sys::IO::Stat ($file : string);

Identical to "stat", except that if path $file is a symbolic link(or directory junction only in Windows), then the link itself is stat-ed, not the file that it refers to.

In Windows, this method calls the lstat method, otherwise calls the lstat method.

Exceptions:

Exceptions thrown by Sys::IO::Stat#lstat method or Sys::IO::Windows#lstat method could be thrown.

fstat

static method fstat : Sys::IO::Stat ($fd : int);

Identical to "stat", except that the file to be stat-ed is specified by the file descriptor $fd.

Exceptions:

Exceptions thrown by Sys::IO::Stat#fstat method could be thrown.

env

static method env : string ($name : string);

Gets an environment variable with the name $name.

set_env

static method set_env : void ($name : string, $value : string);

Sets an environment variable with the name $name and the value $value.

If $value is undef or "", the environment variable is removed.

Exceptions:

This method calls the following methods, so exceptions thrown by these methods could be thrown.

osname

static method osname : string ()

Gets the OS name. This method corresponds to Perl's $^O.

  • linux

  • darwin

  • MSWin32

  • freebsd

  • openbsd

  • solaris

Exceptions:

If the OS name could not be determined, an exception is thrown.

socket

static method socket : void ($socket_fd_ref : int*, $domain : int, $type : int, $protocol : int);

Opens a socket given the domain $domain, the type $type, and the protocal $protocol.

The created socket file descriptor is set to the value referenced by $socket_fd_ref.

This method calls Sys::Socket#socket method.

If the system supports FD_CLOEXEC, this flag is set to the value referenced by $socket_fd_ref using "fcntl".

Exceptions:

Exceptions thrown by Sys::Socket#socket method could be thrown.

connect

static method connect : void ($socket_fd : int, $sockaddr : Sys::Socket::Sockaddr);

Attempts to connect to a remote socket, just like the connect system call.

This method calls Sys::Socket#connect method.

Exceptions:

Exceptions thrown by Sys::Socket#connect method could be thrown.

bind

static method bind : void ($socket_fd : int, $sockaddr : Sys::Socket::Sockaddr);

Binds a network address $sockaddr to the socket $socket_fd.

This method calls Sys::Socket#bind method.

Exceptions:

Exceptions thrown by Sys::Socket#bind method could be thrown.

listen

static method listen : void ($socket_fd : int, $backlog : int);

Does the same thing that the listen system call does.

This method calls Sys::Socket#listen method.

Exceptions:

Exceptions thrown by Sys::Socket#listen method could be thrown.

accept

static method accept : Sys::Socket::Sockaddr ($new_socket_fd_ref : int*, $socket_fd : int);

Accepts an incoming socket connect, just as the accept system call does. Returns the packed address.

A new connected socket file descriptor is set to the value referenced by $new_socket_fd_ref.

Thie methods calls Sys::Socket#accept method.

The returned packed address is upgraded to a child class of the Sys::Socket::Sockaddr using upgrade method.

If the system supports FD_CLOEXEC, this flag is set to the value referenced by $new_socket_fd_ref using "fcntl".

Exceptions:

Exceptions thrown by Sys::Socket#accept method could be thrown.

recv

static method recv : int ($socket_fd : int, $buffer : mutable string, $length : int, $flags : int, $buffer_offset : int = 0);

Receives a message on a socket.

This method calls Sys::Socket#recv method given the arguments given to this method and returns its return value.

Exceptions:

Exceptions thrown by Sys::Socket#recv method could be thrown.

recvfrom

static method recvfrom : int ($socket_fd : int, $buffer : mutable string, $length : int, $flags : int, $sockaddr_ref : Sys::Socket::Sockaddr[], $buffer_offset : int = 0);

Receives a message on a socket given the array $sockaddr_ref for a peer socket address for output.

This method calls Sys::Socket#recvfrom method given the arguments given to this method and returns its return value.

$addrlen_ref is set to an int reference.

If $sockaddr_ref is given, $sockaddr is set to a Sys::Socket::Sockaddr object.

In this case, $sockaddr is upgraded by calling Sys::Socket::Sockaddr#upgrade method and $sockaddr_ref at index 0 is set to it.

Exceptions:

If $sockaddr_ref for an array for a peer socket address for output is defined, the length must be 1.

Exceptions thrown by Sys::Socket#recvfrom method could be thrown.

send

static method send : int ($socket_fd : int, $buffer : string, $flags : int, $length : int = -1, $buffer_offset : int = 0);

Sends a message on a socket.

This method calls Sys::Socket#send method given the arguments given to this method and returns its return value.

If $length is less than 0, $length is set to the length of $buffer.

Exceptions:

Exceptions thrown by Sys::Socket#sendto method could be thrown.

sendto

static method sendto : int ($socket_fd : int, $buffer : string, $flags : int, $sockaddr : Sys::Socket::Sockaddr, $length : int = -1, $buffer_offset : int = 0);

Sends a message on a socket given the peer socket address $sockaddr.

This method calls Sys::Socket#sendto method given the arguments given to this method and returns its return value.

If $length is less than 0, $length is set to the length of $buffer.

Exceptions:

Exceptions thrown by Sys::Socket#sendto method could be thrown.

shutdown

static method shutdown : void ($socket_fd : int, $how : int);

Shuts down a socket connection $socket_fd in the manner indicated by $how.

This method calls Sys::Socket#shutdown method.

Exceptions:

Exceptions thrown by Sys::Socket#shutdown method could be thrown.

getpeername

static method getpeername : Sys::Socket::Sockaddr ($socket_fd : int);

Returns the packed sockaddr address of the other end of the socket connection $socket_fd.

This method calls Sys::Socket#getpeername method.

The returned packed sockaddr address is upgraded to a child class of the Sys::Socket::Sockaddr using upgrade method.

Exceptions:

Exceptions thrown by Sys::Socket#getpeername method could be thrown.

getsockname

static method getsockname : Sys::Socket::Sockaddr ($socket_fd : int)

Returns the packed sockaddr address of this end of the socket connection $socket_fd.

Thie method calls Sys::Socket#getsockname method.

The returned packed sockaddr address is upgraded to a child class of the Sys::Socket::Sockaddr using upgrade method.

Exceptions:

Exceptions thrown by Sys::Socket#getsockname method could be thrown.

socketpair

static method socketpair : void ($socket_fd1_ref : int*, $socket_fd2_ref : int*, $domain : int, $type : int, $protocol : int);

Creates an unnamed pair of sockets in the specified domain, of the specified type. The domain $domain, the type $type, the protocal $protocol are specified the same as for the syscall of the same name.

The opened reading file descripor is set to the value referenced by $socket_fd1_ref.

The opened writing file descripor is set to the value referenced by $socket_fd2_ref.

This method calls Sys::Socket#socketpair method .

If available, FD_CLOEXEC is set to the file descriptor of the value referenced by $socket_fd1_ref and the value referenced by $socket_fd2_ref.

Exceptions:

Exceptions thrown by Sys::Socket#socketpair method could be thrown.

setsockopt

static method setsockopt : void ($socket_fd : int, $level : int, $option_name : int, $option_value : object of string|Int);

Sets the socket option requested.

This method calls Sys::Socket#getsockopt method.

Exceptions:

$option_value must be defined. Otherwise an exception is thrown.

The type of \$option_value must be the Int or string type.

Exceptions thrown by Sys::Socket#getsockopt method could be thrown.

getsockopt

static method getsockopt : string ($socket_fd : int, $level : int, $option_name : int, $option_value_length : int = -1);

If $option_value_length is less than 0, it is set to 4.

This method calls Sys::Socket#getsockopt method.

Examples:

Getting an int value:

my $reuseaddr_packed = Sys->getsockopt($socket, SOCKET->SOL_SOCKET, SOCKET->SO_REUSEADDR);
my $reuseaddr_ref = [0];
Fn->memcpy($reuseaddr_ref, 0, $reuseaddr_packed, 0, 4);
my $reuseaddr = $reuseaddr_ref->[0];

Exceptions:

Exceptions thrown by Sys::Socket#getsockopt method could be thrown.

signal

static method signal : void ($signal_number : int, $handler_name : string);

Sets a signal handler with its name $handler_name for the given signal number $signal_number.

If $handler_name is "DEFAULT", the signal handler is "SIG_DFL".

If $handler_name is "IGNORE", the signal handler is "SIG_IGN".

See Sys::Signal#signal method in detail.

Exceptions:

If $handler_name is not available, an exception is thrown.

The exceptions thrown by Sys::Signal#signal method could be thrown.

kill

static method kill : void ($signal_number : int, $process_id : int);

Send a signal $signal_number to the process whose process ID is $process_id.

See Sys::Signal#kill method in detail.

In Windows, see Sys::Signal#raise method in detail.

Exceptions:

The exceptions thrown by Sys::Signal#alarm method could be thrown.

The exceptions thrown by Sys::Signal#raise method could be thrown.

$process_id must be equal to Sys->process_id in Windows. Otherwise an exception is thrown.

alarm

static method alarm : int ($seconds : int);

Sets a alarm signal sent after seconds $seconds.

See Sys::Signal#alarm method in detail.

Exceptions:

The exceptions thrown by Sys::Signal#alarm method could be thrown.

fork

static method fork : int ();

Forks the process by calling Sys::Process#fork method.

It returns the child process ID to the parent process, or returns 0 to the child process.

Exceptions:

Exceptions thrown by Sys::Process#fork method could be thrown.

getpriority

static method getpriority : int ($which : int, $who : int);

Return the scheduling priority of the process, process group, or user, as indicated by $which and $who is obtained.

Exceptions:

Exceptions thrown by Sys::Process#getpriority method could be thrown.

setpriority

static method setpriority : void ($which : int, $who : int, $priority : int)

Sets the scheduling priority of the process, process group, or user, as indicated by $which and $who is obtained.

Exceptions:

Exceptions thrown by Sys::Process#setpriority method could be thrown.

sleep

static method sleep : int ($seconds : int);

Sleeps for the seconds $seconds.

wait

static method wait : int ($wstatus_ref : int*);

Waits for state changes in a child of the calling process, and returns a process ID whose state is changed.

The status about the child whose state has changed is set to $wstatus_ref.

The following methods in Sys::Process class checks the value of $wstatus_ref.

Exceptions:

Exceptions thrown by Sys::Process#wait method could be thrown.

waitpid

static method waitpid : int ($process_id : in, $options : int, $wstatus_ref : int*);

Same as the "wait" method, but can give the process ID $process_id and the options $options.

See Sys::Process::Constant about constant values given to $options.

Exceptions:

Exceptions thrown by Sys::Process#waitpid method could be thrown.

system

static method system : int ($command : string);

Executes a command specified in command using shell and return the "wait" status.

exit

static method exit : void ($status : int);

Terminates the calling process immediately with the status $status.

pipe

static method pipe : void ($read_fd_ref : int*, $write_fd_ref : int*);

Opens a pair of pipes.

If the system supports FD_CLOEXEC, this flag is set to the value referenced by $read_fd_ref and the value referenced by $write_fd_ref using "fcntl".

getpgrp

static method getpgrp : int ($process_id : int);

Gets the process group number given the process ID $process_id of the running this program.

setpgrp

static method setpgrp : void ($process_id : int, $process_group_id : int);

Sets the process group number $process_group_id given the process ID $process_id of the running this program.

process_id

static method process_id : int ();

Gets the process number of the running this program.

getppid

static method getppid : int ();

Returns the process ID of the parent of the calling process.

exec

static method exec : void ($program : string, $args : string[] = undef);

Executes the program $program with the arguments $args without using shell and never returns.

Examples:

Sys->exec("/bin/echo", ["-n", "Hello"]);

real_user_id

static method real_user_id : int ();

Gets the real user ID of the current process.

This method calls Sys::User#getuid method and returns its return value.

Exceptions:

Exceptions thrown by Sys::User#getuid method could be thrown.

effective_user_id

static method effective_user_id : int ();

Gets the effective user ID of the current process.

This method calls Sys::User#geteuid method and returns its return value.

Exceptions:

Exceptions thrown by Sys::User#geteuid method could be thrown.

real_group_id

static method real_group_id : int ();

Gets the real group ID of the current process.

This method calls Sys::User#getgid method and returns its return value.

Exceptions:

Exceptions thrown by Sys::User#getgid method could be thrown.

effective_group_id

static method effective_group_id : int ();

Gets the effective group ID of the current process.

This method calls Sys::User#getegid method and returns its return value.

Exceptions:

Exceptions thrown by Sys::User#getegid method could be thrown.

set_real_user_id

static method set_real_user_id : void ($uid : int);

Sets the real user ID of the current process.

This method calls Sys::User#setuid method given the argument given to this method.

Exceptions:

Exceptions thrown by Sys::User#setuid method could be thrown.

set_effective_user_id

static method set_effective_user_id : void ($euid : int);

Sets the effective user ID of the current process.

This method calls Sys::User#seteuid method given the argument given to this method.

Exceptions:

Exceptions thrown by Sys::User#seteuid method could be thrown.

set_real_group_id

static method set_real_group_id : void ($real_group_id : int);

Sets the real group ID of the current process.

This method calls Sys::User#setgid method given the argument given to this method.

Exceptions:

Exceptions thrown by Sys::User#setgid method could be thrown.

set_effective_group_id

static method set_effective_group_id : void ($effective_group_id : int);

Sets the effective group ID of the current process.

This method calls Sys::User#getegid method given the argument given to this method.

Exceptions:

Exceptions thrown by Sys::User#getegid method could be thrown.

setpwent

static method setpwent : void ();

Rewinds to the beginning of the password database.

endpwent

static method endpwent : void ();

Closes the password database after all processing has been performed.

getpwent

static method getpwent : Sys::User::Passwd ();

Gets a next password entry.

setgrent

static method setgrent : void ();

Rewinds to the beginning of the group database.

endgrent

static method endgrent : void ();

Closes the group database after all processing has been performed.

getgrent

static method getgrent : Sys::User::Group ();

Gets a next group entry.

getgroups

static method getgroups : int[] ();

Returns the supplementary group IDs of the calling process.

setgroups

static method setgroups : void ($group_ids : int[]);

Sets the supplementary group IDs for the calling process.

getpwuid

static method getpwuid : Sys::User::Passwd ($id : int);

Searches a password entry given The user ID $id. If found, returns the password entry, otherwise return undef.

getpwnam

static method getpwnam : Sys::User::Passwd ($name : string);

Searches a password entry given The user name $name. If found, returns the password entry, otherwise return undef.

getgrgid

static method getgrgid : Sys::User::Group ($id : int);

Searches a group entry given The group ID $id. If found, returns the group entry, otherwise return undef.

getgrnam

static method getgrnam : Sys::User::Group ($name : string);

Searches a group entry given The group name $name. If found, returns the group entry, otherwise return undef.

Modules

See Also

Repository

SPVM::Sys - Github

Author

Yuki Kimoto(https://github.com/yuki-kimoto)

Contributors

Gabor Szabo(https://github.com/szabgab)

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License