Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 78740 invoked from network); 1 May 2008 22:24:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 May 2008 22:24:45 -0000 Received: (qmail 58691 invoked by uid 500); 1 May 2008 22:24:47 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 58591 invoked by uid 500); 1 May 2008 22:24:47 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 58575 invoked by uid 99); 1 May 2008 22:24:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 May 2008 15:24:47 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 May 2008 22:24:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DD42C23889FF; Thu, 1 May 2008 15:24:14 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r652691 - /apr/apr/branches/1.3.x/network_io/unix/sendrecv.c Date: Thu, 01 May 2008 22:24:14 -0000 To: commits@apr.apache.org From: wrowe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080501222414.DD42C23889FF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: wrowe Date: Thu May 1 15:24:14 2008 New Revision: 652691 URL: http://svn.apache.org/viewvc?rev=652691&view=rev Log: Reflow the OS/X sendfile implementation to proceed from writev(hd..iovec) to the sendfile/tr..iovec series, tallying these correctly. Submitted by: Geoff Greer and wrowe Backports: r652690 Modified: apr/apr/branches/1.3.x/network_io/unix/sendrecv.c Modified: apr/apr/branches/1.3.x/network_io/unix/sendrecv.c URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/network_io/unix/sendrecv.c?rev=652691&r1=652690&r2=652691&view=diff ============================================================================== --- apr/apr/branches/1.3.x/network_io/unix/sendrecv.c (original) +++ apr/apr/branches/1.3.x/network_io/unix/sendrecv.c Thu May 1 15:24:14 2008 @@ -413,7 +413,8 @@ apr_off_t nbytes = 0; apr_off_t bytes_to_send = *len; apr_size_t header_bytes_written = 0; - int rv; + int rv = 0; + int sent_headers = 0; /* Ignore flags for now. */ flags = 0; @@ -436,17 +437,24 @@ return arv; } } - - if (hdtr->numheaders) { - rv = writev(sock->socketdes, - hdtr->headers, - hdtr->numheaders); - if (rv > 0) { - header_bytes_written = rv; - rv = 0; + + if (!sent_headers) { + if (hdtr->numheaders) { + rv = writev(sock->socketdes, + hdtr->headers, + hdtr->numheaders); + if (rv > 0) { + header_bytes_written = rv; + sent_headers = 1; + rv = 0; + } + } + else { + sent_headers = 1; } } - else if (bytes_to_send) { + + if (bytes_to_send && sent_headers) { /* We won't dare call sendfile() if we don't have * header or file bytes to send because nbytes == 0 * means send the remaining file to EOF. @@ -464,12 +472,13 @@ if (errno == EAGAIN) { if (sock->timeout > 0) { sock->options |= APR_INCOMPLETE_WRITE; + rv = 0; } /* BSD's sendfile can return -1/EAGAIN even if it * sent bytes. Sanitize the result so we get normal EAGAIN * semantics w.r.t. bytes sent. */ - if (nbytes) { + else if (nbytes) { /* normal exit for a big file & non-blocking io */ (*len) = nbytes + header_bytes_written; return APR_SUCCESS; @@ -486,19 +495,17 @@ } } } - else { + + if (sent_headers && !bytes_to_send) { /* just trailer bytes... use writev() */ rv = writev(sock->socketdes, hdtr->trailers, hdtr->numtrailers); if (rv > 0) { - nbytes = rv; + nbytes += rv; rv = 0; } - else { - nbytes = 0; - } } if ((rv == -1) && (errno == EAGAIN) && (sock->timeout > 0)) {