The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

Data::Tools::Socket provides set of socket I/O functions.

SYNOPSIS

use Data::Tools::Socket qw( :all ); # import all functions
use Data::Tools::Socket; # the same as :all :)
use Data::Tools::Socket qw( :none ); # do not import anything, use full package names
# --------------------------------------------------------------------------
my $read_res_len = socket_read( $socket, $data_ref, $length, $timeout );
my $write_res_len = socket_write( $socket, $data, $length, $timeout );
my $write_res_len = socket_print( $socket, $data, $timeout );
# --------------------------------------------------------------------------
my $read_data = socket_read_message( $socket, $timeout );
my $write_res = socket_write_message( $socket, $data, $timeout );
# --------------------------------------------------------------------------

FUNCTIONS

socket_read( $socket, $data_ref, $length, $timeout )

Reads $length sized data from the $socket and store it to $data_ref scalar reference.

Returns read length (can be shorter than requested $length);

$timeout is optional, it is in seconds and can be less than 1 second.

socket_write( $socket, $data, $length, $timeout )

Writes $length sized data from $data scalar to the $socket.

Returns write length (can be shorter than requested $length);

$timeout is optional, it is in seconds and can be less than 1 second.

socket_print( $socket, $data, $timeout )

Same as socket_write() but calculates requested length from the $data scalar.

$timeout is optional, it is in seconds and can be less than 1 second.

socket_read_message( $socket, $timeout )

Reads 32bit network-order integer, which then is used as data size to be read from the socket (i.e. message = 32bit-integer + data ).

Returns read data or undef for message or network error.

$timeout is optional, it is in seconds and can be less than 1 second.

socket_write_message( $socket, $data, $timeout )

Writes 32bit network-order integer, which is the size of the given $data to be written to the $socket and then writes the data (i.e. message = 32bit-integer + data ).

Returns 1 on success or undef for message or network error.

$timeout is optional, it is in seconds and can be less than 1 second.

TODO

* more docs

REQUIRED MODULES

Data::Tools::Socket uses:

* IO::Select
* Time::HiRes

GITHUB REPOSITORY

git@github.com:cade-vs/perl-data-tools.git

AUTHOR

Vladi Belperchinov-Shabanski "Cade"
<cade@noxrun.com> <cade@bis.bg> <cade@cpan.org>