apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Erenkrantz <jerenkra...@ebuilt.com>
Subject Re: [PATCH] tweaks to apr_sendfile() for Solaris
Date Thu, 26 Jul 2001 07:08:38 GMT
On Wed, Jul 25, 2001 at 05:23:12PM -0400, Jeff Trawick wrote:
> Jeff Trawick <trawick@attglobal.net> writes:
> 
> > With this patch
> > 
> > 1) we don't call wait_for_io_or_timeout() after successfully sending
> >    data
> > 
> > 2) we try again to send data after wait_for_io_or_timeout() finds that
> >    the socket is now writable
> > 
> > 3) the code looks more like the other APR network write operations

I think the "patch" below would address #1 and #2, but definitely not 
#3.  =)

As this patch actually has many lines of diffs (due to reorg in the
Solaris section), I'll just enclose the relevant section of code so that
the logic is obvious.  I just don't like the idea of adding more 
places where we call sendfilev().  We're bound to screw up something 
later.  I'd take the hit of the two extra ints instead.  But, that's
me.  -- justin

------
[ arv is a apr_status_t and repeat is an int. ]
 
    /* Actually do the sendfilev
     *
     * Solaris may return -1/EAGAIN even if it sent bytes on a non-block sock.
     *
     * However, if we are on a TIMEOUT socket (which as far as the OS is
     * concerned is a non-blocking socket), we want to block until the 
     * other side has read the data (as determined by poll).  Furthermore, 
     * if no bytes were originally sent (nbytes == 0), we want to retry
     * sending the sendfilevec_t once more.
     */
    arv = 0;
    do {
        /* Clear out the repeat */
        repeat = 0;

        /* socket, vecs, number of vecs, bytes written */
        rv = sendfilev(sock->socketdes, sfv, vecs, &nbytes);

        if (rv == -1 && errno == EAGAIN)
        {
            /* We wrote something successfully - see above */
            if (nbytes)
                rv = 0; 

            /* If this is the second time and we now got a successful write, 
             * yet still received EAGAIN, we don't wait again.
             */
            if (!arv && apr_is_option_set(sock->netmask, APR_SO_TIMEOUT) == 1)
            {
                apr_status_t t = apr_wait_for_io_or_timeout(sock, 0);

                if (t != APR_SUCCESS)
                {
                    *len = 0;
                    return t;
                }

                /* We failed first try, repeat, but don't repeat twice. */
                if (!nbytes)
                {
                    arv = 1; 
                    repeat = 1;
                }
            }
        }
    } while ((rv == -1 && errno == EINTR) || repeat);

    if (rv == -1)
    {
        *len = 0;
        return errno;
    }

    /* Update how much we sent */
    *len = nbytes;
    return APR_SUCCESS;


Mime
View raw message