NAME
Linux::Perl::sendmsg
SYNOPSIS
my $bytes = Linux::Perl::sendmsg->sendmsg(
fd => $fd,
name => $name,
iovec => [ \$str1, \$str2, .. ],
control => [ $level, $type, $data ],
flags => \@flags,
);
You can alternatively use your platform-specific module, e.g., Linux::Perl::sendmsg::x86_64.
DESCRIPTION
This module provides a Linux-specific sendmsg()
implementation. See man 2 sendmsg
for what this can do differently from send()
and sendto
.
METHODS
$bytes = CLASS->sendmsg( %OPTS )
If EAGAIN/EWOULDBLOCK is encountered, undef is returned.
%OPTS correspond to the system call arguments:
fd
name
- irrelevant for connected socketsiovec
- Optional, a reference to an array of string referencescontrol
- Optional, a reference to an array of: $LEVEL, $TYPE, $DATA. See below for examples. If you don’t use this, you might as well use Perl’ssend()
built-in.flags
- Optional, a reference to an array of any/all of:CONFIRM
,DONTROUTE
,DONTWAIT
,EOR
,MORE
,NOSIGNAL
,OOB
.
CONTROL EXAMPLES
Sending credentials via local socket
use Socket;
control => [
Socket::SOL_SOCKET(), Socket::SCM_CREDENTIALS(),
pack( 'I!*', $$, $>, split( m< >, $) ) ),
]
Passing open file descriptors via local socket
control => [
Socket::SOL_SOCKET(), Socket::SCM_RIGHTS(),
pack( 'I!*', @file_descriptors ),
]
Also see Socket::MsgHdr’s documentation for another example.
TODO
I’m not sure if recvmsg()
is feasible to implement in pure Perl, but that would be a natural complement to this module.
SEE ALSO
Socket::MsgHdr provides both sendmsg()
and recvmsg()
.