| 1 | package Socket::MsgHdr; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | #use bytes; | ||||||||||
| 6 | |||||||||||
| 7 | 5 | our @EXPORT = qw( sendmsg recvmsg ); | |||||||||
| 8 | 5 | our @EXPORT_OK = qw( pack_cmsghdr unpack_cmsghdr ); # Undocumented! | |||||||||
| 9 | 5 | our $VERSION = '0.06'; | |||||||||
| 10 | |||||||||||
| 11 | # Forcibly export our sendmsg, recvmsg methods | ||||||||||
| 12 | 5 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | *IO::Socket::sendmsg = \&sendmsg; | |||||||||
| 14 | 5 | *IO::Socket::recvmsg = \&recvmsg; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | # Define our simple accessor/mutator methods | ||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | sub flags { | ||||||||
|
Subroutine
flags: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 20 | 4 | my $self = shift; | |||||||||
| 21 | 4 | ▶ | $self->{flags} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 4 | ▶ | $self->{flags} = 0 unless defined $self->{flags}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 4 | $self->{flags}; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 5 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||
| 27 | 5 | for my $attr (qw|name buf control|) { | |||||||||
| 28 | 5 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 15 | ▶ | *{$attr} = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 31 | 77 | my $self = shift; | |||||||||
| 32 | 77 | ▶ | $self->{$attr} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 77 | ▶ | $self->{$attr} = '' unless defined $self->{$attr}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 77 | $self->{$attr}; | |||||||||
| 35 | 15 | }; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 5 | foreach my $attr (qw|name buf control|) { | |||||||||
| 39 | 5 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 15 | ▶ | *{$attr . "len"} = sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||
| 41 | 31 | my $self = shift; | |||||||||
| 42 | 31 | my $olen = length($self->$attr); | |||||||||
| 43 | 31 | ▶ | return $olen unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 22 | my $nlen = shift; | |||||||||
| 45 | |||||||||||
| 46 | 22 | ▶ | if ($nlen != $olen) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | $self->{$attr} = $olen > $nlen ? | ||||||||||
| 48 | 22 | ▶ | substr($self->{$attr}, 0, $nlen) : | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | "\x00" x $nlen; | ||||||||||
| 50 | } | ||||||||||
| 51 | 22 | $nlen; | |||||||||
| 52 | 15 | }; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | # XS functions | ||||||||||
| 58 | # ============ | ||||||||||
| 59 | # | ||||||||||
| 60 | # -- sendmsg, recvmsg, pack_cmsghdr, unpack_cmsghdr | ||||||||||
| 61 | # | ||||||||||
| 62 | 5 | require XSLoader; | |||||||||
| 63 | 5 | XSLoader::load('Socket::MsgHdr', $VERSION); | |||||||||
| 64 | |||||||||||
| 65 | # Module import | ||||||||||
| 66 | # ============= | ||||||||||
| 67 | # | ||||||||||
| 68 | 3 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 3 | require Exporter; | |||||||||
| 70 | 3 | goto &Exporter::import; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | # Constructor | ||||||||||
| 74 | # =========== | ||||||||||
| 75 | # | ||||||||||
| 76 | 31 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 31 | my $class = shift; | |||||||||
| 78 | 31 | my $self = { name => '', | |||||||||
| 79 | control => '', | ||||||||||
| 80 | buf => '', | ||||||||||
| 81 | flags => 0 }; | ||||||||||
| 82 | |||||||||||
| 83 | 31 | bless $self, $class; | |||||||||
| 84 | |||||||||||
| 85 | 31 | my %args = @_; | |||||||||
| 86 | 31 | foreach my $m (keys %args) { | |||||||||
| 87 | 43 | $self->$m($args{$m}); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 31 | return $self; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | # Methods | ||||||||||
| 94 | # ======= | ||||||||||
| 95 | # | ||||||||||
| 96 | # -- cmsghdr | ||||||||||
| 97 | # | ||||||||||
| 98 | 7 | ▶ | sub cmsghdr { | ||||||||
|
Subroutine
cmsghdr: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 7 | my $self = shift; | |||||||||
| 100 | 7 | ▶ | unless (@_) { return &unpack_cmsghdr($self->{control}); } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 5 | $self->{control} = &pack_cmsghdr(@_); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | # -- name, buf, control, flags | ||||||||||
| 105 | # -- namelen, buflen, controllen | ||||||||||
| 106 | # (loaded in INIT) | ||||||||||
| 107 | |||||||||||
| 108 | 5 | 1; | |||||||||
| 109 | __END__ | ||||||||||