You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Greg Stein <gs...@lyra.org> on 2002/05/23 23:25:48 UTC

Re: cvs commit: httpd-2.0/server log.c

On Thu, May 23, 2002 at 12:19:09PM -0000, trawick@apache.org wrote:
>...
>   +++ log.c	23 May 2002 12:19:09 -0000	1.121
>...
>   +    bytes_wanted = BUFFER_SIZE;
>   +    endptr = buf = apr_palloc(p, BUFFER_SIZE);
>   +    do {
>   +        bytes_read = bytes_wanted;
>   +        rv = apr_file_read(pid_file, endptr, &bytes_read);
>   +        if (rv != APR_SUCCESS && rv != APR_EOF) {
>   +            return rv;
>   +        }
>   +        bytes_wanted -= bytes_read;
>   +        endptr += bytes_read; 
>   +    }
>   +    while (bytes_wanted > 0 && rv != APR_EOF);

Oof... needlessly complicated. Just use apr_file_read_full(). It will return
all the bytes that you ask for, unless an error condition occurs (EOF).
There is no need to do any looping.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: cvs commit: httpd-2.0/server log.c

Posted by Greg Stein <gs...@lyra.org>.
On Thu, May 23, 2002 at 02:31:45PM -0700, Justin Erenkrantz wrote:
> On Thu, May 23, 2002 at 02:25:48PM -0700, Greg Stein wrote:
> > Oof... needlessly complicated. Just use apr_file_read_full(). It will return
> > all the bytes that you ask for, unless an error condition occurs (EOF).
> > There is no need to do any looping.
> 
> You'd have to do a stat() on the file to get the file size as we
> don't know how much data we need.  
> 
> According to the docs, it says that it is not possible for bytes
> to be read and an APR_EOF error to be returned.  That seems like
> it is conflict with the Unix impl though.  (The Unix impl could
> return bytes and APR_EOF.)  -- justin

The doc should probably match that of write_full:

    It is possible for both bytes to be written and an error to be
    returned.  And if *bytes_written is less than nbytes, an
    accompanying error is _always_ returned.

IOW, read_full should be: you get success and all-read, or you get an error
and some-read. But never EINTR or somesuch.

It means that you can avoid the stupid loops to ensure that you get
everything read or written.

In the case of the pidfile, you just read in BUFFER_SIZE. It will always
come back with some number read and APR_EOF. If you truly read that many
bytes, then something is wrong :-)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: cvs commit: httpd-2.0/server log.c

Posted by Justin Erenkrantz <je...@apache.org>.
On Thu, May 23, 2002 at 02:25:48PM -0700, Greg Stein wrote:
> Oof... needlessly complicated. Just use apr_file_read_full(). It will return
> all the bytes that you ask for, unless an error condition occurs (EOF).
> There is no need to do any looping.

You'd have to do a stat() on the file to get the file size as we
don't know how much data we need.  

According to the docs, it says that it is not possible for bytes
to be read and an APR_EOF error to be returned.  That seems like
it is conflict with the Unix impl though.  (The Unix impl could
return bytes and APR_EOF.)  -- justin