apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr/network_io/unix sendrecv.c
Date Thu, 11 Apr 2002 01:05:40 GMT
brianp      02/04/10 18:05:40

  Modified:    .        CHANGES
               network_io/unix sendrecv.c
  Log:
  If a socket write or sendfile call writes less than the requested
  amount of data, do a select to wait for writability on the socket
  before attempting the next write.
  Obtained from: Jeff Trawick
  
  Revision  Changes    Path
  1.255     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.254
  retrieving revision 1.255
  diff -u -r1.254 -r1.255
  --- CHANGES	9 Apr 2002 07:42:27 -0000	1.254
  +++ CHANGES	11 Apr 2002 01:05:39 -0000	1.255
  @@ -1,5 +1,9 @@
   Changes with APR b1
   
  +  *) On socket write functions (apr_sendfile, apr_send, apr_sendv),
  +     added a select to wait for writability on the socket if the
  +     previous write was incomplete.  [Jeff Trawick, Brian Pane]
  +
     *) Deprecated the apr_lock.h API. Please see the following files
        for the improved thread and process locking and signaling:
        apr_proc_mutex.h, apr_thread_mutex.h, apr_thread_rwlock.h,
  
  
  
  1.79      +35 -2     apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- sendrecv.c	13 Mar 2002 20:39:25 -0000	1.78
  +++ sendrecv.c	11 Apr 2002 01:05:39 -0000	1.79
  @@ -97,13 +97,19 @@
   {
       ssize_t rv;
       
  +    if (sock->netmask & APR_INCOMPLETE_WRITE) {
  +        goto do_select;
  +    }
  +
       do {
           rv = write(sock->socketdes, buf, (*len));
       } while (rv == -1 && errno == EINTR);
   
       if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) 
         && sock->timeout != 0) {
  -        apr_status_t arv = apr_wait_for_io_or_timeout(sock, 0);
  +        apr_status_t arv;
  +do_select:
  +        arv = apr_wait_for_io_or_timeout(sock, 0);
           if (arv != APR_SUCCESS) {
               *len = 0;
               return arv;
  @@ -118,6 +124,9 @@
           *len = 0;
           return errno;
       }
  +    if (sock->timeout && rv < *len) {
  +	sock->netmask |= APR_INCOMPLETE_WRITE;
  +    }
       (*len) = rv;
       return APR_SUCCESS;
   }
  @@ -238,6 +247,16 @@
                        apr_int32_t nvec, apr_size_t *len)
   {
       apr_ssize_t rv;
  +    apr_size_t requested_len = 0;
  +    apr_int32_t i;
  +
  +    for (i = 0; i < nvec; i++) {
  +        requested_len += vec[i].iov_len;
  +    }
  +
  +    if (sock->netmask & APR_INCOMPLETE_WRITE) {
  +        goto do_select;
  +    }
   
       do {
           rv = writev(sock->socketdes, vec, nvec);
  @@ -245,7 +264,9 @@
   
       if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && 
         sock->timeout != 0) {
  -        apr_status_t arv = apr_wait_for_io_or_timeout(sock, 0);
  +        apr_status_t arv;
  +do_select:
  +        arv = apr_wait_for_io_or_timeout(sock, 0);
           if (arv != APR_SUCCESS) {
               *len = 0;
               return arv;
  @@ -260,6 +281,9 @@
           *len = 0;
           return errno;
       }
  +    if (sock->timeout && rv < requested_len) {
  +	sock->netmask |= APR_INCOMPLETE_WRITE;
  +    }
       (*len) = rv;
       return APR_SUCCESS;
   }
  @@ -323,6 +347,11 @@
           }
       }
   
  +    if (sock->netmask & APR_INCOMPLETE_WRITE) {
  +        sock->netmask &= ~APR_INCOMPLETE_WRITE;
  +        goto do_select;
  +    }
  +
       do {
           rv = sendfile(sock->socketdes,	/* socket */
           	      file->filedes,	/* open file descriptor of the file to be sent */
  @@ -334,6 +363,7 @@
       if (rv == -1 && 
           (errno == EAGAIN || errno == EWOULDBLOCK) && 
           sock->timeout > 0) {
  +do_select:
   	arv = apr_wait_for_io_or_timeout(sock, 0);
   	if (arv != APR_SUCCESS) {
   	    *len = 0;
  @@ -364,6 +394,9 @@
   
       if (rv < *len) {
           *len = nbytes;
  +        if (sock->timeout) {
  +            sock->netmask |= APR_INCOMPLETE_WRITE;
  +        }
           return apr_setsocketopt(sock, APR_TCP_NOPUSH, 0);
       }
   
  
  
  

Mime
View raw message