You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/06/14 22:56:01 UTC

cvs commit: apache-2.0/src/os/win32 iol_socket.c

stoddard    00/06/14 13:56:01

  Modified:    src/lib/apr aprlib.def
               src/lib/apr/include apr_network_io.h
               src/lib/apr/network_io/win32 sendrecv.c sockopt.c
               src/os/win32 iol_socket.c
  Log:
  Win32: Cleanup ap_setsockopt(). First cut at implementing ap_getsockopt() and iol_getopt().
  Do we need to move iol into APR?
  
  Revision  Changes    Path
  1.29      +1 -1      apache-2.0/src/lib/apr/aprlib.def
  
  Index: aprlib.def
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/aprlib.def,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- aprlib.def	2000/05/31 18:34:12	1.28
  +++ aprlib.def	2000/06/14 20:55:57	1.29
  @@ -79,7 +79,7 @@
   	ap_get_os_sock   @70
   	ap_remove_poll_socket   @71
   	ap_clear_poll_sockets   @72
  -;	ap_setipaddr @73
  +	ap_getsocketopt @73
   ;	ap_getipaddr @74
   ;	ap_create_signal   @75
   ;	ap_setup_signal   @76
  
  
  
  1.38      +26 -0     apache-2.0/src/lib/apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- apr_network_io.h	2000/06/12 20:45:26	1.37
  +++ apr_network_io.h	2000/06/14 20:55:58	1.38
  @@ -422,6 +422,32 @@
   
   /*
   
  +=head1 ap_status_t ap_getsocketopt(ap_socket_t *sock, ap_int32_t opt, ap_int32_t* on)
  +
  +B<Query socket options for the specified socket> 
  +
  +    arg 1) The socket to query
  +    arg 2) The option we would like to query.  One of:
  +              APR_SO_DEBUG      --  turn on debugging information 
  +              APR_SO_KEEPALIVE  --  keep connections active
  +              APR_SO_LINGER     --  lingers on close if data is present
  +              APR_SO_NONBLOCK   --  Turns blocking on/off for socket
  +              APR_SO_REUSEADDR  --  The rules used in validating addresses
  +                                    supplied to bind should allow reuse
  +                                    of local addresses.
  +              APR_SO_TIMEOUT    --  Set the timeout value in microseconds.
  +                                    values < 0 mean wait forever.  0 means
  +                                    don't wait at all.
  +              APR_SO_SNDBUF     --  Set the SendBufferSize
  +              APR_SO_RCVBUF     --  Set the ReceiveBufferSize
  +    arg 3) Socket option returned on the call.
  +
  +=cut
  + */
  +ap_status_t ap_getsocketopt(ap_socket_t *sock, ap_int32_t opt, ap_int32_t* on);
  +
  +/*
  +
   =head1 ap_status_t ap_set_local_port(ap_socket_t *sock, ap_uint32_t port)
         Assocaite a local port with a socket.
   
  
  
  
  1.18      +1 -0      apache-2.0/src/lib/apr/network_io/win32/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sendrecv.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- sendrecv.c	2000/05/12 00:14:43	1.17
  +++ sendrecv.c	2000/06/14 20:55:59	1.18
  @@ -100,6 +100,7 @@
   
       *len = dwBytes;
       return APR_SUCCESS;
  +
   }
   
   ap_status_t ap_sendv(ap_socket_t *sock, const struct iovec *vec,
  
  
  
  1.18      +44 -17    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- sockopt.c	2000/06/14 17:16:47	1.17
  +++ sockopt.c	2000/06/14 20:55:59	1.18
  @@ -81,23 +81,21 @@
   ap_status_t ap_setsocketopt(ap_socket_t *sock, ap_int32_t opt, ap_int32_t on)
   {
       int one;
  -    struct linger li;
       ap_status_t stat;
   
  -    if (on)
  -        one = 1;
  -    else
  -        one = 0;
  +    one = on ? 1 : 0;
   
  -    if (opt & APR_SO_TIMEOUT) {
  +    switch (opt) {
  +    case APR_SO_TIMEOUT: 
  +    {
           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 */
  +            /* Set the socket non-blocking if it was previously blocking */
               if (sock->timeout != 0) {
                   if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
                       return stat;
  @@ -124,23 +122,24 @@
               setsockopt(sock->sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &zero, sizeof(zero));
           }
           sock->timeout = new_timeout;
  +        break;
       }
  -    if (opt & APR_SO_KEEPALIVE) {
  +    case APR_SO_KEEPALIVE:
           if (setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int)) == -1) {
               return WSAGetLastError();
           }
  -    }
  -    if (opt & APR_SO_DEBUG) {
  +        break;
  +    case APR_SO_DEBUG:
           if (setsockopt(sock->sock, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int)) == -1) {
               return WSAGetLastError();
           }
  -    }
  -    if (opt & APR_SO_REUSEADDR) {
  +        break;
  +    case APR_SO_REUSEADDR:
           if (setsockopt(sock->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(int)) == -1) {
               return WSAGetLastError();
           }
  -    }
  -    if (opt & APR_SO_NONBLOCK) {
  +        break;
  +    case APR_SO_NONBLOCK:
           if (on) {
               if ((stat = soblock(sock->sock)) != APR_SUCCESS) 
                   return stat;
  @@ -149,16 +148,44 @@
               if ((stat = sononblock(sock->sock)) != APR_SUCCESS)
                   return stat;
           }
  -    }
  -    if (opt & APR_SO_LINGER) {
  +        break;
  +    case APR_SO_LINGER:
  +    {
  +        struct linger li;
           li.l_onoff = on;
           li.l_linger = MAX_SECS_TO_LINGER;
           if (setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) {
               return WSAGetLastError();
           }
  +        break;
  +    }
  +    default:
  +        return APR_EINVAL;
  +        break;
       }
       return APR_SUCCESS;
   }
  +
  +ap_status_t ap_getsocketopt(ap_socket_t *sock, ap_int32_t opt, ap_int32_t *on)
  +{
  +    switch (opt) {
  +    case APR_SO_TIMEOUT: 
  +        /* Do we want to store sock->timeout in APR units or windows units? */
  +        *on = sock->timeout * 1000; /* Convert from milliseconds (windows units) to microseconds 
  +                                     * (APR units) */
  +        break;
  +    case APR_SO_KEEPALIVE:
  +    case APR_SO_DEBUG:
  +    case APR_SO_REUSEADDR:
  +    case APR_SO_NONBLOCK:
  +    case APR_SO_LINGER:
  +    default:
  +        return APR_ENOTIMPL;
  +        break;
  +    }
  +    return APR_SUCCESS;
  +}
  +
   
   ap_status_t ap_gethostname(char *buf, int len, ap_pool_t *cont)
   {
  
  
  
  1.16      +3 -3      apache-2.0/src/os/win32/iol_socket.c
  
  Index: iol_socket.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/iol_socket.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- iol_socket.c	2000/04/16 16:59:41	1.15
  +++ iol_socket.c	2000/06/14 20:56:00	1.16
  @@ -84,13 +84,13 @@
   
   static ap_status_t win32_getopt(ap_iol *viol, ap_iol_option opt, void *value)
   {
  +    /* XXX Todo: Convert iol to use APR time units... */
       iol_socket *iol = (iol_socket *)viol;
   
       switch (opt) {
       case AP_IOL_TIMEOUT:
  -#if 0
  -	*(int *)value = iol->timeout; // ToDo: Impleent this
  -#endif
  +        ap_getsocketopt(iol->sock, APR_SO_TIMEOUT, (ap_int32_t *) value);
  +        (*(ap_int32_t *)value) /= AP_USEC_PER_SEC;
   	break;
       default:
   	return APR_EINVAL;
  
  
  

Re: cvs commit: apache-2.0/src/os/win32 iol_socket.c

Posted by Manoj Kasichainula <ma...@io.com>.
On Wed, Jun 14, 2000 at 02:13:32PM -0700, rbb@covalent.net wrote:
> We've talked about this before.  My opinion currently is that IOL's are
> not necessarily very useful as they currently stand.  Basically, all iol's
> are is an abstraction around data stores (currently just files and
> sockets).  They don't really let people layer multiple iol's together to
> get real layering.

Sure they do. Create a new fudd_iol by passing another IOL to the
initialzation function. Each full_iol_{read,write,readv,writev} just
acts as a filtering function. It may not be perfectly efficient
(though I think it can be), and it may not be appropriate for Apache's
layering requirements (I haven't worked my way through the long
threads on that subject yet), but you can get basic layering set up
with them just fine.

> I have considered multiple times moving the iol's down
> to APR, because it is in the STATUS file.  Each time I begin to do the
> work, I look at what I am doing and I wonder how useful it is for APR.  I
> don't have a good answer, but I'm just not sure APR needs the iol's.

Getting back the beautiful feature in Unix where all I/O thingies have
the same interface would be a very good thing.

> Having said that, if we are going to move iol's down to APR, I would like
> them completely re-vamped.  Currently the iol's are basically adding
> another layer of indirection to the stack, which I believe is
> unecessary.

(Assuming you're actually talking about the execution stack instead of
a logical diagram...) And that can change very easily if the APR read
and write functions switch to using interfaces that match the IOLs'.
Then, the ap_iol_methods structure can just point to the APR functions
directly.  I advocated this a few months ago.


Re: cvs commit: apache-2.0/src/os/win32 iol_socket.c

Posted by rb...@covalent.net.
>   Do we need to move iol into APR?

We've talked about this before.  My opinion currently is that IOL's are
not necessarily very useful as they currently stand.  Basically, all iol's
are is an abstraction around data stores (currently just files and
sockets).  They don't really let people layer multiple iol's together to
get real layering.  I have considered multiple times moving the iol's down
to APR, because it is in the STATUS file.  Each time I begin to do the
work, I look at what I am doing and I wonder how useful it is for APR.  I
don't have a good answer, but I'm just not sure APR needs the iol's.

Having said that, if we are going to move iol's down to APR, I would like
them completely re-vamped.  Currently the iol's are basically adding
another layer of indirection to the stack, which I believe is
unecessary.  Basically, what we get right now is:

struct BUFF
    struct IOL
        struct ap_foo_t   (foo = (file | socket))

I believe we could make the ap_foo_t have the same fetures as iol's,
without the added layer.  I designed something like this about a year ago,
and posted about it to the list.  Some people ignored it, others seemed a
little interested.  I dropped it because I ran out of time.

Just my 0.02.

Ryan


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: cvs commit: apache-2.0/src/os/win32 iol_socket.c

Posted by rb...@covalent.net.
>   Do we need to move iol into APR?

We've talked about this before.  My opinion currently is that IOL's are
not necessarily very useful as they currently stand.  Basically, all iol's
are is an abstraction around data stores (currently just files and
sockets).  They don't really let people layer multiple iol's together to
get real layering.  I have considered multiple times moving the iol's down
to APR, because it is in the STATUS file.  Each time I begin to do the
work, I look at what I am doing and I wonder how useful it is for APR.  I
don't have a good answer, but I'm just not sure APR needs the iol's.

Having said that, if we are going to move iol's down to APR, I would like
them completely re-vamped.  Currently the iol's are basically adding
another layer of indirection to the stack, which I believe is
unecessary.  Basically, what we get right now is:

struct BUFF
    struct IOL
        struct ap_foo_t   (foo = (file | socket))

I believe we could make the ap_foo_t have the same fetures as iol's,
without the added layer.  I designed something like this about a year ago,
and posted about it to the list.  Some people ignored it, others seemed a
little interested.  I dropped it because I ran out of time.

Just my 0.02.

Ryan


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------