passing $fd as a reference

Discussion in 'Perl Misc' started by Larry, Oct 5, 2007.

  1. Larry

    Larry Guest

    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!
    Larry, Oct 5, 2007
    #1
    1. Advertising

  2. Larry

    Larry Guest

    In article <051020071302388074%>,
    Jim Gibson <> 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 ??
    Larry, Oct 6, 2007
    #2
    1. Advertising

  3. On Oct 6, 7:56 am, Larry <> wrote:
    > In article <051020071302388074%>,
    > Jim Gibson <> 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).
    Brian McCauley, Oct 6, 2007
    #3
  4. Larry

    Larry Guest

    In article <>,
    Brian McCauley <> wrote:

    > In what way does it not work?


    it was my fault, now it's working great...
    Larry, Oct 7, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sam pal
    Replies:
    3
    Views:
    540
    E. Robert Tisdale
    Jul 16, 2003
  2. Victor Bazarov
    Replies:
    25
    Views:
    878
    E. Robert Tisdale
    Mar 23, 2005
  3. pereges
    Replies:
    7
    Views:
    436
    pereges
    Jun 1, 2008
  4. Ramon F Herrera
    Replies:
    8
    Views:
    477
    Pascal J. Bourguignon
    Sep 13, 2009
  5. Replies:
    2
    Views:
    145
Loading...

Share This Page