apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/network_io/win32 sockets.c sockopt.c
Date Mon, 15 Jul 2002 06:17:36 GMT
wrowe       2002/07/14 23:17:36

  Modified:    network_io/win32 sockets.c sockopt.c
  Log:
    Implement the win32 apr_socket_timeout_set/get, and accomodate both the
    local timeout_ms and the common timeout field definitions.
  
  Revision  Changes    Path
  1.81      +2 -2      apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- sockets.c	5 Jul 2002 17:58:10 -0000	1.80
  +++ sockets.c	15 Jul 2002 06:17:36 -0000	1.81
  @@ -315,8 +315,8 @@
               tvptr = NULL;
           }
           else {
  -            tv.tv_sec =  (long)(sock->timeout / APR_USEC_PER_SEC);
  -            tv.tv_usec = (long)(sock->timeout % APR_USEC_PER_SEC);
  +            tv.tv_sec =  apr_time_sec_get(sock->timeout);
  +            tv.tv_usec = apr_time_usec_get(sock->timeout);
               tvptr = &tv;
           }
           rc = select(FD_SETSIZE+1, NULL, &wfdset, &efdset, tvptr);
  
  
  
  1.39      +67 -10    apr/network_io/win32/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockopt.c,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- sockopt.c	6 Jun 2002 02:58:16 -0000	1.38
  +++ sockopt.c	15 Jul 2002 06:17:36 -0000	1.39
  @@ -78,6 +78,52 @@
       return APR_SUCCESS;
   }
   
  +
  +APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t
t)
  +{
  +    apr_status_t stat;
  +
  +    if (t == 0) {
  +        /* Set the socket non-blocking if it was previously blocking */
  +        if (sock->timeout != 0) {
  +            if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
  +                return stat;
  +        }
  +    }
  +    else if (t > 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 != t) 
  +        {
  +            /* Win32 timeouts are in msec */
  +            sock->timeout_ms = apr_time_as_msec(t);
  +            setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, 
  +                       (char *) &sock->timeout_ms, 
  +                       sizeof(sock->timeout_ms));
  +            setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, 
  +                       (char *) &sock->timeout_ms, 
  +                       sizeof(sock->timeout_ms));
  +        }
  +    }
  +    else if (t < 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 = t;
  +    return APR_SUCCESS;
  +}
  +
  +
   APR_DECLARE(apr_status_t) apr_setsocketopt(apr_socket_t *sock,
                                              apr_int32_t opt, apr_int32_t on)
   {
  @@ -89,10 +135,7 @@
       switch (opt) {
       case APR_SO_TIMEOUT: 
       {
  -        if (on > 0) {
  -            on = on/1000;  /* Convert from APR units (uS) to windows units (mS) */ 
  -        }
  -
  +        /* XXX: to be deprecated */
           if (on == 0) {
               /* Set the socket non-blocking if it was previously blocking */
               if (sock->timeout != 0) {
  @@ -107,9 +150,16 @@
                       return stat;
               }
               /* Reset socket timeouts if the new timeout differs from the old timeout */
  -            if (sock->timeout != on) {
  -                setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &on, sizeof(on));
  -                setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &on, sizeof(on));
  +            if (sock->timeout != on) 
  +            {
  +                /* Win32 timeouts are in msec */
  +                sock->timeout_ms = apr_time_to_msec(on);
  +                setsockopt(sock->sock, SOL_SOCKET, SO_RCVTIMEO, 
  +                           (char *) &sock->timeout_ms, 
  +                           sizeof(sock->timeout_ms));
  +                setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, 
  +                           (char *) &sock->timeout_ms, 
  +                           sizeof(sock->timeout_ms));
               }
           }
           else if (on < 0) {
  @@ -188,14 +238,21 @@
       return APR_SUCCESS;
   }
   
  +
  +APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t
*t)
  +{
  +    *t = sock->timeout;
  +    return APR_SUCCESS;
  +}
  +
  +
   APR_DECLARE(apr_status_t) apr_getsocketopt(apr_socket_t *sock,
                                              apr_int32_t opt, apr_int32_t *on)
   {
       switch (opt) {
       case APR_SO_TIMEOUT: 
  -        /* Convert from milliseconds (windows units) to microseconds 
  -         * (APR units) */
  -        *on = (apr_int32_t)(sock->timeout * 1000);
  +        /* XXX: to be deprecated */
  +        *on = sock->timeout;
           break;
       case APR_SO_DISCONNECTED:
           *on = sock->disconnected;
  
  
  

Mime
View raw message