httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@hyperreal.org
Subject cvs commit: apache-2.0/src/lib/apr/network_io/os2 networkio.h sendrecv.c sockets.c sockopt.c
Date Wed, 03 Nov 1999 14:03:27 GMT
bjh         99/11/03 06:03:27

  Modified:    src/lib/apr/network_io/os2 networkio.h sendrecv.c sockets.c
                        sockopt.c
  Log:
  OS/2: Rework ap_send/ap_recv to time out properly on blocking sockets.
  
  Revision  Changes    Path
  1.6       +2 -1      apache-2.0/src/lib/apr/network_io/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/networkio.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- networkio.h	1999/10/29 14:21:00	1.5
  +++ networkio.h	1999/11/03 14:03:25	1.6
  @@ -68,7 +68,8 @@
       struct sockaddr_in *local_addr;
       struct sockaddr_in *remote_addr;
       int addr_len;
  -    int timeout; 
  +    int timeout;
  +    int nonblock;
   };
   
   struct pollfd_t {
  
  
  
  1.6       +68 -78    apache-2.0/src/lib/apr/network_io/os2/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sendrecv.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sendrecv.c	1999/10/29 14:21:01	1.5
  +++ sendrecv.c	1999/11/03 14:03:25	1.6
  @@ -65,38 +65,34 @@
   ap_status_t ap_send(struct socket_t *sock, const char *buf, ap_ssize_t *len)
   {
       ssize_t rv;
  -    
  +    int fds, err = 0;
  +
       do {
  -        rv = send(sock->socketdes, buf, (*len), 0);
  -    } while (rv == -1 && sock_errno() == SOCEINTR);
  +        if (!sock->nonblock || err == SOCEWOULDBLOCK) {
  +            fds = sock->socketdes;
  +            rv = select(&fds, 0, 1, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
   
  -    if (rv == -1 && sock_errno() == SOCEWOULDBLOCK && sock->timeout
!= 0) {
  -        int fds;
  -        int srv;
  +            if (rv != 1) {
  +                *len = -1;
  +                err = sock_errno();
   
  -        do {
  -            fds = sock->socketdes;
  -            srv = select(&fds, 0, 1, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
  -        } while (srv == -1 && sock_errno() == SOCEINTR);
  +                if (rv == 0)
  +                    return APR_TIMEUP;
   
  -        if (srv == 0) {
  -            (*len) = -1;
  -            return APR_TIMEUP;
  -        }
  -        else if (srv < 0) {
  -            (*len) = -1;
  -            return os2errno(sock_errno());
  -        }
  -        else {
  -            do {
  -                rv = send(sock->socketdes, buf, (*len), 0);
  -            } while (rv == -1 && sock_errno() == SOCEINTR);
  +                if (err == SOCEINTR)
  +                    continue;
  +
  +                return os2errno(err);
  +            }
           }
  -    }
   
  -    if (rv < 0) {
  -        *len = 0;
  -        return os2errno(sock_errno());
  +        rv = send(sock->socketdes, buf, (*len), 0);
  +        err = rv < 0 ? sock_errno() : 0;
  +    } while (err == SOCEINTR || err == SOCEWOULDBLOCK);
  +
  +    if (err) {
  +        *len = -1;
  +        return os2errno(err);
       }
   
       (*len) = rv;
  @@ -108,38 +104,34 @@
   ap_status_t ap_recv(struct socket_t *sock, char *buf, ap_ssize_t *len)
   {
       ssize_t rv;
  -    
  +    int fds, err = 0;
  +
       do {
  -        rv = recv(sock->socketdes, buf, (*len), 0);
  -    } while (rv == -1 && sock_errno() == SOCEINTR);
  +        if (!sock->nonblock || err == SOCEWOULDBLOCK) {
  +            fds = sock->socketdes;
  +            rv = select(&fds, 1, 0, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
   
  -    if (rv == -1 && sock_errno() == SOCEWOULDBLOCK && sock->timeout
!= 0) {
  -        int fds;
  -        int srv;
  +            if (rv != 1) {
  +                *len = -1;
  +                err = sock_errno();
   
  -        do {
  -            fds = sock->socketdes;
  -            srv = select(&fds, 1, 0, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
  -        } while (srv == -1 && sock_errno() == SOCEINTR);
  +                if (rv == 0)
  +                    return APR_TIMEUP;
   
  -        if (srv == 0) {
  -            (*len) = -1;
  -            return APR_TIMEUP;
  -        }
  -        else if (srv < 0) {
  -            (*len) = -1;
  -            return os2errno(sock_errno());
  -        }
  -        else {
  -            do {
  -                rv = recv(sock->socketdes, buf, (*len), 0);
  -            } while (rv == -1 && sock_errno() == SOCEINTR);
  +                if (err == SOCEINTR)
  +                    continue;
  +
  +                return os2errno(err);
  +            }
           }
  -    }
  +
  +        rv = recv(sock->socketdes, buf, (*len), 0);
  +        err = rv < 0 ? sock_errno() : 0;
  +    } while (err == SOCEINTR || err == SOCEWOULDBLOCK);
   
  -    if (rv < 0) {
  -        *len = 0;
  -        return os2errno(sock_errno());
  +    if (err) {
  +        *len = -1;
  +        return os2errno(err);
       }
   
       (*len) = rv;
  @@ -148,45 +140,43 @@
   
   
   
  -ap_status_t ap_sendv(ap_socket_t *sock, const struct iovec *vec, ap_int32_t nvec, ap_int32_t
*nbytes)
  +ap_status_t ap_sendv(ap_socket_t *sock, const struct iovec *vec, ap_int32_t nvec, ap_int32_t
*len)
   {
       ap_status_t rv;
       struct iovec *tmpvec;
  +    int fds, err = 0;
   
       tmpvec = alloca(sizeof(struct iovec) * nvec);
       memcpy(tmpvec, vec, sizeof(struct iovec) * nvec);
   
       do {
  -        rv = writev(sock->socketdes, tmpvec, nvec);
  -    } while (rv == -1 && sock_errno() == SOCEINTR);
  +        if (!sock->nonblock || err == SOCEWOULDBLOCK) {
  +            fds = sock->socketdes;
  +            rv = select(&fds, 0, 1, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
   
  -    if (rv == -1 && sock_errno() == SOCEWOULDBLOCK && sock->timeout
!= 0) {
  -        int fds;
  -        int srv;
  +            if (rv != 1) {
  +                *len = -1;
  +                err = sock_errno();
   
  -        do {
  -            fds = sock->socketdes;
  -            srv = select(&fds, 1, 0, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
  -        } while (srv == -1 && sock_errno() == SOCEINTR);
  +                if (rv == 0)
  +                    return APR_TIMEUP;
   
  -        if (srv == 0) {
  -            return APR_TIMEUP;
  -        }
  -        else if (srv < 0) {
  -            return os2errno(sock_errno());
  -        }
  -        else {
  -            do {
  -                rv = writev(sock->socketdes, (struct iovec *)vec, nvec);
  -            } while (rv == -1 && sock_errno() == SOCEINTR);
  +                if (err == SOCEINTR)
  +                    continue;
  +
  +                return os2errno(err);
  +            }
           }
  -    }
  -    
  -    if (rv < 0) {
  -        *nbytes = 0;
  -        return os2errno(sock_errno());
  +
  +        rv = writev(sock->socketdes, tmpvec, nvec);
  +        err = rv < 0 ? sock_errno() : 0;
  +    } while (err == SOCEINTR || err == SOCEWOULDBLOCK);
  +
  +    if (err) {
  +        *len = -1;
  +        return os2errno(err);
       }
   
  -    *nbytes = rv;
  +    *len = rv;
       return APR_SUCCESS;
   }
  
  
  
  1.10      +1 -0      apache-2.0/src/lib/apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- sockets.c	1999/11/02 21:21:52	1.9
  +++ sockets.c	1999/11/03 14:03:25	1.10
  @@ -107,6 +107,7 @@
           return os2errno(sock_errno());
       }
       (*new)->timeout = -1;
  +    (*new)->nonblock = FALSE;
       ap_register_cleanup((*new)->cntxt, (void *)(*new), 
                           socket_cleanup, ap_null_cleanup);
       return APR_SUCCESS;
  
  
  
  1.7       +3 -1      apache-2.0/src/lib/apr/network_io/os2/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockopt.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- sockopt.c	1999/10/29 14:21:02	1.6
  +++ sockopt.c	1999/11/03 14:03:25	1.7
  @@ -98,8 +98,10 @@
           }
       }
       if (opt & APR_SO_NONBLOCK) {
  -        if (ioctl(sock->socketdes, FIONBIO, (caddr_t)&on, sizeof(on)) == -1) {
  +        if (ioctl(sock->socketdes, FIONBIO, (caddr_t)&one, sizeof(one)) == -1) {
               return os2errno(sock_errno());
  +        } else {
  +            sock->nonblock = one;
           }
       }
       if (opt & APR_SO_LINGER) {
  
  
  

Mime
View raw message