apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <cliffwool...@yahoo.com>
Subject Re: apr_buckets_file.c:file_read + XTHREAD
Date Wed, 28 Nov 2001 00:50:23 GMT
On Tue, 27 Nov 2001, Doug MacEachern wrote:

> if file_read() cannot mmap the the file, it does this:
>     if ((flags = apr_file_flags_get(f)) & APR_XTHREAD) {
>         /* this file descriptor is shared across multiple threads and
>          * this OS doesn't support that natively, so as a workaround
>          * we must reopen the file into a->readpool */
>         const char *fname;
>         apr_file_name_get(&fname, f);
>         rv = apr_file_open(&f, fname, (flags & ~APR_XTHREAD), 0, a->readpool);
>         if (rv != APR_SUCCESS)
>             return rv;
>         a->fd = f;
>     }
> #endif
> in the case above does the file get re-opened everytime file_read() is
> called

It's theoretically possible for it to happen if you've split or copied
your file bucket _before reading from it_ the first time.

> if not the latter, any reason why it can't be that way?  looks like
> the XTHREAD thinger is only used by mod_file_cache.c, shouldn't its
> handler take care of re-opening the file instead of file_read()?

No!  The whole point of mod_file_cache is that we don't _want_ to reopen
the file on every request if we don't have to.  :)

> re-open

That it will happen once is the more likely scenario.  If the bucket has
not been split or copied, then we reopen the file once, turn off the
APR_XTHREAD flag, and replace the file bucket's a->fd with the re-opened,
not shared across threads file descriptor.  Any copies or splits we do
after that which then have apr_bucket_read() called on them will see
~APR_XTHREAD and will skip this block.

> and apr_file_seek() for every file_read() doesn't seem right. and i
> don't see why apr_file_seek() should happen if the file isn't being
> re-opened, but it currently happens regardless of the XTHREAD flag.

Because if the file bucket is ever split or copied, your file pointer is
useless.  There's not a really easy way to keep track of when you need to
seek and when you don't, so we just do it all the time.  You could come
up with some kind of logic to set a variable that says whether it's been
split/copied or not, and if not, then you can skip the seek, but I think I
came up with a case once where even that would break.


   Cliff Woolley
   Charlottesville, VA

View raw message