This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
small improvements to documentation of IO::Socket
[perl5.git] / dist / IO / lib / IO / Socket / UNIX.pm
CommitLineData
cf7fe8a2
GS
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;
cf7fe8a2
GS
12use Carp;
13
14@ISA = qw(IO::Socket);
1936be83 15$VERSION = "1.25";
105cd853 16$VERSION = eval $VERSION;
cf7fe8a2
GS
17
18IO::Socket::UNIX->register_domain( AF_UNIX );
19
20sub new {
21 my $class = shift;
22 unshift(@_, "Peer") if @_ == 1;
23 return $class->SUPER::new(@_);
24}
25
26sub configure {
27 my($sock,$arg) = @_;
28 my($bport,$cport);
29
30 my $type = $arg->{Type} || SOCK_STREAM;
31
32 $sock->socket(AF_UNIX, $type, 0) or
33 return undef;
34
35 if(exists $arg->{Local}) {
36 my $addr = sockaddr_un($arg->{Local});
37 $sock->bind($addr) or
38 return undef;
39 }
a25cd2ee 40 if(exists $arg->{Listen} && $type != SOCK_DGRAM) {
cf7fe8a2
GS
41 $sock->listen($arg->{Listen} || 5) or
42 return undef;
43 }
44 elsif(exists $arg->{Peer}) {
45 my $addr = sockaddr_un($arg->{Peer});
46 $sock->connect($addr) or
47 return undef;
48 }
49
50 $sock;
51}
52
53sub hostpath {
54 @_ == 1 or croak 'usage: $sock->hostpath()';
55 my $n = $_[0]->sockname || return undef;
56 (sockaddr_un($n))[0];
57}
58
59sub peerpath {
60 @_ == 1 or croak 'usage: $sock->peerpath()';
61 my $n = $_[0]->peername || return undef;
62 (sockaddr_un($n))[0];
63}
64
651; # Keep require happy
66
67__END__
68
69=head1 NAME
70
71IO::Socket::UNIX - Object interface for AF_UNIX domain sockets
72
73=head1 SYNOPSIS
74
75 use IO::Socket::UNIX;
76
77=head1 DESCRIPTION
78
79C<IO::Socket::UNIX> provides an object interface to creating and using sockets
80in the AF_UNIX domain. It is built upon the L<IO::Socket> interface and
81inherits all the methods defined by L<IO::Socket>.
82
83=head1 CONSTRUCTOR
84
85=over 4
86
87=item new ( [ARGS] )
88
89Creates an C<IO::Socket::UNIX> object, which is a reference to a
90newly created symbol (see the C<Symbol> package). C<new>
91optionally takes arguments, these arguments are in key-value pairs.
92
93In addition to the key-value pairs accepted by L<IO::Socket>,
94C<IO::Socket::UNIX> provides.
95
96 Type Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
97 Local Path to local fifo
98 Peer Path to peer fifo
1936be83 99 Listen Queue size for listen
cf7fe8a2
GS
100
101If the constructor is only passed a single argument, it is assumed to
102be a C<Peer> specification.
103
1936be83 104If the C<Listen> argument is given, but false, the queue size will be set to 5.
cf7fe8a2
GS
105
106 NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
bbc7dcd2 107
cf7fe8a2
GS
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
9f7d1e40 136bugs to <perlbug@perl.org>.
cf7fe8a2
GS
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