Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > passing $fd as a reference

Reply
Thread Tools

passing $fd as a reference

 
 
Larry
Guest
Posts: n/a
 
      10-05-2007
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!
 
Reply With Quote
 
 
 
 
Larry
Guest
Posts: n/a
 
      10-06-2007
In article <051020071302388074%(E-Mail Removed)>,
Jim Gibson <(E-Mail Removed)> wrote:

> 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 ??
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      10-06-2007
On Oct 6, 7:56 am, Larry <(E-Mail Removed)> wrote:
> In article <051020071302388074%(E-Mail Removed)>,
> Jim Gibson <(E-Mail Removed)> wrote:
>
> > 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 ??


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).

 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      10-07-2007
In article <(E-Mail Removed). com>,
Brian McCauley <(E-Mail Removed)> wrote:

> In what way does it not work?


it was my fault, now it's working great...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a reference as a reference pamelamishra@gmail.com Perl Misc 2 08-16-2007 09:48 PM
asp.net 2005 question re: "reference to a non-shared member requires an object reference" ce ASP .Net 1 06-23-2005 09:15 PM
web reference interfering with reference to component Dude ASP .Net 0 11-09-2004 11:53 AM
How to tell if a reference is project or file reference from within the IDE? Darren ASP .Net 0 10-11-2004 12:51 AM
Passing the value by reference is same as pointer by reference sam pal C++ 3 07-16-2003 09:14 PM



Advertisments