Re: Streaming

Tim Wood <timwood0-yBeKhBN/[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
At 10:39 PM 12/04/06, Richard Levenberg wrote:
>In a previous email where I was asking about how to interrupt the while
>loop. I have another question though. Within the loop is there an FCGX
>appropriate way to stream out data or do I use the request.out parameter
>and just call write on that?
>
>  while (FCGX_Accept_r(&request) >= 0) {
>    char *content_type;
>    FCGX_FPrintF(request.out, "Content-type: %s\r\n\r\n", content_type);
>    /* stream out content-type data here */
>    FCGX_Finish_r(&request);
>  }


R-
Here's how I do it.  HTH!
TW


use constant RSIZE => (96 * 1024);
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
        ...
        # Send HTTP headers for the download and start transfer
        # from *ITEMFILE
        sendHeaders($itemInfo, $itemLen);
        my $xferred = doDownload(\*ITEMFILE);
        close(RECFILE);
...
}

# Output the HTTP headers for the download.
sub sendHeaders {
        my $itemInfo = shift;
        my $itemLen = shift;

        print "Content-type: application/octet-stream\n";
        print "Content-length: $flen\n";
        print "\n";
}

# Perform download I/O, return amount downloaded.  Detect early close
# of connection by user with SIGPIPE.
sub doDownload {
        my $itemFile = shift;
        my $buf = [ ];
        my ($xferred, $rlen) = (0, 0);

        for ($xferred = 0;
                our $gotPIPE == 0 && ($rlen = read($itemFile, $buf, RSIZE)) != 0;
                $xferred += $rlen) 
        {
                print STDOUT $buf;
        }
        # RESOLVE die/warn handlers needed?
DLDONE: 
        return $xferred;
}


___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.