| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # IO::Socket::UNIX.pm | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | # Copyright (c) 1997-8 Graham Barr . All rights reserved. | 
| 4 |  |  |  |  |  |  | # This program is free software; you can redistribute it and/or | 
| 5 |  |  |  |  |  |  | # modify it under the same terms as Perl itself. | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | package IO::Socket::UNIX; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 17 |  |  | 17 |  | 101 | use strict; | 
|  | 17 |  |  |  |  | 31 |  | 
|  | 17 |  |  |  |  | 452 |  | 
| 10 | 17 |  |  | 17 |  | 69 | use IO::Socket; | 
|  | 17 |  |  |  |  | 25 |  | 
|  | 17 |  |  |  |  | 88 |  | 
| 11 | 17 |  |  | 17 |  | 102 | use Carp; | 
|  | 17 |  |  |  |  | 32 |  | 
|  | 17 |  |  |  |  | 6696 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our @ISA = qw(IO::Socket); | 
| 14 |  |  |  |  |  |  | our $VERSION = "1.49"; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | IO::Socket::UNIX->register_domain( AF_UNIX ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub new { | 
| 19 | 9 |  |  | 9 | 1 | 1556950 | my $class = shift; | 
| 20 | 9 | 50 |  |  |  | 79 | unshift(@_, "Peer") if @_ == 1; | 
| 21 | 9 |  |  |  |  | 136 | return $class->SUPER::new(@_); | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub configure { | 
| 25 | 7 |  |  | 7 | 0 | 25 | my($sock,$arg) = @_; | 
| 26 | 7 |  |  |  |  | 12 | my($bport,$cport); | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 7 |  | 100 |  |  | 70 | my $type = $arg->{Type} || SOCK_STREAM; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 7 | 50 |  |  |  | 139 | $sock->socket(AF_UNIX, $type, 0) or | 
| 31 |  |  |  |  |  |  | return undef; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 7 | 50 |  |  |  | 23 | if(exists $arg->{Blocking}) { | 
| 34 | 0 | 0 |  |  |  | 0 | $sock->blocking($arg->{Blocking}) or | 
| 35 |  |  |  |  |  |  | return undef; | 
| 36 |  |  |  |  |  |  | } | 
| 37 | 7 | 100 |  |  |  | 28 | if(exists $arg->{Local}) { | 
| 38 | 5 |  |  |  |  | 58 | my $addr = sockaddr_un($arg->{Local}); | 
| 39 | 5 | 50 |  |  |  | 103 | $sock->bind($addr) or | 
| 40 |  |  |  |  |  |  | return undef; | 
| 41 |  |  |  |  |  |  | } | 
| 42 | 7 | 100 | 66 |  |  | 65 | if(exists $arg->{Listen} && $type != SOCK_DGRAM) { | 
|  |  | 100 |  |  |  |  |  | 
| 43 | 4 | 50 | 100 |  |  | 36 | $sock->listen($arg->{Listen} || 5) or | 
| 44 |  |  |  |  |  |  | return undef; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | elsif(exists $arg->{Peer}) { | 
| 47 | 2 |  |  |  |  | 74 | my $addr = sockaddr_un($arg->{Peer}); | 
| 48 | 2 | 50 |  |  |  | 226 | $sock->connect($addr) or | 
| 49 |  |  |  |  |  |  | return undef; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 7 |  |  |  |  | 104 | $sock; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub hostpath { | 
| 56 | 0 | 0 |  | 0 | 1 |  | @_ == 1 or croak 'usage: $sock->hostpath()'; | 
| 57 | 0 |  | 0 |  |  |  | my $n = $_[0]->sockname || return undef; | 
| 58 | 0 |  |  |  |  |  | (sockaddr_un($n))[0]; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub peerpath { | 
| 62 | 0 | 0 |  | 0 | 1 |  | @_ == 1 or croak 'usage: $sock->peerpath()'; | 
| 63 | 0 |  | 0 |  |  |  | my $n = $_[0]->peername || return undef; | 
| 64 | 0 |  |  |  |  |  | (sockaddr_un($n))[0]; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | 1; # Keep require happy | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | __END__ |