You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@locus.apache.org on 2000/07/07 04:54:54 UTC

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;