#! /usr/bin/perl -Tw --

use strict;
#use warnings;	#-w

use constant LOGFNAME=>"/root/hostintranet-ssht-out.log";

open LOG,">>".LOGFNAME
	or die "append: ".LOGFNAME;
my $stdout=select();
$|=1;
select LOG;
$|=1;
select $stdout;

my($nulldev ,$nullinode )=stat "/dev/null";
my($stdindev,$stdininode)=stat STDIN;
my $isnull=($nulldev==$stdindev && $nullinode==$stdininode);

sub out
{
my($msg)=@_;

	$msg="$$: $msg\n";
	print LOG $msg;
	print $msg;
}

sub outdie
{
my($msg)=@_;

	out $msg;
	die $msg;
}

out "CONNECT";
for (;;) {
	out scalar localtime(time());

	my $tmo=60;
	while ($tmo-->0) {
		sleep 1;
		next if $isnull;

		my $rfds="";
		vec($rfds,fileno(STDIN),1)=1;
		my $efds=$rfds;
		next if 1!=select $rfds,undef,$efds,0;
		my $got;
		outdie "expectfds" if vec($efds,fileno(STDIN),1);
		my $sysread;
		outdie "sysread=$sysread" if 1!=($sysread=sysread STDIN,$got,1);
		}
	}
