File | /usr/local/lib/perl5/5.8.8/IO/Socket/UNIX.pm |
Statements Executed | 18 |
Statement Execution Time | 1.24ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
0 | 0 | 0 | 0s | 0s | BEGIN | IO::Socket::UNIX::
0 | 0 | 0 | 0s | 0s | configure | IO::Socket::UNIX::
0 | 0 | 0 | 0s | 0s | hostpath | IO::Socket::UNIX::
0 | 0 | 0 | 0s | 0s | new | IO::Socket::UNIX::
0 | 0 | 0 | 0s | 0s | peerpath | IO::Socket::UNIX::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # IO::Socket::UNIX.pm | ||||
2 | # | ||||
3 | # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. 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 | 3 | 143µs | 1 | 24µs | use strict; # spent 24µs making 1 call to strict::import |
10 | 1 | 5µs | our(@ISA, $VERSION); | ||
11 | 3 | 105µs | 1 | 4.90ms | use IO::Socket; # spent 4.90ms making 1 call to IO::Socket::import |
12 | 3 | 110µs | 1 | 4.01ms | use Socket; # spent 4.01ms making 1 call to Exporter::import |
13 | 3 | 717µs | 1 | 230µs | use Carp; # spent 230µs making 1 call to Exporter::import |
14 | |||||
15 | 1 | 10µs | @ISA = qw(IO::Socket); | ||
16 | 1 | 6µs | $VERSION = "1.22"; | ||
17 | 1 | 59µs | $VERSION = eval $VERSION; | ||
18 | |||||
19 | 1 | 70µs | 2 | 169µs | IO::Socket::UNIX->register_domain( AF_UNIX ); # spent 147µs making 1 call to Socket::AUTOLOAD
# spent 22µs making 1 call to IO::Socket::register_domain |
20 | |||||
21 | sub new { | ||||
22 | my $class = shift; | ||||
23 | unshift(@_, "Peer") if @_ == 1; | ||||
24 | return $class->SUPER::new(@_); | ||||
25 | } | ||||
26 | |||||
27 | sub configure { | ||||
28 | my($sock,$arg) = @_; | ||||
29 | my($bport,$cport); | ||||
30 | |||||
31 | my $type = $arg->{Type} || SOCK_STREAM; | ||||
32 | |||||
33 | $sock->socket(AF_UNIX, $type, 0) or | ||||
34 | return undef; | ||||
35 | |||||
36 | if(exists $arg->{Local}) { | ||||
37 | my $addr = sockaddr_un($arg->{Local}); | ||||
38 | $sock->bind($addr) or | ||||
39 | return undef; | ||||
40 | } | ||||
41 | if(exists $arg->{Listen} && $type != SOCK_DGRAM) { | ||||
42 | $sock->listen($arg->{Listen} || 5) or | ||||
43 | return undef; | ||||
44 | } | ||||
45 | elsif(exists $arg->{Peer}) { | ||||
46 | my $addr = sockaddr_un($arg->{Peer}); | ||||
47 | $sock->connect($addr) or | ||||
48 | return undef; | ||||
49 | } | ||||
50 | |||||
51 | $sock; | ||||
52 | } | ||||
53 | |||||
54 | sub hostpath { | ||||
55 | @_ == 1 or croak 'usage: $sock->hostpath()'; | ||||
56 | my $n = $_[0]->sockname || return undef; | ||||
57 | (sockaddr_un($n))[0]; | ||||
58 | } | ||||
59 | |||||
60 | sub peerpath { | ||||
61 | @_ == 1 or croak 'usage: $sock->peerpath()'; | ||||
62 | my $n = $_[0]->peername || return undef; | ||||
63 | (sockaddr_un($n))[0]; | ||||
64 | } | ||||
65 | |||||
66 | 1 | 18µs | 1; # Keep require happy | ||
67 | |||||
68 | __END__ | ||||
69 | |||||
70 | =head1 NAME | ||||
71 | |||||
72 | IO::Socket::UNIX - Object interface for AF_UNIX domain sockets | ||||
73 | |||||
74 | =head1 SYNOPSIS | ||||
75 | |||||
76 | use IO::Socket::UNIX; | ||||
77 | |||||
78 | =head1 DESCRIPTION | ||||
79 | |||||
80 | C<IO::Socket::UNIX> provides an object interface to creating and using sockets | ||||
81 | in the AF_UNIX domain. It is built upon the L<IO::Socket> interface and | ||||
82 | inherits all the methods defined by L<IO::Socket>. | ||||
83 | |||||
84 | =head1 CONSTRUCTOR | ||||
85 | |||||
86 | =over 4 | ||||
87 | |||||
88 | =item new ( [ARGS] ) | ||||
89 | |||||
90 | Creates an C<IO::Socket::UNIX> object, which is a reference to a | ||||
91 | newly created symbol (see the C<Symbol> package). C<new> | ||||
92 | optionally takes arguments, these arguments are in key-value pairs. | ||||
93 | |||||
94 | In addition to the key-value pairs accepted by L<IO::Socket>, | ||||
95 | C<IO::Socket::UNIX> provides. | ||||
96 | |||||
97 | Type Type of socket (eg SOCK_STREAM or SOCK_DGRAM) | ||||
98 | Local Path to local fifo | ||||
99 | Peer Path to peer fifo | ||||
100 | Listen Create a listen socket | ||||
101 | |||||
102 | If the constructor is only passed a single argument, it is assumed to | ||||
103 | be a C<Peer> specification. | ||||
104 | |||||
105 | |||||
106 | NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE | ||||
107 | |||||
108 | As of VERSION 1.18 all IO::Socket objects have autoflush turned on | ||||
109 | by default. This was not the case with earlier releases. | ||||
110 | |||||
111 | NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE | ||||
112 | |||||
113 | =back | ||||
114 | |||||
115 | =head1 METHODS | ||||
116 | |||||
117 | =over 4 | ||||
118 | |||||
119 | =item hostpath() | ||||
120 | |||||
121 | Returns the pathname to the fifo at the local end | ||||
122 | |||||
123 | =item peerpath() | ||||
124 | |||||
125 | Returns the pathanme to the fifo at the peer end | ||||
126 | |||||
127 | =back | ||||
128 | |||||
129 | =head1 SEE ALSO | ||||
130 | |||||
131 | L<Socket>, L<IO::Socket> | ||||
132 | |||||
133 | =head1 AUTHOR | ||||
134 | |||||
135 | Graham Barr. Currently maintained by the Perl Porters. Please report all | ||||
136 | bugs to <perl5-porters@perl.org>. | ||||
137 | |||||
138 | =head1 COPYRIGHT | ||||
139 | |||||
140 | Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved. | ||||
141 | This program is free software; you can redistribute it and/or | ||||
142 | modify it under the same terms as Perl itself. | ||||
143 | |||||
144 | =cut |