Name

Test::SPVM::Sys::Socket::ServerManager::IP - Server Manager for tests for internet domain sockets

Description

Test::SPVM::Sys::Socket::ServerManager::IP class is a server manager for tests for internet domain sockets.

Usage

my $server = Test::SPVM::Sys::Socket::ServerManager::IP->new(
  code => sub {
    my ($server_manager) = @_;
    
    my $port = $server_manager->port;
    
    my $server = Test::SPVM::Sys::Socket::Server->new_echo_server_ipv4_tcp(port => $port);
    
    $server->start;
  },
);

Details

This class is originally a Test::TCP porting for tests for SPVM::Sys::Socket.

Super Class

Test::SPVM::Sys::Socket::ServerManager

Class Methods

new

my $server = Test::SPVM::Sys::Socket::ServerManager::IP->new(%options);

Calls new method in its super class and returns its return value.

Options:

The following options are available adding the options of new method in its super class.

  • port

    Sets "port" field to this value.

Fields

port

my $port = $self->port;

The port number to which the server binds.

Instance Methods

init_fields

$server->init_fields(%options);

Calls init_fields method in the super class and sets fields of this calss.

"port" field is set to the value of port option.

If port option is not specified, the field is set to an available port.

This method is a protected method, so it should only be called in this class and its child classes.

start

$server->start($code);

Starts a server process given an anon subroutine $code.

This method calls fork function and starts the server specified by $code in the child process.

The Test::SPVM::Sys::Socket::ServerManager::IP object is passed to the 1th argument of $code.

$server->start(sub {
  my ($server_manager) = @_;
  
  my $port = $server_manager->port;
  
  
});

The parent process waits until the server starts.