Warning : file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219
Warning : Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
PK ! z8` 8`
Time/HiRes.pmnu [ package Time::HiRes;
{ use 5.006; }
use strict;
require Exporter;
use XSLoader ();
our @ISA = qw(Exporter);
our @EXPORT = qw( );
# TODO: this list is a superset of the @names in
# Makefile.PL:doConstants(), automate this somehow.
our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval
getitimer setitimer nanosleep clock_gettime clock_getres
clock clock_nanosleep
CLOCKS_PER_SEC
CLOCK_BOOTTIME
CLOCK_HIGHRES
CLOCK_MONOTONIC
CLOCK_MONOTONIC_COARSE
CLOCK_MONOTONIC_FAST
CLOCK_MONOTONIC_PRECISE
CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW_APPROX
CLOCK_PROCESS_CPUTIME_ID
CLOCK_PROF
CLOCK_REALTIME
CLOCK_REALTIME_COARSE
CLOCK_REALTIME_FAST
CLOCK_REALTIME_PRECISE
CLOCK_REALTIME_RAW
CLOCK_SECOND
CLOCK_SOFTTIME
CLOCK_THREAD_CPUTIME_ID
CLOCK_TIMEOFDAY
CLOCK_UPTIME
CLOCK_UPTIME_COARSE
CLOCK_UPTIME_FAST
CLOCK_UPTIME_PRECISE
CLOCK_UPTIME_RAW
CLOCK_UPTIME_RAW_APPROX
CLOCK_VIRTUAL
ITIMER_PROF
ITIMER_REAL
ITIMER_REALPROF
ITIMER_VIRTUAL
TIMER_ABSTIME
d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
d_nanosleep d_clock_gettime d_clock_getres
d_clock d_clock_nanosleep d_hires_stat
d_futimens d_utimensat d_hires_utime
stat lstat utime
);
our $VERSION = '1.9758';
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
our $AUTOLOAD;
sub AUTOLOAD {
my $constname;
($constname = $AUTOLOAD) =~ s/.*:://;
# print "AUTOLOAD: constname = $constname ($AUTOLOAD)\n";
die "&Time::HiRes::constant not defined" if $constname eq 'constant';
my ($error, $val) = constant($constname);
# print "AUTOLOAD: error = $error, val = $val\n";
if ($error) {
my (undef,$file,$line) = caller;
die "$error at $file line $line.\n";
}
{
no strict 'refs';
*$AUTOLOAD = sub { $val };
}
goto &$AUTOLOAD;
}
sub import {
my $this = shift;
for my $i (@_) {
if (($i eq 'clock_getres' && !&d_clock_getres) ||
($i eq 'clock_gettime' && !&d_clock_gettime) ||
($i eq 'clock_nanosleep' && !&d_clock_nanosleep) ||
($i eq 'clock' && !&d_clock) ||
($i eq 'nanosleep' && !&d_nanosleep) ||
($i eq 'usleep' && !&d_usleep) ||
($i eq 'utime' && !&d_hires_utime) ||
($i eq 'ualarm' && !&d_ualarm)) {
require Carp;
Carp::croak("Time::HiRes::$i(): unimplemented in this platform");
}
}
Time::HiRes->export_to_level(1, $this, @_);
}
XSLoader::load( 'Time::HiRes', $XS_VERSION );
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
=head1 NAME
Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers
=head1 SYNOPSIS
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
clock_gettime clock_getres clock_nanosleep clock
stat lstat utime);
usleep ($microseconds);
nanosleep ($nanoseconds);
ualarm ($microseconds);
ualarm ($microseconds, $interval_microseconds);
$t0 = [gettimeofday];
($seconds, $microseconds) = gettimeofday;
$elapsed = tv_interval ( $t0, [$seconds, $microseconds]);
$elapsed = tv_interval ( $t0, [gettimeofday]);
$elapsed = tv_interval ( $t0 );
use Time::HiRes qw ( time alarm sleep );
$now_fractions = time;
sleep ($floating_seconds);
alarm ($floating_seconds);
alarm ($floating_seconds, $floating_interval);
use Time::HiRes qw( setitimer getitimer );
setitimer ($which, $floating_seconds, $floating_interval );
getitimer ($which);
use Time::HiRes qw( clock_gettime clock_getres clock_nanosleep
ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
ITIMER_REALPROF );
$realtime = clock_gettime(CLOCK_REALTIME);
$resolution = clock_getres(CLOCK_REALTIME);
clock_nanosleep(CLOCK_REALTIME, 1.5e9);
clock_nanosleep(CLOCK_REALTIME, time()*1e9 + 10e9, TIMER_ABSTIME);
my $ticktock = clock();
use Time::HiRes qw( stat lstat );
my @stat = stat("file");
my @stat = stat(FH);
my @stat = lstat("file");
use Time::HiRes qw( utime );
utime $floating_seconds, $floating_seconds, file...;
=head1 DESCRIPTION
The C module implements a Perl interface to the
C, C, C, C, and
C/C system calls, in other words, high
resolution time and timers. See the L section below and the
test scripts for usage; see your system documentation for the
description of the underlying C or C, C,
C, and C/C calls.
If your system lacks C or an emulation of it you don't
get C or the one-argument form of C.
If your system lacks all of C, C,
C, and C, you don't get C,
C, or C.
If your system lacks both C and C you don't get
C or C.
If you try to import an unimplemented function in the C statement
it will fail at compile time.
If your subsecond sleeping is implemented with C instead
of C, you can mix subsecond sleeping with signals since
C does not use signals. This, however, is not portable,
and you should first check for the truth value of
C<&Time::HiRes::d_nanosleep> to see whether you have nanosleep, and
then carefully read your C C API documentation for any
peculiarities.
If you are using C for something else than mixing sleeping
with signals, give some thought to whether Perl is the tool you should
be using for work requiring nanosecond accuracies.
Remember that unless you are working on a I system,
any clocks and timers will be imprecise, especially so if you are working
in a pre-emptive multiuser system. Understand the difference between
I and process time (in UNIX-like systems the sum of
I and I times). Any attempt to sleep for X seconds will
most probably end up sleeping B than that, but don't be surprised
if you end up sleeping slightly B.
The following functions can be imported from this module.
No functions are exported by default.
=over 4
=item gettimeofday ()
In array context returns a two-element array with the seconds and
microseconds since the epoch. In scalar context returns floating
seconds like C (see below).
=item usleep ( $useconds )
Sleeps for the number of microseconds (millionths of a second)
specified. Returns the number of microseconds actually slept.
Can sleep for more than one second, unlike the C system call.
Can also sleep for zero seconds, which often works like a I.
See also C, C, and
C.
Do not expect usleep() to be exact down to one microsecond.
=item nanosleep ( $nanoseconds )
Sleeps for the number of nanoseconds (1e9ths of a second) specified.
Returns the number of nanoseconds actually slept (accurate only to
microseconds, the nearest thousand of them). Can sleep for more than
one second. Can also sleep for zero seconds, which often works like
a I. See also C,
C, and C.
Do not expect nanosleep() to be exact down to one nanosecond.
Getting even accuracy of one thousand nanoseconds is good.
=item ualarm ( $useconds [, $interval_useconds ] )
Issues a C call; the C<$interval_useconds> is optional and
will be zero if unspecified, resulting in C-like behaviour.
Returns the remaining time in the alarm in microseconds, or C
if an error occurred.
ualarm(0) will cancel an outstanding ualarm().
Note that the interaction between alarms and sleeps is unspecified.
=item tv_interval
tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] )
Returns the floating seconds between the two times, which should have
been returned by C. If the second argument is omitted,
then the current time is used.
=item time ()
Returns a floating seconds since the epoch. This function can be
imported, resulting in a nice drop-in replacement for the C
provided with core Perl; see the L below.
B: This higher resolution timer can return values either less
or more than the core C, depending on whether your platform
rounds the higher resolution timer values up, down, or to the nearest second
to get the core C, but naturally the difference should be never
more than half a second. See also L, if available
in your system.
B: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when
the C seconds since epoch rolled over to 1_000_000_000, the
default floating point format of Perl and the seconds since epoch have
conspired to produce an apparent bug: if you print the value of
C you seem to be getting only five decimals, not
six as promised (microseconds). Not to worry, the microseconds are
there (assuming your platform supports such granularity in the first
place). What is going on is that the default floating point format of
Perl only outputs 15 digits. In this case that means ten digits
before the decimal separator and five after. To see the microseconds
you can use either C/C with C<"%.6f">, or the
C function in list context, which will give you the
seconds and microseconds as two separate values.
=item sleep ( $floating_seconds )
Sleeps for the specified amount of seconds. Returns the number of
seconds actually slept (a floating point value). This function can
be imported, resulting in a nice drop-in replacement for the C
provided with perl, see the L below.
Note that the interaction between alarms and sleeps is unspecified.
=item alarm ( $floating_seconds [, $interval_floating_seconds ] )
The C signal is sent after the specified number of seconds.
Implemented using C if available, C if not.
The C<$interval_floating_seconds> argument is optional and will be
zero if unspecified, resulting in C-like behaviour. This
function can be imported, resulting in a nice drop-in replacement for
the C provided with perl, see the L below.
Returns the remaining time in the alarm in seconds, or C
if an error occurred.
B: With some combinations of operating systems and Perl
releases C restarts C, instead of interrupting it.
This means that an C followed by a C may together
take the sum of the times specified for the C and the
C, not just the time of the C.
Note that the interaction between alarms and sleeps is unspecified.
=item setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] )
Start up an interval timer: after a certain time, a signal ($which) arrives,
and more signals may keep arriving at certain intervals. To disable
an "itimer", use C<$floating_seconds> of zero. If the
C<$interval_floating_seconds> is set to zero (or unspecified), the
timer is disabled B the next delivered signal.
Use of interval timers may interfere with C, C,
and C. In standard-speak the "interaction is unspecified",
which means that I may happen: it may work, it may not.
In scalar context, the remaining time in the timer is returned.
In list context, both the remaining time and the interval are returned.
There are usually three or four interval timers (signals) available: the
C<$which> can be C, C, C, or
C. Note that which ones are available depends: true
UNIX platforms usually have the first three, but only Solaris seems to
have C (which is used to profile multithreaded programs).
Win32 unfortunately does not have interval timers.
C results in C-like behaviour. Time is counted in
I; that is, wallclock time. C is delivered when
the timer expires.
C counts time in (process) I; that is,
only when the process is running. In multiprocessor/user/CPU systems
this may be more or less than real or wallclock time. (This time is
also known as the I.) C is delivered when the
timer expires.
C counts time when either the process virtual time or when
the operating system is running on behalf of the process (such as I/O).
(This time is also known as the I.) (The sum of user
time and system time is known as the I.) C is
delivered when the timer expires. C can interrupt system calls.
The semantics of interval timers for multithreaded programs are
system-specific, and some systems may support additional interval
timers. For example, it is unspecified which thread gets the signals.
See your C documentation.
=item getitimer ( $which )
Return the remaining time in the interval timer specified by C<$which>.
In scalar context, the remaining time is returned.
In list context, both the remaining time and the interval are returned.
The interval is always what you put in using C.
=item clock_gettime ( $which )
Return as seconds the current value of the POSIX high resolution timer
specified by C<$which>. All implementations that support POSIX high
resolution timers are supposed to support at least the C<$which> value
of C, which is supposed to return results close to the
results of C, or the number of seconds since 00:00:00:00
January 1, 1970 Greenwich Mean Time (GMT). Do not assume that
CLOCK_REALTIME is zero, it might be one, or something else.
Another potentially useful (but not available everywhere) value is
C, which guarantees a monotonically increasing time
value (unlike time() or gettimeofday(), which can be adjusted).
See your system documentation for other possibly supported values.
=item clock_getres ( $which )
Return as seconds the resolution of the POSIX high resolution timer
specified by C<$which>. All implementations that support POSIX high
resolution timers are supposed to support at least the C<$which> value
of C, see L.
B: the resolution returned may be highly optimistic. Even if
the resolution is high (a small number), all it means is that you'll
be able to specify the arguments to clock_gettime() and clock_nanosleep()
with that resolution. The system might not actually be able to measure
events at that resolution, and the various overheads and the overall system
load are certain to affect any timings.
=item clock_nanosleep ( $which, $nanoseconds, $flags = 0)
Sleeps for the number of nanoseconds (1e9ths of a second) specified.
Returns the number of nanoseconds actually slept. The $which is the
"clock id", as with clock_gettime() and clock_getres(). The flags
default to zero but C can specified (must be exported
explicitly) which means that C<$nanoseconds> is not a time interval
(as is the default) but instead an absolute time. Can sleep for more
than one second. Can also sleep for zero seconds, which often works
like a I. See also C,
C, and C.
Do not expect clock_nanosleep() to be exact down to one nanosecond.
Getting even accuracy of one thousand nanoseconds is good.
=item clock()
Return as seconds the I (user + system time) spent by
the process since the first call to clock() (the definition is B
"since the start of the process", though if you are lucky these times
may be quite close to each other, depending on the system). What this
means is that you probably need to store the result of your first call
to clock(), and subtract that value from the following results of clock().
The time returned also includes the process times of the terminated
child processes for which wait() has been executed. This value is
somewhat like the second value returned by the times() of core Perl,
but not necessarily identical. Note that due to backward
compatibility limitations the returned value may wrap around at about
2147 seconds or at about 36 minutes.
=item stat
=item stat FH
=item stat EXPR
=item lstat
=item lstat FH
=item lstat EXPR
As L or L
but with the access/modify/change file timestamps
in subsecond resolution, if the operating system and the filesystem
both support such timestamps. To override the standard stat():
use Time::HiRes qw(stat);
Test for the value of &Time::HiRes::d_hires_stat to find out whether
the operating system supports subsecond file timestamps: a value
larger than zero means yes. There are unfortunately no easy
ways to find out whether the filesystem supports such timestamps.
UNIX filesystems often do; NTFS does; FAT doesn't (FAT timestamp
granularity is B seconds).
A zero return value of &Time::HiRes::d_hires_stat means that
Time::HiRes::stat is a no-op passthrough for CORE::stat()
(and likewise for lstat),
and therefore the timestamps will stay integers. The same
thing will happen if the filesystem does not do subsecond timestamps,
even if the &Time::HiRes::d_hires_stat is non-zero.
In any case do not expect nanosecond resolution, or even a microsecond
resolution. Also note that the modify/access timestamps might have
different resolutions, and that they need not be synchronized, e.g.
if the operations are
write
stat # t1
read
stat # t2
the access time stamp from t2 need not be greater-than the modify
time stamp from t1: it may be equal or I.
=item utime LIST
As L
but with the ability to set the access/modify file timestamps
in subsecond resolution, if the operating system and the filesystem,
and the mount options of the filesystem, all support such timestamps.
To override the standard utime():
use Time::HiRes qw(utime);
Test for the value of &Time::HiRes::d_hires_utime to find out whether
the operating system supports setting subsecond file timestamps.
As with CORE::utime(), passing undef as both the atime and mtime will
call the syscall with a NULL argument.
The actual achievable subsecond resolution depends on the combination
of the operating system and the filesystem.
Modifying the timestamps may not be possible at all: for example, the
C filesystem mount option may prohibit you from changing the
access time timestamp.
Returns the number of files successfully changed.
=back
=head1 EXAMPLES
use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
$microseconds = 750_000;
usleep($microseconds);
# signal alarm in 2.5s & every .1s thereafter
ualarm(2_500_000, 100_000);
# cancel that ualarm
ualarm(0);
# get seconds and microseconds since the epoch
($s, $usec) = gettimeofday();
# measure elapsed time
# (could also do by subtracting 2 gettimeofday return values)
$t0 = [gettimeofday];
# do bunch of stuff here
$t1 = [gettimeofday];
# do more stuff here
$t0_t1 = tv_interval $t0, $t1;
$elapsed = tv_interval ($t0, [gettimeofday]);
$elapsed = tv_interval ($t0); # equivalent code
#
# replacements for time, alarm and sleep that know about
# floating seconds
#
use Time::HiRes;
$now_fractions = Time::HiRes::time;
Time::HiRes::sleep (2.5);
Time::HiRes::alarm (10.6666666);
use Time::HiRes qw ( time alarm sleep );
$now_fractions = time;
sleep (2.5);
alarm (10.6666666);
# Arm an interval timer to go off first at 10 seconds and
# after that every 2.5 seconds, in process virtual time
use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
$SIG{VTALRM} = sub { print time, "\n" };
setitimer(ITIMER_VIRTUAL, 10, 2.5);
use Time::HiRes qw( clock_gettime clock_getres CLOCK_REALTIME );
# Read the POSIX high resolution timer.
my $high = clock_gettime(CLOCK_REALTIME);
# But how accurate we can be, really?
my $reso = clock_getres(CLOCK_REALTIME);
use Time::HiRes qw( clock_nanosleep TIMER_ABSTIME );
clock_nanosleep(CLOCK_REALTIME, 1e6);
clock_nanosleep(CLOCK_REALTIME, 2e9, TIMER_ABSTIME);
use Time::HiRes qw( clock );
my $clock0 = clock();
... # Do something.
my $clock1 = clock();
my $clockd = $clock1 - $clock0;
use Time::HiRes qw( stat );
my ($atime, $mtime, $ctime) = (stat("istics"))[8, 9, 10];
=head1 C API
In addition to the perl API described above, a C API is available for
extension writers. The following C functions are available in the
modglobal hash:
name C prototype
--------------- ----------------------
Time::NVtime NV (*)()
Time::U2time void (*)(pTHX_ UV ret[2])
Both functions return equivalent information (like C)
but with different representations. The names C and C
were selected mainly because they are operating system independent.
(C is Unix-centric, though some platforms like Win32 and
VMS have emulations for it.)
Here is an example of using C from C:
NV (*myNVtime)(); /* Returns -1 on failure. */
SV **svp = hv_fetchs(PL_modglobal, "Time::NVtime", 0);
if (!svp) croak("Time::HiRes is required");
if (!SvIOK(*svp)) croak("Time::NVtime isn't a function pointer");
myNVtime = INT2PTR(NV(*)(), SvIV(*svp));
printf("The current time is: %" NVff "\n", (*myNVtime)());
=head1 DIAGNOSTICS
=head2 useconds or interval more than ...
In ualarm() you tried to use number of microseconds or interval (also
in microseconds) more than 1_000_000 and setitimer() is not available
in your system to emulate that case.
=head2 negative time not invented yet
You tried to use a negative time argument.
=head2 internal error: useconds < 0 (unsigned ... signed ...)
Something went horribly wrong-- the number of microseconds that cannot
become negative just became negative. Maybe your compiler is broken?
=head2 useconds or uinterval equal to or more than 1000000
In some platforms it is not possible to get an alarm with subsecond
resolution and later than one second.
=head2 unimplemented in this platform
Some calls simply aren't available, real or emulated, on every platform.
=head1 CAVEATS
Notice that the core C maybe rounding rather than truncating.
What this means is that the core C may be reporting the time
as one second later than C and C.
Adjusting the system clock (either manually or by services like ntp)
may cause problems, especially for long running programs that assume
a monotonously increasing time (note that all platforms do not adjust
time as gracefully as UNIX ntp does). For example in Win32 (and derived
platforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily
drift off from the system clock (and the original time()) by up to 0.5
seconds. Time::HiRes will notice this eventually and recalibrate.
Note that since Time::HiRes 1.77 the clock_gettime(CLOCK_MONOTONIC)
might help in this (in case your system supports CLOCK_MONOTONIC).
Some systems have APIs but not implementations: for example QNX and Haiku
have the interval timer APIs but not the functionality.
In pre-Sierra macOS (pre-10.12, OS X) clock_getres(), clock_gettime()
and clock_nanosleep() are emulated using the Mach timers; as a side
effect of being emulated the CLOCK_REALTIME and CLOCK_MONOTONIC are
the same timer.
gnukfreebsd seems to have non-functional futimens() and utimensat()
(at least as of 10.1): therefore the hires utime() does not work.
=head1 SEE ALSO
Perl modules L, L.
Your system documentation for C, C,
C, C, C, C,
C, C, C, C, C.
=head1 AUTHORS
D. Wegscheid
R. Schertler
J. Hietaniemi
G. Aas
=head1 COPYRIGHT AND LICENSE
Copyright (c) 1996-2002 Douglas E. Wegscheid. All rights reserved.
Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Jarkko Hietaniemi.
All rights reserved.
Copyright (C) 2011, 2012, 2013 Andrew Main (Zefram)
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
PK ! % IO/Tty.pmnu [ # Documentation at the __END__
# -*-cperl-*-
package IO::Tty;
use IO::Handle;
use IO::File;
use IO::Tty::Constant;
use Carp;
require POSIX;
require DynaLoader;
use vars qw(@ISA $VERSION $XS_VERSION $CONFIG $DEBUG);
$VERSION = '1.12';
$XS_VERSION = "1.12";
@ISA = qw(IO::Handle);
eval { local $^W = 0; undef local $SIG{__DIE__}; require IO::Stty };
push @ISA, "IO::Stty" if (not $@); # if IO::Stty is installed
BOOT_XS: {
# If I inherit DynaLoader then I inherit AutoLoader and I DON'T WANT TO
require DynaLoader;
# DynaLoader calls dl_load_flags as a static method.
*dl_load_flags = DynaLoader->can('dl_load_flags');
do {
defined(&bootstrap)
? \&bootstrap
: \&DynaLoader::bootstrap
}->(__PACKAGE__);
}
sub import {
IO::Tty::Constant->export_to_level(1, @_);
}
sub open {
my($tty,$dev,$mode) = @_;
IO::File::open($tty,$dev,$mode) or
return undef;
$tty->autoflush;
1;
}
sub clone_winsize_from {
my ($self, $fh) = @_;
croak "Given filehandle is not a tty in clone_winsize_from, called"
if not POSIX::isatty($fh);
return 1 if not POSIX::isatty($self); # ignored for master ptys
my $winsize = " "x1024; # preallocate memory
ioctl($fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize)
and ioctl($self, &IO::Tty::Constant::TIOCSWINSZ, $winsize)
and return 1;
warn "clone_winsize_from: error: $!" if $^W;
return undef;
}
# ioctl() doesn't tell us how long the structure is, so we'll have to trim it
# after TIOCGWINSZ
my $SIZEOF_WINSIZE = length IO::Tty::pack_winsize(0,0,0,0);
sub get_winsize {
my $self = shift;
ioctl($self, IO::Tty::Constant::TIOCGWINSZ(), my $winsize)
or croak "Cannot TIOCGWINSZ - $!";
substr($winsize, $SIZEOF_WINSIZE) = "";
return IO::Tty::unpack_winsize($winsize);
}
sub set_winsize {
my $self = shift;
my $winsize = IO::Tty::pack_winsize(@_);
ioctl($self, IO::Tty::Constant::TIOCSWINSZ(), $winsize)
or croak "Cannot TIOCSWINSZ - $!";
}
sub set_raw($) {
require POSIX;
my $self = shift;
return 1 if not POSIX::isatty($self);
my $ttyno = fileno($self);
my $termios = new POSIX::Termios;
unless ($termios) {
warn "set_raw: new POSIX::Termios failed: $!";
return undef;
}
unless ($termios->getattr($ttyno)) {
warn "set_raw: getattr($ttyno) failed: $!";
return undef;
}
$termios->setiflag(0);
$termios->setoflag(0);
$termios->setlflag(0);
$termios->setcc(&POSIX::VMIN, 1);
$termios->setcc(&POSIX::VTIME, 0);
unless ($termios->setattr($ttyno, &POSIX::TCSANOW)) {
warn "set_raw: setattr($ttyno) failed: $!";
return undef;
}
return 1;
}
1;
__END__
=head1 NAME
IO::Tty - Low-level allocate a pseudo-Tty, import constants.
=head1 VERSION
1.12
=head1 SYNOPSIS
use IO::Tty qw(TIOCNOTTY);
...
# use only to import constants, see IO::Pty to create ptys.
=head1 DESCRIPTION
C is used internally by C to create a pseudo-tty.
You wouldn't want to use it directly except to import constants, use
C. For a list of importable constants, see
L.
Windows is now supported, but ONLY under the Cygwin
environment, see L .
Please note that pty creation is very system-dependend. From my
experience, any modern POSIX system should be fine. Find below a list
of systems that C should work on. A more detailed table
(which is slowly getting out-of-date) is available from the project
pages document manager at SourceForge
L .
If you have problems on your system and your system is listed in the
"verified" list, you probably have some non-standard setup, e.g. you
compiled your Linux-kernel yourself and disabled ptys (bummer!).
Please ask your friendly sysadmin for help.
If your system is not listed, unpack the latest version of C,
do a C<'perl Makefile.PL; make; make test; uname -a'> and send me
(F) the results and I'll see what I can deduce from
that. There are chances that it will work right out-of-the-box...
If it's working on your system, please send me a short note with
details (version number, distribution, etc. 'uname -a' and 'perl -V'
is a good start; also, the output from "perl Makefile.PL" contains a
lot of interesting info, so please include that as well) so I can get
an overview. Thanks!
=head1 VERIFIED SYSTEMS, KNOWN ISSUES
This is a list of systems that C seems to work on ('make
test' passes) with comments about "features":
=over 4
=item * AIX 4.3
Returns EIO instead of EOF when the slave is closed. Benign.
=item * AIX 5.x
=item * FreeBSD 4.4
EOF on the slave tty is not reported back to the master.
=item * OpenBSD 2.8
The ioctl TIOCSCTTY sometimes fails. This is also known in
Tcl/Expect, see http://expect.nist.gov/FAQ.html
EOF on the slave tty is not reported back to the master.
=item * Darwin 7.9.0
=item * HPUX 10.20 & 11.00
EOF on the slave tty is not reported back to the master.
=item * IRIX 6.5
=item * Linux 2.2.x & 2.4.x
Returns EIO instead of EOF when the slave is closed. Benign.
=item * OSF 4.0
EOF on the slave tty is not reported back to the master.
=item * Solaris 8, 2.7, 2.6
Has the "feature" of returning EOF just once?!
EOF on the slave tty is not reported back to the master.
=item * Windows NT/2k/XP (under Cygwin)
When you send (print) a too long line (>160 chars) to a non-raw pty,
the call just hangs forever and even alarm() cannot get you out.
Don't complain to me...
EOF on the slave tty is not reported back to the master.
=item * z/OS
=back
The following systems have not been verified yet for this version, but
a previous version worked on them:
=over 4
=item * SCO Unix
=item * NetBSD
probably the same as the other *BSDs...
=back
If you have additions to these lists, please mail them to
EFE.
=head1 SEE ALSO
L, L
=head1 MAILING LISTS
As this module is mainly used by Expect, support for it is available
via the two Expect mailing lists, expectperl-announce and
expectperl-discuss, at
http://lists.sourceforge.net/lists/listinfo/expectperl-announce
and
http://lists.sourceforge.net/lists/listinfo/expectperl-discuss
=head1 AUTHORS
Originally by Graham Barr EFE, based on the
Ptty module by Nick Ing-Simmons EFE.
Now maintained and heavily rewritten by Roland Giersig
EFE.
Contains copyrighted stuff from openssh v3.0p1, authored by Tatu
Ylonen , Markus Friedl and Todd C. Miller
. I also got a lot of inspiration from
the pty code in Xemacs.
=head1 COPYRIGHT
Now all code is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Nevertheless the above AUTHORS retain their copyrights to the various
parts and want to receive credit if their source code is used.
See the source for details.
=head1 DISCLAIMER
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
In other words: Use at your own risk. Provided as is. Your mileage
may vary. Read the source, Luke!
And finally, just to be sure:
Any Use of This Product, in Any Manner Whatsoever, Will Increase the
Amount of Disorder in the Universe. Although No Liability Is Implied
Herein, the Consumer Is Warned That This Process Will Ultimately Lead
to the Heat Death of the Universe.
=cut
PK ! 읔 IO/Tty/Constant.pmnu [
package IO::Tty::Constant;
use vars qw(@ISA @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(B0 B110 B115200 B1200 B134 B150 B153600 B1800 B19200 B200 B230400 B2400 B300 B307200 B38400 B460800 B4800 B50 B57600 B600 B75 B76800 B9600 BRKINT BS0 BS1 BSDLY CBAUD CBAUDEXT CBRK CCTS_OFLOW CDEL CDSUSP CEOF CEOL CEOL2 CEOT CERASE CESC CFLUSH CIBAUD CIBAUDEXT CINTR CKILL CLNEXT CLOCAL CNSWTCH CNUL CQUIT CR0 CR1 CR2 CR3 CRDLY CREAD CRPRNT CRTSCTS CRTSXOFF CRTS_IFLOW CS5 CS6 CS7 CS8 CSIZE CSTART CSTOP CSTOPB CSUSP CSWTCH CWERASE DEFECHO DIOC DIOCGETP DIOCSETP DOSMODE ECHO ECHOCTL ECHOE ECHOK ECHOKE ECHONL ECHOPRT EXTA EXTB FF0 FF1 FFDLY FIORDCHK FLUSHO HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR IMAXBEL INLCR INPCK ISIG ISTRIP IUCLC IXANY IXOFF IXON KBENABLED LDCHG LDCLOSE LDDMAP LDEMAP LDGETT LDGMAP LDIOC LDNMAP LDOPEN LDSETT LDSMAP LOBLK NCCS NL0 NL1 NLDLY NOFLSH OCRNL OFDEL OFILL OLCUC ONLCR ONLRET ONOCR OPOST PAGEOUT PARENB PAREXT PARMRK PARODD PENDIN RCV1EN RTS_TOG TAB0 TAB1 TAB2 TAB3 TABDLY TCDSET TCFLSH TCGETA TCGETS TCIFLUSH TCIOFF TCIOFLUSH TCION TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW TCSBRK TCSETA TCSETAF TCSETAW TCSETCTTY TCSETS TCSETSF TCSETSW TCXONC TERM_D40 TERM_D42 TERM_H45 TERM_NONE TERM_TEC TERM_TEX TERM_V10 TERM_V61 TIOCCBRK TIOCCDTR TIOCCONS TIOCEXCL TIOCFLUSH TIOCGETD TIOCGETC TIOCGETP TIOCGLTC TIOCSETC TIOCSETN TIOCSETP TIOCSLTC TIOCGPGRP TIOCGSID TIOCGSOFTCAR TIOCGWINSZ TIOCHPCL TIOCKBOF TIOCKBON TIOCLBIC TIOCLBIS TIOCLGET TIOCLSET TIOCMBIC TIOCMBIS TIOCMGET TIOCMSET TIOCM_CAR TIOCM_CD TIOCM_CTS TIOCM_DSR TIOCM_DTR TIOCM_LE TIOCM_RI TIOCM_RNG TIOCM_RTS TIOCM_SR TIOCM_ST TIOCNOTTY TIOCNXCL TIOCOUTQ TIOCREMOTE TIOCSBRK TIOCSCTTY TIOCSDTR TIOCSETD TIOCSIGNAL TIOCSPGRP TIOCSSID TIOCSSOFTCAR TIOCSTART TIOCSTI TIOCSTOP TIOCSWINSZ TM_ANL TM_CECHO TM_CINVIS TM_LCF TM_NONE TM_SET TM_SNL TOSTOP VCEOF VCEOL VDISCARD VDSUSP VEOF VEOL VEOL2 VERASE VINTR VKILL VLNEXT VMIN VQUIT VREPRINT VSTART VSTOP VSUSP VSWTCH VT0 VT1 VTDLY VTIME VWERASE WRAP XCASE XCLUDE XMT1EN XTABS);
__END__
=head1 NAME
IO::Tty::Constant - Terminal Constants (autogenerated)
=head1 SYNOPSIS
use IO::Tty::Constant qw(TIOCNOTTY);
...
=head1 DESCRIPTION
This package defines constants usually found in or
(and their #include hierarchy). Find below an
autogenerated alphabetic list of all known constants and whether they
are defined on your system (prefixed with '+') and have compilation
problems ('o'). Undefined or problematic constants are set to 'undef'.
=head1 DEFINED CONSTANTS
=item +
B0
=item +
B110
=item +
B115200
=item +
B1200
=item +
B134
=item +
B150
=item -
B153600
=item +
B1800
=item +
B19200
=item +
B200
=item +
B230400
=item +
B2400
=item +
B300
=item -
B307200
=item +
B38400
=item +
B460800
=item +
B4800
=item +
B50
=item +
B57600
=item +
B600
=item +
B75
=item -
B76800
=item +
B9600
=item +
BRKINT
=item +
BS0
=item +
BS1
=item +
BSDLY
=item +
CBAUD
=item -
CBAUDEXT
=item +
CBRK
=item -
CCTS_OFLOW
=item -
CDEL
=item +
CDSUSP
=item +
CEOF
=item +
CEOL
=item -
CEOL2
=item +
CEOT
=item +
CERASE
=item -
CESC
=item +
CFLUSH
=item +
CIBAUD
=item -
CIBAUDEXT
=item +
CINTR
=item +
CKILL
=item +
CLNEXT
=item +
CLOCAL
=item -
CNSWTCH
=item -
CNUL
=item +
CQUIT
=item +
CR0
=item +
CR1
=item +
CR2
=item +
CR3
=item +
CRDLY
=item +
CREAD
=item +
CRPRNT
=item +
CRTSCTS
=item -
CRTSXOFF
=item -
CRTS_IFLOW
=item +
CS5
=item +
CS6
=item +
CS7
=item +
CS8
=item +
CSIZE
=item +
CSTART
=item +
CSTOP
=item +
CSTOPB
=item +
CSUSP
=item -
CSWTCH
=item +
CWERASE
=item -
DEFECHO
=item -
DIOC
=item -
DIOCGETP
=item -
DIOCSETP
=item -
DOSMODE
=item +
ECHO
=item +
ECHOCTL
=item +
ECHOE
=item +
ECHOK
=item +
ECHOKE
=item +
ECHONL
=item +
ECHOPRT
=item +
EXTA
=item +
EXTB
=item +
FF0
=item +
FF1
=item +
FFDLY
=item -
FIORDCHK
=item +
FLUSHO
=item +
HUPCL
=item +
ICANON
=item +
ICRNL
=item +
IEXTEN
=item +
IGNBRK
=item +
IGNCR
=item +
IGNPAR
=item +
IMAXBEL
=item +
INLCR
=item +
INPCK
=item +
ISIG
=item +
ISTRIP
=item +
IUCLC
=item +
IXANY
=item +
IXOFF
=item +
IXON
=item -
KBENABLED
=item -
LDCHG
=item -
LDCLOSE
=item -
LDDMAP
=item -
LDEMAP
=item -
LDGETT
=item -
LDGMAP
=item -
LDIOC
=item -
LDNMAP
=item -
LDOPEN
=item -
LDSETT
=item -
LDSMAP
=item -
LOBLK
=item +
NCCS
=item +
NL0
=item +
NL1
=item +
NLDLY
=item +
NOFLSH
=item +
OCRNL
=item +
OFDEL
=item +
OFILL
=item +
OLCUC
=item +
ONLCR
=item +
ONLRET
=item +
ONOCR
=item +
OPOST
=item -
PAGEOUT
=item +
PARENB
=item -
PAREXT
=item +
PARMRK
=item +
PARODD
=item +
PENDIN
=item -
RCV1EN
=item -
RTS_TOG
=item +
TAB0
=item +
TAB1
=item +
TAB2
=item +
TAB3
=item +
TABDLY
=item -
TCDSET
=item +
TCFLSH
=item +
TCGETA
=item +
TCGETS
=item +
TCIFLUSH
=item +
TCIOFF
=item +
TCIOFLUSH
=item +
TCION
=item +
TCOFLUSH
=item +
TCOOFF
=item +
TCOON
=item +
TCSADRAIN
=item +
TCSAFLUSH
=item +
TCSANOW
=item +
TCSBRK
=item +
TCSETA
=item +
TCSETAF
=item +
TCSETAW
=item -
TCSETCTTY
=item +
TCSETS
=item +
TCSETSF
=item +
TCSETSW
=item +
TCXONC
=item -
TERM_D40
=item -
TERM_D42
=item -
TERM_H45
=item -
TERM_NONE
=item -
TERM_TEC
=item -
TERM_TEX
=item -
TERM_V10
=item -
TERM_V61
=item +
TIOCCBRK
=item -
TIOCCDTR
=item +
TIOCCONS
=item +
TIOCEXCL
=item -
TIOCFLUSH
=item +
TIOCGETD
=item -
TIOCGETC
=item -
TIOCGETP
=item -
TIOCGLTC
=item -
TIOCSETC
=item -
TIOCSETN
=item -
TIOCSETP
=item -
TIOCSLTC
=item +
TIOCGPGRP
=item +
TIOCGSID
=item +
TIOCGSOFTCAR
=item +
TIOCGWINSZ
=item -
TIOCHPCL
=item -
TIOCKBOF
=item -
TIOCKBON
=item -
TIOCLBIC
=item -
TIOCLBIS
=item -
TIOCLGET
=item -
TIOCLSET
=item +
TIOCMBIC
=item +
TIOCMBIS
=item +
TIOCMGET
=item +
TIOCMSET
=item +
TIOCM_CAR
=item +
TIOCM_CD
=item +
TIOCM_CTS
=item +
TIOCM_DSR
=item +
TIOCM_DTR
=item +
TIOCM_LE
=item +
TIOCM_RI
=item +
TIOCM_RNG
=item +
TIOCM_RTS
=item +
TIOCM_SR
=item +
TIOCM_ST
=item +
TIOCNOTTY
=item +
TIOCNXCL
=item +
TIOCOUTQ
=item -
TIOCREMOTE
=item +
TIOCSBRK
=item +
TIOCSCTTY
=item -
TIOCSDTR
=item +
TIOCSETD
=item -
TIOCSIGNAL
=item +
TIOCSPGRP
=item -
TIOCSSID
=item +
TIOCSSOFTCAR
=item -
TIOCSTART
=item +
TIOCSTI
=item -
TIOCSTOP
=item +
TIOCSWINSZ
=item -
TM_ANL
=item -
TM_CECHO
=item -
TM_CINVIS
=item -
TM_LCF
=item -
TM_NONE
=item -
TM_SET
=item -
TM_SNL
=item +
TOSTOP
=item -
VCEOF
=item -
VCEOL
=item +
VDISCARD
=item -
VDSUSP
=item +
VEOF
=item +
VEOL
=item +
VEOL2
=item +
VERASE
=item +
VINTR
=item +
VKILL
=item +
VLNEXT
=item +
VMIN
=item +
VQUIT
=item +
VREPRINT
=item +
VSTART
=item +
VSTOP
=item +
VSUSP
=item -
VSWTCH
=item +
VT0
=item +
VT1
=item +
VTDLY
=item +
VTIME
=item +
VWERASE
=item -
WRAP
=item +
XCASE
=item -
XCLUDE
=item -
XMT1EN
=item +
XTABS
=head1 FOR MORE INFO SEE
L
=cut
PK ! Kg# # IO/Pty.pmnu [ # Documentation at the __END__
package IO::Pty;
use strict;
use Carp;
use IO::Tty qw(TIOCSCTTY TCSETCTTY TIOCNOTTY);
use IO::File;
require POSIX;
use vars qw(@ISA $VERSION);
$VERSION = '1.12'; # keep same as in Tty.pm
@ISA = qw(IO::Handle);
eval { local $^W = 0; undef local $SIG{__DIE__}; require IO::Stty };
push @ISA, "IO::Stty" if (not $@); # if IO::Stty is installed
sub new {
my ($class) = $_[0] || "IO::Pty";
$class = ref($class) if ref($class);
@_ <= 1 or croak 'usage: new $class';
my ($ptyfd, $ttyfd, $ttyname) = pty_allocate();
croak "Cannot open a pty" if not defined $ptyfd;
my $pty = $class->SUPER::new_from_fd($ptyfd, "r+");
croak "Cannot create a new $class from fd $ptyfd: $!" if not $pty;
$pty->autoflush(1);
bless $pty => $class;
my $slave = IO::Tty->new_from_fd($ttyfd, "r+");
croak "Cannot create a new IO::Tty from fd $ttyfd: $!" if not $slave;
$slave->autoflush(1);
${*$pty}{'io_pty_slave'} = $slave;
${*$pty}{'io_pty_ttyname'} = $ttyname;
${*$slave}{'io_tty_ttyname'} = $ttyname;
return $pty;
}
sub ttyname {
@_ == 1 or croak 'usage: $pty->ttyname();';
my $pty = shift;
${*$pty}{'io_pty_ttyname'};
}
sub close_slave {
@_ == 1 or croak 'usage: $pty->close_slave();';
my $master = shift;
if (exists ${*$master}{'io_pty_slave'}) {
close ${*$master}{'io_pty_slave'};
delete ${*$master}{'io_pty_slave'};
}
}
sub slave {
@_ == 1 or croak 'usage: $pty->slave();';
my $master = shift;
if (exists ${*$master}{'io_pty_slave'}) {
return ${*$master}{'io_pty_slave'};
}
my $tty = ${*$master}{'io_pty_ttyname'};
my $slave = new IO::Tty;
$slave->open($tty, O_RDWR | O_NOCTTY) ||
croak "Cannot open slave $tty: $!";
return $slave;
}
sub make_slave_controlling_terminal {
@_ == 1 or croak 'usage: $pty->make_slave_controlling_terminal();';
my $self = shift;
local(*DEVTTY);
# loose controlling terminal explicitly
if (defined TIOCNOTTY) {
if (open (\*DEVTTY, "/dev/tty")) {
ioctl( \*DEVTTY, TIOCNOTTY, 0 );
close \*DEVTTY;
}
}
# Create a new 'session', lose controlling terminal.
if (not POSIX::setsid()) {
warn "setsid() failed, strange behavior may result: $!\r\n" if $^W;
}
if (open(\*DEVTTY, "/dev/tty")) {
warn "Could not disconnect from controlling terminal?!\n" if $^W;
close \*DEVTTY;
}
# now open slave, this should set it as controlling tty on some systems
my $ttyname = ${*$self}{'io_pty_ttyname'};
my $slv = new IO::Tty;
$slv->open($ttyname, O_RDWR)
or croak "Cannot open slave $ttyname: $!";
if (not exists ${*$self}{'io_pty_slave'}) {
${*$self}{'io_pty_slave'} = $slv;
} else {
$slv->close;
}
# Acquire a controlling terminal if this doesn't happen automatically
if (not open(\*DEVTTY, "/dev/tty")) {
if (defined TIOCSCTTY) {
if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
warn "warning: TIOCSCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
}
} elsif (defined TCSETCTTY) {
if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
warn "warning: TCSETCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
}
} else {
warn "warning: You have neither TIOCSCTTY nor TCSETCTTY on your system\n" if $^W;
return 0;
}
}
if (not open(\*DEVTTY, "/dev/tty")) {
warn "Error: could not connect pty as controlling terminal!\n";
return undef;
} else {
close \*DEVTTY;
}
return 1;
}
*clone_winsize_from = \&IO::Tty::clone_winsize_from;
*get_winsize = \&IO::Tty::get_winsize;
*set_winsize = \&IO::Tty::set_winsize;
*set_raw = \&IO::Tty::set_raw;
1;
__END__
=head1 NAME
IO::Pty - Pseudo TTY object class
=head1 VERSION
1.12
=head1 SYNOPSIS
use IO::Pty;
$pty = new IO::Pty;
$slave = $pty->slave;
foreach $val (1..10) {
print $pty "$val\n";
$_ = <$slave>;
print "$_";
}
close($slave);
=head1 DESCRIPTION
C provides an interface to allow the creation of a pseudo tty.
C inherits from C and so provide all the methods
defined by the C package.
Please note that pty creation is very system-dependend. If you have
problems, see L for help.
=head1 CONSTRUCTOR
=over 3
=item new
The C constructor takes no arguments and returns a new file
object which is the master side of the pseudo tty.
=back
=head1 METHODS
=over 4
=item ttyname()
Returns the name of the slave pseudo tty. On UNIX machines this will
be the pathname of the device. Use this name for informational
purpose only, to get a slave filehandle, use slave().
=item slave()
The C method will return the slave filehandle of the given
master pty, opening it anew if necessary. If IO::Stty is installed,
you can then call C<$slave-Estty()> to modify the terminal settings.
=item close_slave()
The slave filehandle will be closed and destroyed. This is necessary
in the parent after forking to get rid of the open filehandle,
otherwise the parent will not notice if the child exits. Subsequent
calls of C will return a newly opened slave filehandle.
=item make_slave_controlling_terminal()
This will set the slave filehandle as the controlling terminal of the
current process, which will become a session leader, so this should
only be called by a child process after a fork(), e.g. in the callback
to C (see L). See the C script
(also C) for an example how to correctly spawn a subprocess.
=item set_raw()
Will set the pty to raw. Note that this is a one-way operation, you
need IO::Stty to set the terminal settings to anything else.
On some systems, the master pty is not a tty. This method checks for
that and returns success anyway on such systems. Note that this
method must be called on the slave, and probably should be called on
the master, just to be sure, i.e.
$pty->slave->set_raw();
$pty->set_raw();
=item clone_winsize_from(\*FH)
Gets the terminal size from filehandle FH (which must be a terminal)
and transfers it to the pty. Returns true on success and undef on
failure. Note that this must be called upon the I, i.e.
$pty->slave->clone_winsize_from(\*STDIN);
On some systems, the master pty also isatty. I actually have no
idea if setting terminal sizes there is passed through to the slave,
so if this method is called for a master that is not a tty, it
silently returns OK.
See the C script for example code how to propagate SIGWINCH.
=item get_winsize()
Returns the terminal size, in a 4-element list.
($row, $col, $xpixel, $ypixel) = $tty->get_winsize()
=item set_winsize($row, $col, $xpixel, $ypixel)
Sets the terminal size. If not specified, C<$xpixel> and C<$ypixel> are set to
0. As with C, this must be called upon the I.
=back
=head1 SEE ALSO
L, L, L, L, L
=head1 MAILING LISTS
As this module is mainly used by Expect, support for it is available
via the two Expect mailing lists, expectperl-announce and
expectperl-discuss, at
http://lists.sourceforge.net/lists/listinfo/expectperl-announce
and
http://lists.sourceforge.net/lists/listinfo/expectperl-discuss
=head1 AUTHORS
Originally by Graham Barr EFE, based on the
Ptty module by Nick Ing-Simmons EFE.
Now maintained and heavily rewritten by Roland Giersig
EFE.
Contains copyrighted stuff from openssh v3.0p1, authored by
Tatu Ylonen , Markus Friedl and Todd C. Miller
.
=head1 COPYRIGHT
Now all code is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Nevertheless the above AUTHORS retain their copyrights to the various
parts and want to receive credit if their source code is used.
See the source for details.
=head1 DISCLAIMER
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
In other words: Use at your own risk. Provided as is. Your mileage
may vary. Read the source, Luke!
And finally, just to be sure:
Any Use of This Product, in Any Manner Whatsoever, Will Increase the
Amount of Disorder in the Universe. Although No Liability Is Implied
Herein, the Consumer Is Warned That This Process Will Ultimately Lead
to the Heat Death of the Universe.
=cut
PK ! k(Ɛ Ɛ Socket.pmnu [ package Socket;
use strict;
{ use 5.006001; }
our $VERSION = '2.027';
=head1 NAME
C - networking constants and support functions
=head1 SYNOPSIS
C a low-level module used by, among other things, the L
family of modules. The following examples demonstrate some low-level uses but
a practical program would likely use the higher-level API provided by
C or similar instead.
use Socket qw(PF_INET SOCK_STREAM pack_sockaddr_in inet_aton);
socket(my $socket, PF_INET, SOCK_STREAM, 0)
or die "socket: $!";
my $port = getservbyname "echo", "tcp";
connect($socket, pack_sockaddr_in($port, inet_aton("localhost")))
or die "connect: $!";
print $socket "Hello, world!\n";
print <$socket>;
See also the L section.
=head1 DESCRIPTION
This module provides a variety of constants, structure manipulators and other
functions related to socket-based networking. The values and functions
provided are useful when used in conjunction with Perl core functions such as
socket(), setsockopt() and bind(). It also provides several other support
functions, mostly for dealing with conversions of network addresses between
human-readable and native binary forms, and for hostname resolver operations.
Some constants and functions are exported by default by this module; but for
backward-compatibility any recently-added symbols are not exported by default
and must be requested explicitly. When an import list is provided to the
C line, the default exports are not automatically imported. It is
therefore best practice to always to explicitly list all the symbols required.
Also, some common socket "newline" constants are provided: the constants
C, C, and C, as well as C<$CR>, C<$LF>, and C<$CRLF>, which map
to C<\015>, C<\012>, and C<\015\012>. If you do not want to use the literal
characters in your programs, then use the constants provided here. They are
not exported by default, but can be imported individually, and with the
C<:crlf> export tag:
use Socket qw(:DEFAULT :crlf);
$sock->print("GET / HTTP/1.0$CRLF");
The entire getaddrinfo() subsystem can be exported using the tag C<:addrinfo>;
this exports the getaddrinfo() and getnameinfo() functions, and all the
C, C, C and C constants.
=cut
=head1 CONSTANTS
In each of the following groups, there may be many more constants provided
than just the ones given as examples in the section heading. If the heading
ends C<...> then this means there are likely more; the exact constants
provided will depend on the OS and headers found at compile-time.
=cut
=head2 PF_INET, PF_INET6, PF_UNIX, ...
Protocol family constants to use as the first argument to socket() or the
value of the C or C socket option.
=head2 AF_INET, AF_INET6, AF_UNIX, ...
Address family constants used by the socket address structures, to pass to
such functions as inet_pton() or getaddrinfo(), or are returned by such
functions as sockaddr_family().
=head2 SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...
Socket type constants to use as the second argument to socket(), or the value
of the C socket option.
=head2 SOCK_NONBLOCK. SOCK_CLOEXEC
Linux-specific shortcuts to specify the C and C flags
during a C call.
socket( my $sockh, PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, 0 )
=head2 SOL_SOCKET
Socket option level constant for setsockopt() and getsockopt().
=head2 SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...
Socket option name constants for setsockopt() and getsockopt() at the
C level.
=head2 IP_OPTIONS, IP_TOS, IP_TTL, ...
Socket option name constants for IPv4 socket options at the C
level.
=head2 IP_PMTUDISC_WANT, IP_PMTUDISC_DONT, ...
Socket option value contants for C socket option.
=head2 IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...
Socket option value constants for C socket option.
=head2 MSG_BCAST, MSG_OOB, MSG_TRUNC, ...
Message flag constants for send() and recv().
=head2 SHUT_RD, SHUT_RDWR, SHUT_WR
Direction constants for shutdown().
=head2 INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE
Constants giving the special C addresses for wildcard, broadcast,
local loopback, and invalid addresses.
Normally equivalent to inet_aton('0.0.0.0'), inet_aton('255.255.255.255'),
inet_aton('localhost') and inet_aton('255.255.255.255') respectively.
=head2 IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, ...
IP protocol constants to use as the third argument to socket(), the level
argument to getsockopt() or setsockopt(), or the value of the C
socket option.
=head2 TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...
Socket option name constants for TCP socket options at the C
level.
=head2 IN6ADDR_ANY, IN6ADDR_LOOPBACK
Constants giving the special C addresses for wildcard and local
loopback.
Normally equivalent to inet_pton(AF_INET6, "::") and
inet_pton(AF_INET6, "::1") respectively.
=head2 IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...
Socket option name constants for IPv6 socket options at the C
level.
=cut
# Still undocumented: SCM_*, SOMAXCONN, IOV_MAX, UIO_MAXIOV
=head1 STRUCTURE MANIPULATORS
The following functions convert between lists of Perl values and packed binary
strings representing structures.
=cut
=head2 $family = sockaddr_family $sockaddr
Takes a packed socket address (as returned by pack_sockaddr_in(),
pack_sockaddr_un() or the perl builtin functions getsockname() and
getpeername()). Returns the address family tag. This will be one of the
C constants, such as C for a C addresses or
C for a C. It can be used to figure out what unpack to
use for a sockaddr of unknown type.
=head2 $sockaddr = pack_sockaddr_in $port, $ip_address
Takes two arguments, a port number and an opaque string (as returned by
inet_aton(), or a v-string). Returns the C structure with those
arguments packed in and C filled in. For Internet domain sockets,
this structure is normally what you need for the arguments in bind(),
connect(), and send().
An undefined $port argument is taken as zero; an undefined $ip_address is
considered a fatal error.
=head2 ($port, $ip_address) = unpack_sockaddr_in $sockaddr
Takes a C structure (as returned by pack_sockaddr_in(),
getpeername() or recv()). Returns a list of two elements: the port and an
opaque string representing the IP address (you can use inet_ntoa() to convert
the address to the four-dotted numeric format). Will croak if the structure
does not represent an C address.
In scalar context will return just the IP address.
=head2 $sockaddr = sockaddr_in $port, $ip_address
=head2 ($port, $ip_address) = sockaddr_in $sockaddr
A wrapper of pack_sockaddr_in() or unpack_sockaddr_in(). In list context,
unpacks its argument and returns a list consisting of the port and IP address.
In scalar context, packs its port and IP address arguments as a C
and returns it.
Provided largely for legacy compatibility; it is better to use
pack_sockaddr_in() or unpack_sockaddr_in() explicitly.
=head2 $sockaddr = pack_sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]
Takes two to four arguments, a port number, an opaque string (as returned by
inet_pton()), optionally a scope ID number, and optionally a flow label
number. Returns the C structure with those arguments packed in
and C filled in. IPv6 equivalent of pack_sockaddr_in().
An undefined $port argument is taken as zero; an undefined $ip6_address is
considered a fatal error.
=head2 ($port, $ip6_address, $scope_id, $flowinfo) = unpack_sockaddr_in6 $sockaddr
Takes a C structure. Returns a list of four elements: the port
number, an opaque string representing the IPv6 address, the scope ID, and the
flow label. (You can use inet_ntop() to convert the address to the usual
string format). Will croak if the structure does not represent an C
address.
In scalar context will return just the IP address.
=head2 $sockaddr = sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]
=head2 ($port, $ip6_address, $scope_id, $flowinfo) = sockaddr_in6 $sockaddr
A wrapper of pack_sockaddr_in6() or unpack_sockaddr_in6(). In list context,
unpacks its argument according to unpack_sockaddr_in6(). In scalar context,
packs its arguments according to pack_sockaddr_in6().
Provided largely for legacy compatibility; it is better to use
pack_sockaddr_in6() or unpack_sockaddr_in6() explicitly.
=head2 $sockaddr = pack_sockaddr_un $path
Takes one argument, a pathname. Returns the C structure with that
path packed in with C filled in. For C sockets, this
structure is normally what you need for the arguments in bind(), connect(),
and send().
=head2 ($path) = unpack_sockaddr_un $sockaddr
Takes a C structure (as returned by pack_sockaddr_un(),
getpeername() or recv()). Returns a list of one element: the pathname. Will
croak if the structure does not represent an C address.
=head2 $sockaddr = sockaddr_un $path
=head2 ($path) = sockaddr_un $sockaddr
A wrapper of pack_sockaddr_un() or unpack_sockaddr_un(). In a list context,
unpacks its argument and returns a list consisting of the pathname. In a
scalar context, packs its pathname as a C