On Fri, Nov 17, 2000 at 02:42:43PM +1100, Steve Smith wrote:
> Hi,
> 
> All I get is an empty document.  My understanding is that the data
> written to the tmpfile should be available immediately through the
> filehandle even if it hasn't been flushed.

I wouldn't bet on it flushing: mod_perl may not have written it out yet.
perl often doesn't flush writes to disk until close.  Try adding a

   select( (select( $fh ), $| = 1 )[0] ) ;

just after the open and see if that fixes things.

Also, Apache doesn't seek or rewind the FD (see below), so even if it's flushed,
your file position may no longer be at the beginning of the file, depending
on your C RTL.  I seem to recall that some require you to seek() between
reads and writes to ensure synchronization.

That lack of a rewind can be nice when you're caching things: you can sysread
some header lines, then turn the rest over to Apache to send.

- Barrie

API_EXPORT(long) ap_send_fd_length(FILE *f, request_rec *r, long length)
{
    char buf[IOBUFSIZE];
    long total_bytes_sent = 0;
    register int n, w, o, len;

    if (length == 0)
        return 0;

    ap_soft_timeout("send body", r);

    while (!r->connection->aborted) {
        if ((length > 0) && (total_bytes_sent + IOBUFSIZE) > length)
            len = length - total_bytes_sent;
        else
            len = IOBUFSIZE;

        while ((n = fread(buf, sizeof(char), len, f)) < 1
               && ferror(f) && errno == EINTR && !r->connection->aborted)
            continue;


Reply via email to