httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/network_io/win32 sockets.c sockopt.c
Date Wed, 14 Jun 2000 17:16:50 GMT
stoddard    00/06/14 10:16:49

  Modified:    src/lib/apr/network_io/win32 sockets.c sockopt.c
  Log:
  Get non-blocking network I/O working on Windows. Apache serves pages on Windows
  now. Cleaned up some Windows specific bugs with timing out connections as well.
  
  Revision  Changes    Path
  1.30      +5 -2      apache-2.0/src/lib/apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockets.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- sockets.c	2000/05/01 14:39:34	1.29
  +++ sockets.c	2000/06/14 17:16:47	1.30
  @@ -97,11 +97,13 @@
       }
   
       (*new)->local_addr->sin_family = AF_INET;
  +    (*new)->remote_addr->sin_family = AF_INET;
   
       (*new)->addr_len = sizeof(*(*new)->local_addr);
   
       (*new)->local_addr->sin_port = 0;   
  - 
  +
  +    (*new)->timeout = -1;
       ap_register_cleanup((*new)->cntxt, (void *)(*new), 
                           socket_cleanup, ap_null_cleanup);
       return APR_SUCCESS;
  @@ -169,6 +171,7 @@
       memcpy((*new)->local_addr, sock->local_addr, sizeof(struct sockaddr_in));
   
       (*new)->addr_len = sizeof(struct sockaddr_in);
  +    (*new)->timeout = -1;   
   
       (*new)->sock = accept(sock->sock, (struct sockaddr *)(*new)->local_addr,
                           &(*new)->addr_len);
  @@ -176,7 +179,7 @@
       if ((*new)->sock == INVALID_SOCKET) {
           return WSAGetLastError();
       }
  -    
  +
       ap_register_cleanup((*new)->cntxt, (void *)(*new), 
                           socket_cleanup, ap_null_cleanup);
       return APR_SUCCESS;
  
  
  
  1.17      +37 -10    apache-2.0/src/lib/apr/network_io/win32/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockopt.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- sockopt.c	2000/05/01 14:39:34	1.16
  +++ sockopt.c	2000/06/14 17:16:47	1.17
  @@ -60,9 +60,9 @@
   
   ap_status_t soblock(SOCKET sd)
   {
  -    int one = 1;
  +    int zero = 0;
   
  -    if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) {
  +    if (ioctlsocket(sd, FIONBIO, &zero) == SOCKET_ERROR) {
           return WSAGetLastError();
       }
       return APR_SUCCESS;
  @@ -70,9 +70,9 @@
   
   ap_status_t sononblock(SOCKET sd)
   {
  -    int zero = 0;
  +    int one = 1;
   
  -    if (ioctlsocket(sd, FIONBIO, &zero) == SOCKET_ERROR) {
  +    if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) {
           return WSAGetLastError();
       }
       return APR_SUCCESS;
  @@ -90,13 +90,40 @@
           one = 0;
   
       if (opt & APR_SO_TIMEOUT) {
  -        int timeout;
  -        sock->timeout = on;
  -        timeout = on / 1000; /* Windows needs timeout in mSeconds */
  -        if (setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, (char*) &timeout, 
  -                       sizeof(timeout)) == SOCKET_ERROR) {
  -            return WSAGetLastError();
  +        int new_timeout;
  +        if (on <= 0)
  +            new_timeout = on;
  +        else
  +            new_timeout = on/1000;  /* Windows needs timeout in mSeconds */
  +                    
  +        if (new_timeout == 0) {
  +            /* Set the socket non-blocking if it isn't already set to non-blocking */
  +            if (sock->timeout != 0) {
  +                if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
  +                    return stat;
  +            }
  +        }
  +        else if (new_timeout > 0) {
  +            /* Set the socket to blocking if it was previously non-blocking */
  +            if (sock->timeout == 0) {
  +                if ((stat = soblock(sock->sock)) != APR_SUCCESS)
  +                    return stat;
  +            }
  +            /* Reset socket timeouts if the new timeout differs from the old timeout */
  +            if (sock->timeout != new_timeout) {
  +                setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &new_timeout,
sizeof(new_timeout));
  +                setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &new_timeout,
sizeof(new_timeout));
  +            }
  +        }
  +        else if (new_timeout < 0) {
  +            int zero = 0;
  +            /* Set the socket to blocking with infinite timeouts */
  +            if ((stat = soblock(sock->sock)) != APR_SUCCESS)
  +                return stat;
  +            setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &zero, sizeof(zero));
  +            setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &zero, sizeof(zero));
           }
  +        sock->timeout = new_timeout;
       }
       if (opt & APR_SO_KEEPALIVE) {
           if (setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int))
== -1) {
  
  
  

Mime
View raw message