Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 68331 invoked by uid 500); 7 Jul 2000 02:54:55 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 68320 invoked by uid 500); 7 Jul 2000 02:54:54 -0000 Delivered-To: apmail-apache-2.0-cvs@apache.org Date: 7 Jul 2000 02:54:54 -0000 Message-ID: <20000707025454.68316.qmail@locus.apache.org> From: trawick@locus.apache.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/lib/apr/network_io/unix sendrecv.c trawick 00/07/06 19:54:54 Modified: src/lib/apr/network_io/unix sendrecv.c Log: ap_sendfile() fixes: all Unix flavors: fix the check for whether or not we have a timeout FreeBSD flavor: make it work correct with a non-blocking socket that doesn't have a timeout Revision Changes Path 1.31 +29 -12 apache-2.0/src/lib/apr/network_io/unix/sendrecv.c Index: sendrecv.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- sendrecv.c 2000/07/06 15:13:23 1.30 +++ sendrecv.c 2000/07/07 02:54:54 1.31 @@ -253,7 +253,7 @@ if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; @@ -331,20 +331,37 @@ headerstruct.trl_cnt = hdtr->numtrailers; /* FreeBSD can send the headers/footers as part of the system call */ + do { - rv = sendfile(file->filedes, /* open file descriptor of the file to be sent */ - sock->socketdes, /* socket */ - *offset, /* where in the file to start */ - bytes_to_send, /* number of bytes to send */ - &headerstruct, /* Headers/footers */ - &nbytes, /* number of bytes written */ - flags /* undefined, set to 0 */ - ); + if (bytes_to_send) { + /* We won't dare call sendfile() if we don't have + * header or file bytes to send because bytes_to_send == 0 + * means send the whole file. + */ + rv = sendfile(file->filedes, /* file to be sent */ + sock->socketdes, /* socket */ + *offset, /* where in the file to start */ + bytes_to_send, /* number of bytes to send */ + &headerstruct, /* Headers/footers */ + &nbytes, /* number of bytes written */ + flags); /* undefined, set to 0 */ + } + else { + /* just trailer bytes... use writev() + */ + rv = writev(sock->socketdes, + hdtr->trailers, + hdtr->numtrailers); + if (rv > 0) { + nbytes = rv; + rv = 0; + } + } } while (rv == -1 && errno == EINTR); if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { ap_status_t arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; @@ -435,7 +452,7 @@ if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { ap_status_t arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { @@ -564,7 +581,7 @@ if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0;