summaryrefslogtreecommitdiff
path: root/ext/IO
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-12-25 11:25:00 +1200
committerChip Salzenberg <chip@atlantic.net>1996-12-25 11:25:00 +1200
commit7a4c00b4303a05a04564a03a88f4fa5c7a06a6e9 (patch)
treeed0b5c9815e3415ad3fb0f0239c9dbcc595f6997 /ext/IO
parentb0c42ed9ba0f4415d135379bc4867084c8c23f6a (diff)
downloadperl-7a4c00b4303a05a04564a03a88f4fa5c7a06a6e9.tar.gz
[inseparable changes from patch from perl5.003_15 to perl5.003_16]
CORE PORTABILITY Subject: _13: patches for unicos/unicosmk Date: Fri, 20 Dec 1996 14:38:50 -0600 From: Dean Roehrich <roehrich@cray.com> Files: Configure MANIFEST hints/unicos.sh hints/unicosmk.sh private-msgid: <199612202038.OAA22805@poplar.cray.com> LIBRARY AND EXTENSIONS Subject: Refresh IO to 1.14 From: Graham Barr <gbarr@ti.com> Files: MANIFEST ext/IO/IO.xs ext/IO/README ext/IO/lib/IO/File.pm ext/IO/lib/IO/Handle.pm ext/IO/lib/IO/Pipe.pm ext/IO/lib/IO/Seekable.pm ext/IO/lib/IO/Select.pm ext/IO/lib/IO/Socket.pm t/lib/io_dup.t t/lib/io_pipe.t t/lib/io_sel.t t/lib/io_sock.t t/lib/io_tell.t t/lib/io_udp.t t/lib/io_xs.t OTHER CORE CHANGES Subject: Fix 'foreach(@ARGV) { while (<>) { push @p,$_ } }' From: Chip Salzenberg <chip@atlantic.net> Files: cop.h pp_hot.c scope.c Subject: Eliminate warnings from C< undef $x; $x OP= "foo" > From: Chip Salzenberg <chip@atlantic.net> Files: doop.c pp.c pp.h pp_hot.c Subject: Try again to improve method caching Date: Mon, 23 Dec 1996 20:13:56 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: gv.c sv.c Msg-ID: <199612240113.UAA09487@monk.mps.ohio-state.edu> (applied based on p5p patch as commit 81c78688fe5c3927ad37ba29de14c86e38120317) Subject: Be more careful about 'o' magic memory management From: Chip Salzenberg <chip@atlantic.net> Files: mg.c sv.c Subject: Fix bad pointer refs when localized object loses magic From: Chip Salzenberg <chip@atlantic.net> Files: scope.c
Diffstat (limited to 'ext/IO')
-rw-r--r--ext/IO/IO.xs4
-rw-r--r--ext/IO/README4
-rw-r--r--ext/IO/lib/IO/File.pm11
-rw-r--r--ext/IO/lib/IO/Handle.pm34
-rw-r--r--ext/IO/lib/IO/Pipe.pm21
-rw-r--r--ext/IO/lib/IO/Seekable.pm7
-rw-r--r--ext/IO/lib/IO/Select.pm163
-rw-r--r--ext/IO/lib/IO/Socket.pm132
8 files changed, 225 insertions, 151 deletions
diff --git a/ext/IO/IO.xs b/ext/IO/IO.xs
index 3cc3518e7e..a6eb075964 100644
--- a/ext/IO/IO.xs
+++ b/ext/IO/IO.xs
@@ -203,6 +203,7 @@ int
untaint(handle)
SV * handle
CODE:
+#ifdef IOf_UNTAINT
IO * io;
io = sv_2io(handle);
if (io) {
@@ -210,9 +211,12 @@ untaint(handle)
RETVAL = 0;
}
else {
+#endif
RETVAL = -1;
errno = EINVAL;
+#ifdef IOf_UNTAINT
}
+#endif
OUTPUT:
RETVAL
diff --git a/ext/IO/README b/ext/IO/README
new file mode 100644
index 0000000000..e855afade4
--- /dev/null
+++ b/ext/IO/README
@@ -0,0 +1,4 @@
+This directory contains files from the IO distribution maintained by
+Graham Barr <bodg@tiuk.ti.com>. If you find that you have to modify
+any files in this directory then please forward him a patch for only
+the files in this directory.
diff --git a/ext/IO/lib/IO/File.pm b/ext/IO/lib/IO/File.pm
index 81d48b1c54..e44d77f1fe 100644
--- a/ext/IO/lib/IO/File.pm
+++ b/ext/IO/lib/IO/File.pm
@@ -1,3 +1,5 @@
+#
+
package IO::File;
=head1 NAME
@@ -91,14 +93,11 @@ L<IO::Seekable>
Derived from FileHandle.pm by Graham Barr E<lt>F<bodg@tiuk.ti.com>E<gt>.
-=head1 REVISION
-
-$Revision: 1.5 $
-
=cut
require 5.000;
-use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD);
+use strict;
+use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD @ISA);
use Carp;
use Symbol;
use SelectSaver;
@@ -110,7 +109,7 @@ require DynaLoader;
@ISA = qw(IO::Handle IO::Seekable Exporter DynaLoader);
-$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
+$VERSION = "1.06";
@EXPORT = @IO::Seekable::EXPORT;
diff --git a/ext/IO/lib/IO/Handle.pm b/ext/IO/lib/IO/Handle.pm
index 7b8c709c78..59741c1c11 100644
--- a/ext/IO/lib/IO/Handle.pm
+++ b/ext/IO/lib/IO/Handle.pm
@@ -180,12 +180,11 @@ class from C<IO::Handle> and inherit those methods.
Derived from FileHandle.pm by Graham Barr E<lt>F<bodg@tiuk.ti.com>E<gt>
-Version 1.1201 specialized from 1.12 for inclusion in Perl distribution
-
=cut
require 5.000;
-use vars qw($RCS $VERSION @EXPORT_OK $AUTOLOAD);
+use strict;
+use vars qw($VERSION @EXPORT_OK $AUTOLOAD @ISA);
use Carp;
use Symbol;
use SelectSaver;
@@ -193,8 +192,7 @@ use SelectSaver;
require Exporter;
@ISA = qw(Exporter);
-$VERSION = "1.1201";
-$RCS = sprintf("%s", q$Revision: 1.15 $ =~ /([\d\.]+)/);
+$VERSION = "1.14";
@EXPORT_OK = qw(
autoflush
@@ -244,6 +242,7 @@ sub AUTOLOAD {
$constname =~ s/.*:://;
my $val = constant($constname);
defined $val or croak "$constname is not a valid IO::Handle macro";
+ no strict 'refs';
*$AUTOLOAD = sub { $val };
goto &$AUTOLOAD;
}
@@ -270,16 +269,23 @@ sub new_from_fd {
bless $fh, $class;
}
-#
-# That an IO::Handle is being destroyed does not necessarily mean
-# that the associated filehandle should be closed. This is because
-# *FOO{FILEHANDLE} may by a synonym for *BAR{FILEHANDLE}.
-#
-# If this IO::Handle really does have the final reference to the
-# given FILEHANDLE, then Perl will close it for us automatically.
-#
-
sub DESTROY {
+ my ($fh) = @_;
+
+ # During global object destruction, this function may be called
+ # on FILEHANDLEs as well as on the GLOBs that contains them.
+ # Thus the following trickery. If only the CORE file operators
+ # could deal with FILEHANDLEs, it wouldn't be necessary...
+
+ if ($fh =~ /=FILEHANDLE\(/) {
+ local *TMP = $fh;
+ close(TMP)
+ if defined fileno(TMP);
+ }
+ else {
+ close($fh)
+ if defined fileno($fh);
+ }
}
################################################
diff --git a/ext/IO/lib/IO/Pipe.pm b/ext/IO/lib/IO/Pipe.pm
index 9ec8b6498a..34cb0daad2 100644
--- a/ext/IO/lib/IO/Pipe.pm
+++ b/ext/IO/lib/IO/Pipe.pm
@@ -4,7 +4,7 @@ package IO::Pipe;
=head1 NAME
-IO::Pipe - supply object methods for pipes
+IO::pipe - supply object methods for pipes
=head1 SYNOPSIS
@@ -89,11 +89,7 @@ L<IO::Handle>
=head1 AUTHOR
-Graham Barr E<lt>F<bodg@tiuk.ti.com>E<gt>
-
-=head1 REVISION
-
-$Revision: 1.7 $
+Graham Barr <bodg@tiuk.ti.com>
=head1 COPYRIGHT
@@ -104,12 +100,13 @@ as Perl itself.
=cut
require 5.000;
+use strict;
use vars qw($VERSION);
use Carp;
use Symbol;
require IO::Handle;
-$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
+$VERSION = "1.08";
sub new {
my $type = shift;
@@ -165,9 +162,10 @@ sub reader {
my $pid = $me->_doit(0,@_)
if(@_);
+ close(${*$me}[1]);
bless $me, ref($fh);
- *{*$me} = *{*$fh}; # Alias self to handle
- bless $fh; # Really wan't un-bless here
+ *{*$me} = *{*$fh}; # Alias self to handle
+ bless $fh, 'IO::Pipe::DeadEnd'; # Really wan't un-bless here
${*$me}{'io_pipe_pid'} = $pid
if defined $pid;
@@ -181,9 +179,10 @@ sub writer {
my $pid = $me->_doit(1,@_)
if(@_);
+ close(${*$me}[0]);
bless $me, ref($fh);
- *{*$me} = *{*$fh}; # Alias self to handle
- bless $fh; # Really wan't un-bless here
+ *{*$me} = *{*$fh}; # Alias self to handle
+ bless $fh, 'IO::Pipe::DeadEnd'; # Really wan't un-bless here
${*$me}{'io_pipe_pid'} = $pid
if defined $pid;
diff --git a/ext/IO/lib/IO/Seekable.pm b/ext/IO/lib/IO/Seekable.pm
index 8e0f87ac18..e8a9530e80 100644
--- a/ext/IO/lib/IO/Seekable.pm
+++ b/ext/IO/lib/IO/Seekable.pm
@@ -42,14 +42,11 @@ L<IO::File>
Derived from FileHandle.pm by Graham Barr E<lt>bodg@tiuk.ti.comE<gt>
-=head1 REVISION
-
-$Revision: 1.5 $
-
=cut
require 5.000;
use Carp;
+use strict;
use vars qw($VERSION @EXPORT @ISA);
use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
require Exporter;
@@ -57,7 +54,7 @@ require Exporter;
@EXPORT = qw(SEEK_SET SEEK_CUR SEEK_END);
@ISA = qw(Exporter);
-$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
+$VERSION = "1.06";
sub clearerr {
@_ == 1 or croak 'usage: $fh->clearerr()';
diff --git a/ext/IO/lib/IO/Select.pm b/ext/IO/lib/IO/Select.pm
index 845d6b25a4..dea684a62e 100644
--- a/ext/IO/lib/IO/Select.pm
+++ b/ext/IO/lib/IO/Select.pm
@@ -1,4 +1,8 @@
# IO::Select.pm
+#
+# Copyright (c) 1995 Graham Barr. All rights reserved. This program is free
+# software; you can redistribute it and/or modify it under the same terms
+# as Perl itself.
package IO::Select;
@@ -47,17 +51,30 @@ will be returned when an event occurs. C<IO::Select> keeps these values in a
cache which is indexed by the C<fileno> of the handle, so if more than one
handle with the same C<fileno> is specified then only the last one is cached.
+Each handle can be an C<IO::Handle> object, an integer or an array
+reference where the first element is a C<IO::Handle> or an integer.
+
=item remove ( HANDLES )
Remove all the given handles from the object. This method also works
by the C<fileno> of the handles. So the exact handles that were added
need not be passed, just handles that have an equivalent C<fileno>
+=item exists ( HANDLE )
+
+Returns a true value (actually the handle itself) if it is present.
+Returns undef otherwise.
+
+=item handles
+
+Return an array of all registered handles.
+
=item can_read ( [ TIMEOUT ] )
-Return an array of handles that are ready for reading. C<TIMEOUT> is the maximum
-amount of time to wait before returning an empty list. If C<TIMEOUT> is
-not given then the call will block.
+Return an array of handles that are ready for reading. C<TIMEOUT> is
+the maximum amount of time to wait before returning an empty list. If
+C<TIMEOUT> is not given and any handles are registered then the call
+will block.
=item can_write ( [ TIMEOUT ] )
@@ -65,8 +82,8 @@ Same as C<can_read> except check for handles that can be written to.
=item has_error ( [ TIMEOUT ] )
-Same as C<can_read> except check for handles that have an error condition, for
-example EOF.
+Same as C<can_read> except check for handles that have an error
+condition, for example EOF.
=item count ()
@@ -74,12 +91,20 @@ Returns the number of handles that the object will check for when
one of the C<can_> methods is called or the object is passed to
the C<select> static method.
+=item bits()
+
+Return the bit string suitable as argument to the core select() call.
+
+=item bits()
+
+Return the bit string suitable as argument to the core select() call.
+
=item select ( READ, WRITE, ERROR [, TIMEOUT ] )
-C<select> is a static method, that is you call it with the package name
-like C<new>. C<READ>, C<WRITE> and C<ERROR> are either C<undef> or
-C<IO::Select> objects. C<TIMEOUT> is optional and has the same effect as
-before.
+C<select> is a static method, that is you call it with the package
+name like C<new>. C<READ>, C<WRITE> and C<ERROR> are either C<undef>
+or C<IO::Select> objects. C<TIMEOUT> is optional and has the same
+effect as for the core select call.
The result will be an array of 3 elements, each a reference to an array
which will hold the handles that are ready for reading, writing and have
@@ -120,10 +145,6 @@ listening for more connections on a listen socket
Graham Barr E<lt>F<Graham.Barr@tiuk.ti.com>E<gt>
-=head1 REVISION
-
-$Revision: 1.9 $
-
=head1 COPYRIGHT
Copyright (c) 1995 Graham Barr. All rights reserved. This program is free
@@ -136,13 +157,13 @@ use strict;
use vars qw($VERSION @ISA);
require Exporter;
-$VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/);
+$VERSION = "1.10";
@ISA = qw(Exporter); # This is only so we can do version checking
-sub VEC_BITS {0}
-sub FD_COUNT {1}
-sub FIRST_FD {2}
+sub VEC_BITS () {0}
+sub FD_COUNT () {1}
+sub FIRST_FD () {2}
sub new
{
@@ -159,39 +180,63 @@ sub new
sub add
{
+ shift->_update('add', @_);
+}
+
+
+sub remove
+{
+ shift->_update('remove', @_);
+}
+
+
+sub exists
+{
my $vec = shift;
- my $f;
+ $vec->[$vec->_fileno(shift) + FIRST_FD];
+}
- $vec->[VEC_BITS] = '' unless defined $vec->[VEC_BITS];
- foreach $f (@_)
- {
- my $fn = $f =~ /^\d+$/ ? $f : fileno($f);
- next
- unless defined $fn;
- vec($vec->[VEC_BITS],$fn,1) = 1;
- $vec->[FD_COUNT] += 1
- unless defined $vec->[$fn+FIRST_FD];
- $vec->[$fn+FIRST_FD] = $f;
- }
- $vec->[VEC_BITS] = undef unless $vec->count;
+sub _fileno
+{
+ my($self, $f) = @_;
+ $f = $f->[0] if ref($f) eq 'ARRAY';
+ ($f =~ /^\d+$/) ? $f : fileno($f);
}
-sub remove
+sub _update
{
my $vec = shift;
- my $f;
+ my $add = shift eq 'add';
+ my $bits = $vec->[VEC_BITS];
+ $bits = '' unless defined $bits;
+
+ my $count = 0;
+ my $f;
foreach $f (@_)
{
- my $fn = $f =~ /^\d+$/ ? $f : fileno($f);
- next
- unless defined $fn;
- vec($vec->[VEC_BITS],$fn,1) = 0;
- $vec->[$fn+FIRST_FD] = undef;
- $vec->[FD_COUNT] -= 1;
+ my $fn = $vec->_fileno($f);
+ next unless defined $fn;
+ my $i = $fn + FIRST_FD;
+ if ($add) {
+ if (defined $vec->[$i]) {
+ $vec->[$i] = $f; # if array rest might be different, so we update
+ next;
+ }
+ $vec->[FD_COUNT]++;
+ vec($bits, $fn, 1) = 1;
+ $vec->[$i] = $f;
+ } else { # remove
+ next unless defined $vec->[$i];
+ $vec->[FD_COUNT]--;
+ vec($bits, $fn, 1) = 0;
+ $vec->[$i] = undef;
+ }
+ $count++;
}
- $vec->[VEC_BITS] = undef unless $vec->count;
+ $vec->[VEC_BITS] = $vec->[FD_COUNT] ? $bits : undef;
+ $count;
}
sub can_read
@@ -201,7 +246,7 @@ sub can_read
my $r = $vec->[VEC_BITS];
defined($r) && (select($r,undef,undef,$timeout) > 0)
- ? _handles($vec, $r)
+ ? handles($vec, $r)
: ();
}
@@ -212,7 +257,7 @@ sub can_write
my $w = $vec->[VEC_BITS];
defined($w) && (select(undef,$w,undef,$timeout) > 0)
- ? _handles($vec, $w)
+ ? handles($vec, $w)
: ();
}
@@ -223,7 +268,7 @@ sub has_error
my $e = $vec->[VEC_BITS];
defined($e) && (select(undef,undef,$e,$timeout) > 0)
- ? _handles($vec, $e)
+ ? handles($vec, $e)
: ();
}
@@ -233,6 +278,28 @@ sub count
$vec->[FD_COUNT];
}
+sub bits
+{
+ my $vec = shift;
+ $vec->[VEC_BITS];
+}
+
+sub as_string # for debugging
+{
+ my $vec = shift;
+ my $str = ref($vec) . ": ";
+ my $bits = $vec->bits;
+ my $count = $vec->count;
+ $str .= defined($bits) ? unpack("b*", $bits) : "undef";
+ $str .= " $count";
+ my @handles = @$vec;
+ splice(@handles, 0, FIRST_FD);
+ for (@handles) {
+ $str .= " " . (defined($_) ? "$_" : "-");
+ }
+ $str;
+}
+
sub _max
{
my($a,$b,$c) = @_;
@@ -254,8 +321,8 @@ sub select
my @result = ();
my $rb = defined $r ? $r->[VEC_BITS] : undef;
- my $wb = defined $w ? $e->[VEC_BITS] : undef;
- my $eb = defined $e ? $w->[VEC_BITS] : undef;
+ my $wb = defined $w ? $w->[VEC_BITS] : undef;
+ my $eb = defined $e ? $e->[VEC_BITS] : undef;
if(select($rb,$wb,$eb,$t) > 0)
{
@@ -282,18 +349,20 @@ sub select
@result;
}
-sub _handles
+
+sub handles
{
my $vec = shift;
my $bits = shift;
my @h = ();
my $i;
+ my $max = scalar(@$vec) - 1;
- for($i = scalar(@$vec) - 1 ; $i >= FIRST_FD ; $i--)
+ for ($i = FIRST_FD; $i <= $max; $i++)
{
next unless defined $vec->[$i];
push(@h, $vec->[$i])
- if vec($bits,$i - FIRST_FD,1);
+ if !defined($bits) || vec($bits, $i - FIRST_FD, 1);
}
@h;
diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm
index 94ae88a536..6a69c6b624 100644
--- a/ext/IO/lib/IO/Socket.pm
+++ b/ext/IO/lib/IO/Socket.pm
@@ -20,13 +20,15 @@ C<IO::Socket> only defines methods for those operations which are common to all
types of socket. Operations which are specified to a socket in a particular
domain have methods defined in sub classes of C<IO::Socket>
+C<IO::Socket> will export all functions (and constants) defined by L<Socket>.
+
=head1 CONSTRUCTOR
=over 4
=item new ( [ARGS] )
-Creates a C<IO::Pipe>, which is a reference to a
+Creates a C<IO::Socket>, which is a reference to a
newly created symbol (see the C<Symbol> package). C<new>
optionally takes arguments, these arguments are in key-value pairs.
C<new> only looks for one key C<Domain> which tells new which domain
@@ -81,12 +83,12 @@ with one argument then getsockopt is called, otherwise setsockopt is called.
=item sockdomain
-Returns the numerical number for the socket domain type. For example, fir
+Returns the numerical number for the socket domain type. For example, for
a AF_INET socket the value of &AF_INET will be returned.
=item socktype
-Returns the numerical number for the socket type. For example, fir
+Returns the numerical number for the socket type. For example, for
a SOCK_STREAM socket the value of &SOCK_STREAM will be returned.
=item protocol
@@ -107,14 +109,12 @@ use IO::Handle;
use Socket 1.3;
use Carp;
use strict;
-use vars qw(@ISA @EXPORT_OK $VERSION);
+use vars qw(@ISA $VERSION);
use Exporter;
@ISA = qw(IO::Handle);
-# This one will turn 1.2 => 1.02 and 1.2.3 => 1.0203 and so on ...
-
-$VERSION = do{my @r=(q$Revision: 1.13 $=~/(\d+)/g);sprintf "%d."."%02d"x$#r,@r};
+$VERSION = "1.15";
sub import {
my $pkg = shift;
@@ -155,12 +155,13 @@ sub configure {
croak 'IO::Socket: Cannot configure a generic socket'
unless defined $domain;
- my $sub = ref(_domain2pkg($domain)) . "::configure";
+ my $class = ref(_domain2pkg($domain));
- goto &{$sub}
- if(defined &{$sub});
+ croak "IO::Socket: Cannot configure socket in domain '$domain'"
+ unless ref($fh) eq "IO::Socket";
- croak "IO::Socket: Cannot configure socket in domain '$domain' $sub";
+ bless($fh, $class);
+ $fh->configure;
}
sub socket {
@@ -366,27 +367,6 @@ sub protocol {
${*$fh}{'io_socket_protocol'};
}
-sub _addmethod {
- my $self = shift;
- my $name;
-
- foreach $name (@_) {
- my $n = $name;
-
- no strict qw(refs);
-
- *{$n} = sub {
- my $pkg = ref(${*{$_[0]}}{'io_socket_domain'});
- my $sub = "${pkg}::${n}";
- goto &{$sub} if defined &{$sub};
- croak qq{Can't locate object method "$n" via package "$pkg"};
- }
- unless defined &{$n};
- }
-
-}
-
-
=head1 SUB-CLASSES
=cut
@@ -398,14 +378,13 @@ sub _addmethod {
package IO::Socket::INET;
use strict;
-use vars qw(@ISA $VERSION);
+use vars qw(@ISA);
use Socket;
use Carp;
use Exporter;
@ISA = qw(IO::Socket);
-IO::Socket::INET->_addmethod( qw(sockaddr sockport sockhost peeraddr peerport peerhost));
IO::Socket::INET->register_domain( AF_INET );
my %socket_type = ( tcp => SOCK_STREAM,
@@ -417,22 +396,45 @@ my %socket_type = ( tcp => SOCK_STREAM,
C<IO::Socket::INET> provides a constructor to create an AF_INET domain socket
and some related methods. The constructor can take the following options
- PeerAddr Remote host address
- PeerPort Remote port or service
- LocalPort Local host bind port
- LocalAddr Local host bind address
- Proto Protocol name (eg tcp udp etc)
- Type Socket type (SOCK_STREAM etc)
+ PeerAddr Remote host address <hostname>[:<port>]
+ PeerPort Remote port or service <service>[(<no>)] | <no>
+ LocalAddr Local host bind address hostname[:port]
+ LocalPort Local host bind port <service>[(<no>)] | <no>
+ Proto Protocol name "tcp" | "udp" | ...
+ Type Socket type SOCK_STREAM | SOCK_DGRAM | ...
Listen Queue size for listen
+ Reuse Set SO_REUSEADDR before binding
Timeout Timeout value for various operations
-If Listen is defined then a listen socket is created, else if the socket
-type, which is derived from the protocol, is SOCK_STREAM then a connect
-is called.
+If C<Listen> is defined then a listen socket is created, else if the
+socket type, which is derived from the protocol, is SOCK_STREAM then
+connect() is called.
+
+The C<PeerAddr> can be a hostname or the IP-address on the
+"xx.xx.xx.xx" form. The C<PeerPort> can be a number or a symbolic
+service name. The service name might be followed by a number in
+parenthesis which is used if the service is not known by the system.
+The C<PeerPort> specification can also be embedded in the C<PeerAddr>
+by preceding it with a ":".
+
+Only one of C<Type> or C<Proto> needs to be specified, one will be
+assumed from the other. If you specify a symbolic C<PeerPort> port,
+then the constructor will try to derive C<Type> and C<Proto> from
+the service name.
-Only one of C<Type> or C<Proto> needs to be specified, one will be assumed
-from the other.
+Examples:
+
+ $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
+ PeerPort => http(80),
+ Proto => 'tcp');
+
+ $sock = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)');
+
+ $sock = IO::Socket::INET->new(Listen => 5,
+ LocalAddr => 'localhost',
+ LocalPort => 9000,
+ Proto => 'tcp');
=head2 METHODS
@@ -469,7 +471,6 @@ peer host in a text form xx.xx.xx.xx
=cut
-
sub _sock_info {
my($addr,$port,$proto) = @_;
my @proto = ();
@@ -508,7 +509,8 @@ sub _sock_info {
sub _error {
my $fh = shift;
- carp join("",ref($fh),": ",@_) if @_;
+ $@ = join("",ref($fh),": ",@_);
+ carp $@ if $^W;
close($fh)
if(defined fileno($fh));
return undef;
@@ -551,14 +553,19 @@ sub configure {
${*$fh}{'io_socket_domain'} = bless \$domain;
$fh->socket(AF_INET, $type, $proto) or
- return _error($fh);
+ return _error($fh,"$!");
+
+ if ($arg->{Reuse}) {
+ $fh->sockopt(SO_REUSEADDR,1) or
+ return _error($fh);
+ }
$fh->bind($lport || 0, $laddr) or
- return _error($fh);
+ return _error($fh,"$!");
if(exists $arg->{Listen}) {
$fh->listen($arg->{Listen} || 5) or
- return _error($fh);
+ return _error($fh,"$!");
}
else {
return _error($fh,'Cannot determine remote port')
@@ -569,7 +576,7 @@ sub configure {
unless(defined $raddr);
$fh->connect($rport,$raddr) or
- return _error($fh);
+ return _error($fh,"$!");
}
}
@@ -626,7 +633,6 @@ use Exporter;
@ISA = qw(IO::Socket);
-IO::Socket::UNIX->_addmethod(qw(hostpath peerpath));
IO::Socket::UNIX->register_domain( AF_UNIX );
=head2 IO::Socket::UNIX
@@ -645,11 +651,11 @@ and some related methods. The constructor can take the following options
=item hostpath()
-Returns the pathname to the fifo at the local end.
+Returns the pathname to the fifo at the local end
=item peerpath()
-Returns the pathanme to the fifo at the peer end.
+Returns the pathanme to the fifo at the peer end
=back
@@ -688,32 +694,22 @@ sub configure {
sub hostpath {
@_ == 1 or croak 'usage: $fh->hostpath()';
my $n = $_[0]->sockname || return undef;
-warn length($n);
(sockaddr_un($n))[0];
}
sub peerpath {
@_ == 1 or croak 'usage: $fh->peerpath()';
my $n = $_[0]->peername || return undef;
-warn length($n);
-my @n = sockaddr_un($n);
-warn join(",",@n);
(sockaddr_un($n))[0];
}
-=head1 AUTHOR
-
-Graham Barr E<lt>F<Graham.Barr@tiuk.ti.com>E<gt>
+=head1 SEE ALSO
-=head1 REVISION
+L<Socket>, L<IO::Handle>
-$Revision: 1.13 $
-
-The VERSION is derived from the revision turning each number after the
-first dot into a 2 digit number so
+=head1 AUTHOR
- Revision 1.8 => VERSION 1.08
- Revision 1.2.3 => VERSION 1.0203
+Graham Barr E<lt>F<Graham.Barr@tiuk.ti.com>E<gt>
=head1 COPYRIGHT