Server IP : 127.0.0.2 / Your IP : 3.147.75.131 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/x86_64-linux-gnu/perl/5.22/IO/ |
Upload File : |
# IO::Pipe.pm # # Copyright (c) 1996-8 Graham Barr <gbarr@pobox.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 IO::Pipe; use 5.006_001; use IO::Handle; use strict; our($VERSION); use Carp; use Symbol; $VERSION = "1.15"; sub new { my $type = shift; my $class = ref($type) || $type || "IO::Pipe"; @_ == 0 || @_ == 2 or croak "usage: $class->([READFH, WRITEFH])"; my $me = bless gensym(), $class; my($readfh,$writefh) = @_ ? @_ : $me->handles; pipe($readfh, $writefh) or return undef; @{*$me} = ($readfh, $writefh); $me; } sub handles { @_ == 1 or croak 'usage: $pipe->handles()'; (IO::Pipe::End->new(), IO::Pipe::End->new()); } my $do_spawn = $^O eq 'os2' || $^O eq 'MSWin32'; sub _doit { my $me = shift; my $rw = shift; my $pid = $do_spawn ? 0 : fork(); if($pid) { # Parent return $pid; } elsif(defined $pid) { # Child or spawn my $fh; my $io = $rw ? \*STDIN : \*STDOUT; my ($mode, $save) = $rw ? "r" : "w"; if ($do_spawn) { require Fcntl; $save = IO::Handle->new_from_fd($io, $mode); my $handle = shift; # Close in child: unless ($^O eq 'MSWin32') { fcntl($handle, Fcntl::F_SETFD(), 1) or croak "fcntl: $!"; } $fh = $rw ? ${*$me}[0] : ${*$me}[1]; } else { shift; $fh = $rw ? $me->reader() : $me->writer(); # close the other end } bless $io, "IO::Handle"; $io->fdopen($fh, $mode); $fh->close; if ($do_spawn) { $pid = eval { system 1, @_ }; # 1 == P_NOWAIT my $err = $!; $io->fdopen($save, $mode); $save->close or croak "Cannot close $!"; croak "IO::Pipe: Cannot spawn-NOWAIT: $err" if not $pid or $pid < 0; return $pid; } else { exec @_ or croak "IO::Pipe: Cannot exec: $!"; } } else { croak "IO::Pipe: Cannot fork: $!"; } # NOT Reached } sub reader { @_ >= 1 or croak 'usage: $pipe->reader( [SUB_COMMAND_ARGS] )'; my $me = shift; return undef unless(ref($me) || ref($me = $me->new)); my $fh = ${*$me}[0]; my $pid; $pid = $me->_doit(0, $fh, @_) if(@_); close ${*$me}[1]; bless $me, ref($fh); *$me = *$fh; # Alias self to handle $me->fdopen($fh->fileno,"r") unless defined($me->fileno); bless $fh; # Really wan't un-bless here ${*$me}{'io_pipe_pid'} = $pid if defined $pid; $me; } sub writer { @_ >= 1 or croak 'usage: $pipe->writer( [SUB_COMMAND_ARGS] )'; my $me = shift; return undef unless(ref($me) || ref($me = $me->new)); my $fh = ${*$me}[1]; my $pid; $pid = $me->_doit(1, $fh, @_) if(@_); close ${*$me}[0]; bless $me, ref($fh); *$me = *$fh; # Alias self to handle $me->fdopen($fh->fileno,"w") unless defined($me->fileno); bless $fh; # Really wan't un-bless here ${*$me}{'io_pipe_pid'} = $pid if defined $pid; $me; } package IO::Pipe::End; our(@ISA); @ISA = qw(IO::Handle); sub close { my $fh = shift; my $r = $fh->SUPER::close(@_); waitpid(${*$fh}{'io_pipe_pid'},0) if(defined ${*$fh}{'io_pipe_pid'}); $r; } 1; __END__