passing $fd as a reference

L

Larry

Hi everybody,

below is a few lines from http::daemon pod:

--
$c->send_file( $filename )
$c->send_file( $fd )

Copy the file to the client. The file can be a string (which will be
interpreted as a filename) or a reference to an IO::Handle or glob.
--

I have to admit I have never read file contents by IO::Handle

I usually go about it by:

my $song = 'song.mp3';
open my $fh1, '<', $song or die "open(): $!\n";
binmode $fh1;
close($fh1);

how can I tie the code above to $c->send_file( $fd ) ???

--

btw, when reading a binary file in order to move cursor position, do you
think I should use "seek" or "sysseek" and the should I use read the
file by "read" or "sysread" ??

thanks ever so much!
 
L

Larry

Jim Gibson said:
Use IO::File (untested):

my $fh1 = new IO::File $song;
die "open: $!" unless defined $fh1;
$fh1->binmode;
$c->send_file($fh1);
$fh1->close;

thanks it worked great!!

yet, now I'd like to pass a socket filedesc:

my $fh1 = IO::Socket::INET->new(PeerAddr => '127.0.0.1',PeerPort =>
'65000',Proto => 'tcp');
syswrite $fh1, "GET /song/$itemnum.mp3 HTTP/1.1".$CRLF.$CRLF;
$c->send_file($fh1);
$fh1->close;

But it won't work...why ??
 
B

Brian McCauley

thanks it worked great!!

yet, now I'd like to pass a socket filedesc:

my $fh1 = IO::Socket::INET->new(PeerAddr => '127.0.0.1',PeerPort =>
'65000',Proto => 'tcp');
syswrite $fh1, "GET /song/$itemnum.mp3 HTTP/1.1".$CRLF.$CRLF;
$c->send_file($fh1);
$fh1->close;

But it won't work...why ??

In what way does it not work?

BTW, this has nothing to do with your question (although may be
related to your real problem) but is looks like you are trying to
implement an HTTP/1.1 client.

This is a far from simple exercise. For example HTTP/1.1 clients MUST
support "chunked". Does yours?

Your HTTP request is invalid - it has a 1.1 protocol version number
but lacks the required "Host:" header.

If you want an HTTP client, use LWP (or an external binary).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top