Name

SPVM::IO::Socket - Socket Communications

Usage

use IO::Socket;
use Sys::Socket::Constant as SOCKET;

# Create a new AF_INET socket
my $io_socket= IO::Socket->new({Domain => SOCKET->AF_INET});

# Create a new AF_INET6 socket
my $io_socket= IO::Socket->new({Domain => SOCKET->AF_INET6});

# Create a new AF_UNIX socket
my $io_socket= IO::Socket->new({Domain => SOCKET->AF_UNIX});

Description

SPVM::IO::Socket provides socket communications.

Parent Class

IO::Handle.

Fields

Domain

has Domain : protected int;

Type

has Type : protected int;

Proto

has Proto : protected ro int;

Timeout

has Timeout : protected double;

peername

has peername : protected Sys::Socket::Sockaddr;

See also Sys::Socket::Sockaddr.

Listen

has Listen : protected int;

Class Methods

new

static method new : IO::Socket ($options : object[] = undef);

The socket is set to non-blocking mode.

Options:

  • Domain : Int

  • Type : Int

  • Proto : Int

  • Timeout : Double

  • Listen : Int

See also SPVM::Sys::Socket::Constant.

Instance Methods

sockdomain

method sockdomain : int ();

Gets the "Domain" field.

socktype

method socktype : int ();

Gets the "Type" field.

protocol

method protocol : int ();

Gets the "Proto" field.

timeout

method timeout : double ();

Gets the "Timeout" field.

peername

method peername : Sys::Socket::Sockaddr ();

DESTROY

method DESTROY : void ();

recv

method recv : int ($buffer : mutable string, $length : int = -1, $flags : int = 0, $buf_offset : int = 0);

send

method send : int ($buffer : string, $flags : int = 0, $to : Sys::Socket::Sockaddr = undef, $length : int = -1, $buf_offset : int = 0);

See also Sys::Socket::Sockaddr.

close

method close : int ();

fileno

method fileno : int (); return $self->{fd}; }

sockname

method sockname : Sys::Socket::Sockaddr ();

See also Sys::Socket::Sockaddr.

shutdown

method shutdown : void ($sockfd : int, $how : int);

atmark

method atmark : int ();

sockopt

method sockopt : int ($level : int, $optname : int);

setsockopt

method setsockopt : void ($level : int, $optname : int, $optval : object of string|Int)

connected

method connected : Sys::Socket::Sockaddr ();

See also Sys::Socket::Sockaddr.

peerport

method peerport : int ();

This method is implemented in a child class.

Exceptions:

Not implemented.

peerhost

method peerhost : string ();

This method is implemented in a child class.

Exceptions:

Not implemented.

write

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

read

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

See Also

Sys::Socket

Sys::Socket

Sys::Socket::Constant

Sys::Socket::Constant

IO::Socket::INET

IO::Socket::INET

Perl's IO::Socket

IO::Socket is a Perl's IO::Socket porting to SPVM.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License