diff options
author | Perl 5 Porters <perl5-porters@africa.nicoh.com> | 1996-12-20 11:14:00 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1996-12-20 11:14:00 +1200 |
commit | 7e1af8bca57f405a8444b575a870918a6d88fc5c (patch) | |
tree | b443adc34d8d77831bf947076abd5770335592cf /lib/Net/DummyInetd.pm | |
parent | 7f3dfc00eaef7e421633b2b47af9963dbc626e75 (diff) | |
download | perl-7e1af8bca57f405a8444b575a870918a6d88fc5c.tar.gz |
[inseparable changes from patch from perl5.003_12 to perl5.003_13]
DOCUMENTATION
Subject: small doc tweaks for _12
Date: Thu, 19 Dec 1996 11:05:57 -0500
From: Roderick Schertler <roderick@gate.net>
Files: lib/UNIVERSAL.pm pod/perldiag.pod pod/perltie.pod
Msg-ID: <1826.851011557@eeyore.ibcinc.com>
(applied based on p5p patch as commit 3314ffc68a11690bd9977cbdd7ea0601ad6ced13)
PORTABILITY
Subject: Add missing backslash in Configure
From: Chip Salzenberg <chip@atlantic.net>
Files: Configure
UTILITIES, LIBRARY, AND EXTENSIONS
Subject: Include libnet-1.01 instead of old Net::FTP
From: Graham Barr <Graham.Barr@tiuk.ti.com>
Files: MANIFEST lib/Net/Cmd.pm lib/Net/Domain.pm lib/Net/DummyInetd.pm lib/Net/FTP.pm lib/Net/NNTP.pm lib/Net/Netrc.pm lib/Net/POP3.pm lib/Net/SMTP.pm lib/Net/SNPP.pm lib/Net/Socket.pm lib/Net/Telnet.pm lib/Net/Time.pm pod/perlmod.pod
Subject: Use binmode when doing binary FTP
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Files: lib/Net/FTP.pm
Subject: Re: Open3.pm tries to close unopened file handle
Date: 18 Dec 1996 22:19:54 -0500
From: Roderick Schertler <roderick@gate.net>
Files: MANIFEST lib/IPC/Open2.pm lib/IPC/Open3.pm lib/open2.pl lib/open3.pl pod/perldiag.pod pod/perlfunc.pod t/lib/open2.t t/lib/open3.t
Msg-ID: <pzloavmd9h.fsf@eeyore.ibcinc.com>
(applied based on p5p patch as commit 982b4e8fc47473059e209787b589853f4c8f8f9e)
Subject: Long-standing problem in Socket module
Date: Wed, 18 Dec 1996 23:18:14 -0500
From: Spider Boardman <spider@orb.nashua.nh.us>
Files: Configure Porting/Glossary config_H config_h.SH ext/Socket/Socket.pm ext/Socket/Socket.xs
Msg-ID: <199612190418.XAA07291@Orb.Nashua.NH.US>
(applied based on p5p patch as commit 3e6a22d2723daf415793f9a4fc1b57f4d8a576fd)
Subject: flock() constants
Date: Thu, 19 Dec 1996 01:37:17 -0500
From: Roderick Schertler <roderick@gate.net>
Files: ext/Fcntl/Fcntl.pm ext/Fcntl/Fcntl.xs pod/perlfunc.pod
Msg-ID: <26669.850977437@eeyore.ibcinc.com>
(applied based on p5p patch as commit 3dea0e15e4684f6defe2f25a16bc696b96697ac2)
Diffstat (limited to 'lib/Net/DummyInetd.pm')
-rw-r--r-- | lib/Net/DummyInetd.pm | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/lib/Net/DummyInetd.pm b/lib/Net/DummyInetd.pm new file mode 100644 index 0000000000..8dddc901e6 --- /dev/null +++ b/lib/Net/DummyInetd.pm @@ -0,0 +1,156 @@ +# Net::DummyInetd.pm +# +# Copyright (c) 1995 Graham Barr <Graham.Barr@tiuk.ti.com>. All rights +# reserved. This program is free software; you can redistribute it and/or +# modify it under the same terms as Perl itself. + +package Net::DummyInetd; + +=head1 NAME + +Net::DummyInetd - A dummy Inetd server + +=head1 SYNOPSIS + + use Net::DummyInetd; + use Net::SMTP; + + $inetd = new Net::DummyInetd qw(/usr/lib/sendmail -ba -bs); + + $smtp = Net::SMTP->new('localhost', Port => $inetd->port); + +=head1 DESCRIPTION + +C<Net::DummyInetd> is just what it's name says, it is a dummy inetd server. +Creation of a C<Net::DummyInetd> will cause a child process to be spawned off +which will listen to a socket. When a connection arrives on this socket +the specified command is fork'd and exec'd with STDIN and STDOUT file +descriptors duplicated to the new socket. + +This package was added as an example of how to use C<Net::SMTP> to connect +to a C<sendmail> process, which is not the default, via SIDIN and STDOUT. +A C<Net::Inetd> package will be avaliable in the next release of C<libnet> + +=head1 CONSTRUCTOR + +=over 4 + +=item new ( CMD ) + +Creates a new object and spawns a child process which listens to a socket. +C<CMD> is a list, which will be passed to C<exec> when a new process needs +to be created. + +=back + +=head1 METHODS + +=over 4 + +=item port + +Returns the port number on which the I<DummyInet> object is listening + +=back + +=head1 AUTHOR + +Graham Barr <Graham.Barr@tiuk.ti.com> + +=head1 REVISION + +$Revision: 1.2 $ + +The VERSION is derived from the revision by changing each number after the +first dot into a 2 digit number so + + Revision 1.8 => VERSION 1.08 + Revision 1.2.3 => VERSION 1.0203 + +=head1 COPYRIGHT + +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. + +=cut + +require 5.002; + +use IO::Handle; +use IO::Socket; +use strict; +use vars qw($VERSION); +use Carp; + +$VERSION = do{my @r=(q$Revision: 1.2 $=~/(\d+)/g);sprintf "%d."."%02d"x$#r,@r}; + + +sub _process +{ + my $listen = shift; + my @cmd = @_; + my $vec = ''; + my $r; + + vec($vec,fileno($listen),1) = 1; + + while(select($r=$vec,undef,undef,undef)) + { + my $sock = $listen->accept; + my $pid; + + if($pid = fork()) + { + sleep 1; + close($sock); + } + elsif(defined $pid) + { + my $x = IO::Handle->new_from_fd($sock,"r"); + open(STDIN,"<&=".fileno($x)) || die "$! $@"; + close($x); + + my $y = IO::Handle->new_from_fd($sock,"w"); + open(STDOUT,">&=".fileno($y)) || die "$! $@"; + close($y); + + close($sock); + exec(@cmd) || carp "$! $@"; + } + else + { + close($sock); + carp $!; + } + } + exit -1; +} + +sub new +{ + my $self = shift; + my $type = ref($self) || $self; + + my $listen = IO::Socket::INET->new(Listen => 5, Proto => 'tcp'); + my $pid; + + return bless [ $listen->sockport, $pid ] + if($pid = fork()); + + _process($listen,@_); +} + +sub port +{ + my $self = shift; + $self->[0]; +} + +sub DESTROY +{ + my $self = shift; + kill 9, $self->[1]; +} + +1; |