Name
SPVM::Sys::Socket - System Calls for Sockets
Description
The Sys::Socket class in SPVM has methods to call system calls for sockets.
Usage
use Sys::Socket;
use Sys::Socket::Constant as SOCKET;
my $socket_fd = Sys::Socket->socket(SOCKET->AF_INET, SOCKET->SOCK_STREAM, 0);
Class Methods
htonl
static method htonl : int ($hostlong : int);
Calls the htonl function and returns its return value.
htons
static method htons : short ($hostshort : short);
Calls the htons function and returns its return value.
ntohl
static method ntohl : int ($netlong : int);
Calls the ntohl function and returns its return value.
ntohs
static method ntohs : short ($netshort : short);
Calls the ntohs function and returns its return value.
inet_aton
static method inet_aton : int ($cp : string, $inp : Sys::Socket::In_addr);
Calls the inet_aton function and returns its return value.
Excetpions:
$cp must be defined. Otherwise an excetpion is thrown.
$inp must be defined. Otherwise an excetpion is thrown.
If the got address is not a valid network, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Sys::Socket::Error::InetInvalidNetworkAddress class.
If the inet_aton function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
inet_ntoa
static method inet_ntoa : string ($in : Sys::Socket::In_addr);
Calls the inet_ntoa function and returns its return value.
Excetpions:
$in address must be defined. Otherwise an excetpion is thrown.
If the inet_ntoa function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Sys::Socket::Error::InetInvalidNetworkAddress class.
inet_pton
static method inet_pton : int ($af : int, $src : string, $dst : Sys::Socket::In_addr_base);
Calls the inet_pton function and returns its return value.
See Sys::Socket::Constant about constant values given to $af.
Exceptions:
$af must be AF_INET or AF_INET6. Otherwise an excetpion is thrown.
$dst must be defined. Otherwise an excetpion is thrown.
If $af must be AF_INET, $dst must be the Sys::Socket::In_addr class. Otherwise an excetpion is thrown.
If $af must be AF_INET6, $dst must be the Sys::Socket::In6_addr class. Otherwise an excetpion is thrown.
If the type of $dst is invalid, otherwise an excetpion is thrown.
If the got address is not a valid network, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Sys::Socket::Error::InetInvalidNetworkAddress class.
If the inet_pton function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
inet_ntop
static method inet_ntop : mutable string ($af : int, $src : Sys::Socket::In_addr_base, $dst : mutable string, $size : int);
Calls the inet_ntop function and returns its return value.
See Sys::Socket::Constant about constant values given to $af.
Excetpions:
$af must be AF_INET or AF_INET6. Otherwise an excetpion is thrown.
$src must be defined. Otherwise an excetpion is thrown.
$dst must be defined. Otherwise an excetpion is thrown.
If the inet_ntop function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
socket
static method socket : int ($domain : int, $type : int, $protocol : int);
Calls the socket function and returns its return value.
See Sys::Socket::Constant about constant values given to $domain, $type, and $protocal.
Excetpions:
If the socket function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
connect
static method connect : int ($sockfd : int, $addr : Sys::Socket::Sockaddr, $addrlen : int);
Calls the connect function and returns its return value.
Excetpions:
$addr must be defined. Otherwise an excetpion is thrown.
If the connect function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
bind
static method bind : int ($sockfd : int, $addr : Sys::Socket::Sockaddr, $addrlen : int);
Calls the bind function and returns its return value.
Excetpions:
$addr must be defined. Otherwise an excetpion is thrown.
If the bind function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
accept
static method accept : int ($sockfd : int, $addr : Sys::Socket::Sockaddr, $addrlen_ref : int*);
Calls the accept function and returns its return value.
$addr must be defined. Otherwise an excetpion is thrown.
If the accept function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
listen
static method listen : int ($sockfd : int, $backlog : int);
Calls the listen function and returns its return value.
Excetpions:
If the listen function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
shutdown
static method shutdown : int ($sockfd : int, $how : int);
Calls the shutdown function and returns its return value.
See Sys::Socket::Constant about constant values given to $how.
Excetpions:
If the shutdown function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
closesocket
static method closesocket : int ($fd : int);
Calls the closesocket function and returns its return value.
Excetpions:
If the closesocket function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
close
static method close : int ($fd : int);
Calls the "closesocket" method in Windows.
Calls the close method in the the Sys::IO class in other OSs.
recv
static method recv : int ($sockfd : int, $buf : mutable string, $len : int, $flags : int, $buf_offset : int = 0);
Calls the recv function and returns its return value.
Excetpions:
$buf must be defined. Otherwise an excetpion is thrown.
$len must be less than the length of $buf - $buf_offset. Otherwise an excetpion is thrown.
If the recv function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
send
static method send : int ($sockfd : int, $buf : string, $len : int, $flags : int, $buf_offset : int = 0);
Calls the send function and returns its return value.
Excetpions:
$buf must be defined. Otherwise an excetpion is thrown.
$len must be less than the length of $buf - $buf_offset. Otherwise an excetpion is thrown.
If the send function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
sendto
static method sendto : int ($sockfd : int, $buf : string, $len : int, $flags : int, $addr : Sys::Socket::Sockaddr, $addrlen : int, $buf_offset : int = 0);
Calls the sendto function and returns its return value.
Excetpions:
$buf must be defined. Otherwise an excetpion is thrown.
$addr must be defined. Otherwise an excetpion is thrown.
$len must be less than the length of $buf - $buf_offset. Otherwise an excetpion is thrown.
If the send function failed, an excetpion is thrownn with eval_error_id
set to the basic type ID of the Error::System class.
getpeername
static method getpeername : int ($sockfd : int, $addr : Sys::Socket::Sockaddr, $addrlen_ref : int*);
Calls the getpeername function and returns its return value.
Exceptions:
$addr must be defined. Otherwise an exception is thrown.
If the getpeername function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
Excetpions:
getsockname
static method getsockname : int ($sockfd : int, $addr : Sys::Socket::Sockaddr, $addrlen_ref : int*);
Calls the getsockname function and returns its return value.
Excetpions:
$addr must be defined. Otherwise an exception is thrown.
If the getsockname function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
Excetpions:
getsockopt
static method getsockopt : int ($sockfd : int, $level : int, $optname : int, $optval : mutable string, $optlen_ref : int*);
Calls the getsockopt function and returns its return value.
See Sys::Socket::Constant about constant values given to $level and $optname.
Exceptions:
$optval must be defined. Otherwise an exception is thrown.
The referred value of $optlen_ref must be greater than or equal to 0. Otherwise an exception is thrown.
The referred value of $optlen_ref must be less than or equal to the length of $optval. Otherwise an exception is thrown.
If the getsockopt function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
setsockopt
static method setsockopt : int ($sockfd : int, $level : int, $optname : int, $optval : string, $optlen : int);
Calls the setsockopt function and returns its return value.
See Sys::Socket::Constant about constant values given to $level and $optname.
Exceptions:
$optval must be defined. Otherwise an exception is thrown.
$optlen must be greater than or equal to 0. Otherwise an exception is thrown.
$optlen must be less than or equal to the length of $optval. Otherwise an exception is thrown.
If the setsockopt function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
socketpair
static method socketpair : int ($domain : int, $type : int, $protocol : int, $sv : int[]);
Calls the socketpair function and returns its return value.
See Sys::Socket::Constant about constant values given to $domain, $type, and $protocol.
Exceptions:
$sv must be defined. Otherwise an exception is thrown.
The length of $sv must be greater than or equal to 2. Otherwise an exception is thrown.
If the socketpair function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
getaddrinfo
static method getaddrinfo : int ($node : string, $service : string, $hints : Sys::Socket::Addrinfo, $res_ref : Sys::Socket::AddrinfoLinkedList[]);
Calls the getaddrinfo function and returns its return value.
Exceptions:
$res_array must be defined. Otherwise an exception is thrown.
The length of $res_array must be equal to 1.
If the getnameinfo function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
getnameinfo
static method getnameinfo : int ($sa : Sys::Socket::Sockaddr, $salen : int, $host : mutable string, $hostlen : int, $serv : mutable string, $servlen : int, $flags : int);
Calls the getnameinfo function and returns its return value.
Excetpions:
$sa must be defined. Otherwise an exception is thrown.
If the getnameinfo function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
gai_strerror
static method gai_strerror : string($errcode : int);
Calls the gai_strerror function and returns its return value.
Excepsions:
If the gai_strerror function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
sockatmark
static method sockatmark : int ($sockfd : int);
Calls the sockatmark function and returns its return value.
Excepsions:
If the sockatmark function failed, an exception is thrown with eval_error_id
set to the basic type ID of the Error::System class.
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License