Thanks a lot for your help. Finally i solved it, mixing a little of everything. Maybe i should say before that i'm doing this in order to unit test a class wich will comunicate with Asterisk and get audio from EAGI interface wich writes the audio in fd=3.
use strict;
use warnings;
use IO::Handle;
use IO::File;
my $ftmp = new IO::File ("test_eagi.tmp",'r+');
unless ( defined $ftmp)
{
die "Couldn't open (test_eagi.tmp)\n";
}
if ( fileno($ftmp) == 3 )
{
print "open file with fd 3\n";
}
else
{
die "ERROR: file opened with fd : ".fileno($ftmp)."\n";
}
$| = 1;
$ftmp->autoflush(1);
my $fh_in = new IO::Handle;
my $fh_out = new IO::Handle;
my $buff;
my $blen = 10;
$fh_out->fdopen(3,'r') || die "No se pudo abrir fh_out\n$!\n";
#$fh_out->autoflush(1);
$fh_in->autoflush(1);
my $data_a = 'a'x10;
my $data_b = 'b'x20;
print "data a: ($data_a)\n";
print "data b: ($data_b)\n";
tswrite($data_a,10);
tsread();
tswrite($data_b,20);
tsread();
tswrite($data_a,10);
tsread();
tsread();
tswrite($data_b,20);
tsread();
tsread();
$fh_out->close();
$ftmp->close();
sub tswrite
{
my ($d,$s) = @_;
( my $pos = tell($ftmp) ) >= 0
or die("tell: $!\n");
my $r = $ftmp->write($d,$s);
seek($ftmp, $pos, SEEK_SET)
or die("seek: $!\n");
}
sub tsread
{
$fh_out->read($buff,$blen);
print "$buff\n";
}
|