httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Zedlewski <zedlw...@Princeton.EDU>
Subject Re: [PATCH] Whoops, here's the better Linux sendfile()
Date Fri, 12 Nov 1999 00:46:53 GMT
> Also, I don't believe that Linux sendfile actually guarantees that it
> will write all the bytes requested; AFAIK it works just like the other
> IO functions. I guess we could add a loop to make sure that the
> sendfile call completes all the bytes, but that would be inconsistent
> with the way the other IOL functions work.

Hmm... the man page says "if the transfer was succeeded, the number of bytes
written to out_fd is returned. .  .  [offset] will be set to the offset of
the byte following the last byte that was read."  In my experience, I've
never seen sendfile() fail to send the whole file without some kind of real
error.  It's worth looking at the implementation, though, which I'll do when
I get a chance.  Generally, it seems that ap_sendfile should guarantee
sending the whole file unless an error occurs, because otherwise one would
just use read/write.  Still, I agree it needs more investigation.

> ap_status_t ap_sendfile(struct iovec *headers, ap_file_t *file,
>                         struct iovec *trailers, ap_off_t *offset,
>                         ap_ssize_t count, ap_int_n flags,
>                         ap_size_t *bytes_written);

What about count arguments for both the number of headers and the number of
trailers?  That seems to be the way most Unix OSes implement the header
sending.  And, um, what about an ap_socket_t* onto which to write the
output?  God, this is becoming a bear.  I have it almost done for a couple of
different OSes now and should be able to submit it later tonight.  The
interface should be easy enough to change around.
Maybe it would be smart to do what AIX and freebsd do: have a structure (
ap_hdtr_t ) to hold the header iovec array, trailer iovec array, and lenghts
of each.
Then we'd have:

ap_status_t ap_sendfile( ap_socket_t *socket,
    ap_file_t *file,
    ap_hdtr_t *hdtr,
    ap_off_t *offset,
    ap_size_t  *len,
    ap_int_n flags,

struct ap_hdtr_t {
    struct iovec* headers;
    int numheaders;
    struct iovec* trailers;
    int numtrailers;

Then len gets overwritten with the number of bytes successfully written to
the socket, just as len gets overwritten in ap_send.  That is, if we don't
make it guarantee a complete write.  This also keeps it to 6 arguments, which
is generally the max I like to see in a function, but maybe that's just me.

View raw message