Upgrade to IO 1.22 from gbarr
[p5sagit/p5-mst-13.2.git] / ext / IO / lib / IO / Socket / UNIX.pm
CommitLineData
cf7fe8a2 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
7package IO::Socket::UNIX;
8
9use strict;
17f410f9 10our(@ISA, $VERSION);
cf7fe8a2 11use IO::Socket;
12use Socket;
13use Carp;
14
15@ISA = qw(IO::Socket);
35a60386 16$VERSION = "1.22";
105cd853 17$VERSION = eval $VERSION;
cf7fe8a2 18
19IO::Socket::UNIX->register_domain( AF_UNIX );
20
21sub new {
22 my $class = shift;
23 unshift(@_, "Peer") if @_ == 1;
24 return $class->SUPER::new(@_);
25}
26
27sub 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 }
a25cd2ee 41 if(exists $arg->{Listen} && $type != SOCK_DGRAM) {
cf7fe8a2 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
54sub hostpath {
55 @_ == 1 or croak 'usage: $sock->hostpath()';
56 my $n = $_[0]->sockname || return undef;
57 (sockaddr_un($n))[0];
58}
59
60sub peerpath {
61 @_ == 1 or croak 'usage: $sock->peerpath()';
62 my $n = $_[0]->peername || return undef;
63 (sockaddr_un($n))[0];
64}
65
661; # Keep require happy
67
68__END__
69
70=head1 NAME
71
72IO::Socket::UNIX - Object interface for AF_UNIX domain sockets
73
74=head1 SYNOPSIS
75
76 use IO::Socket::UNIX;
77
78=head1 DESCRIPTION
79
80C<IO::Socket::UNIX> provides an object interface to creating and using sockets
81in the AF_UNIX domain. It is built upon the L<IO::Socket> interface and
82inherits all the methods defined by L<IO::Socket>.
83
84=head1 CONSTRUCTOR
85
86=over 4
87
88=item new ( [ARGS] )
89
90Creates an C<IO::Socket::UNIX> object, which is a reference to a
91newly created symbol (see the C<Symbol> package). C<new>
92optionally takes arguments, these arguments are in key-value pairs.
93
94In addition to the key-value pairs accepted by L<IO::Socket>,
95C<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
102If the constructor is only passed a single argument, it is assumed to
103be a C<Peer> specification.
104
105
106 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
bbc7dcd2 107
cf7fe8a2 108As of VERSION 1.18 all IO::Socket objects have autoflush turned on
109by 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
121Returns the pathname to the fifo at the local end
122
123=item peerpath()
124
125Returns the pathanme to the fifo at the peer end
126
127=back
128
129=head1 SEE ALSO
130
131L<Socket>, L<IO::Socket>
132
133=head1 AUTHOR
134
854822f1 135Graham Barr. Currently maintained by the Perl Porters. Please report all
136bugs to <perl5-porters@perl.org>.
cf7fe8a2 137
138=head1 COPYRIGHT
139
140Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
141This program is free software; you can redistribute it and/or
142modify it under the same terms as Perl itself.
143
144=cut