apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: apr/poll/os2 .cvsignore poll.c
Date Thu, 11 Jul 2002 16:00:11 GMT
bjh         2002/07/11 09:00:08

  Modified:    poll/os2 poll.c
  Added:       poll/os2 .cvsignore
  Log:
  OS/2: rewrite apr_poll() with the new interface.
  There's probably room for optimization here but this at least gets us going
  again & passes testpoll.
  
  Revision  Changes    Path
  1.2       +69 -106   apr/poll/os2/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apr/poll/os2/poll.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- poll.c	11 Jul 2002 05:40:23 -0000	1.1
  +++ poll.c	11 Jul 2002 16:00:08 -0000	1.2
  @@ -52,127 +52,90 @@
    * <http://www.apache.org/>.
    */
   
  +#include "apr.h"
  +#include "apr_poll.h"
   #include "networkio.h"
  -#include "apr_network_io.h"
  -#include "apr_general.h"
  -#include "apr_portable.h"
  -#include "apr_lib.h"
  -#include <sys/time.h>
  -#include <stdlib.h>
  -
  -/*  OS/2 doesn't have a poll function, implement using OS/2 style select */
  - 
  -APR_DECLARE(apr_status_t) apr_poll_setup(apr_pollfd_t **new, apr_int32_t num, apr_pool_t
*cont)
  +
  +APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
  +                      apr_int32_t *nsds, apr_interval_time_t timeout)
   {
  -    *new = (apr_pollfd_t *)apr_palloc(cont, sizeof(apr_pollfd_t));
  +    int *pollset;
  +    int i;
  +    int num_read = 0, num_write = 0, num_except = 0, num_total;
  +    int pos_read, pos_write, pos_except;
   
  -    if (*new == NULL) {
  -        return APR_ENOMEM;
  +    for (i = 0; i < num; i++) {
  +        num_read += (aprset[i].reqevents & APR_POLLIN) != 0;
  +        num_write += (aprset[i].reqevents & APR_POLLOUT) != 0;
  +        num_except += (aprset[i].reqevents & APR_POLLPRI) != 0;
       }
   
  -    (*new)->socket_list = apr_palloc(cont, sizeof(int) * num);
  -    
  -    if ((*new)->socket_list == NULL) {
  -        return APR_ENOMEM;
  -    }
  -    
  -    (*new)->r_socket_list = apr_palloc(cont, sizeof(int) * num);
  -    
  -    if ((*new)->r_socket_list == NULL) {
  -        return APR_ENOMEM;
  -    }
  -    
  -    (*new)->cntxt = cont;
  -    (*new)->num_total = 0;
  -    (*new)->num_read = 0;
  -    (*new)->num_write = 0;
  -    (*new)->num_except = 0;
  -    
  -    return APR_SUCCESS;
  -}
  +    num_total = num_read + num_write + num_except;
  +    pollset = alloca(sizeof(int) * num_total);
  +    memset(pollset, 0, sizeof(int) * num_total);
  +
  +    pos_read = 0;
  +    pos_write = num_read;
  +    pos_except = pos_write + num_write;
   
  +    for (i = 0; i < num; i++) {
  +        if (aprset[i].desc_type == APR_POLL_SOCKET) {
  +            if (aprset[i].reqevents & APR_POLLIN) {
  +                pollset[pos_read++] = aprset[i].desc.s->socketdes;
  +            }
  +
  +            if (aprset[i].reqevents & APR_POLLOUT) {
  +                pollset[pos_write++] = aprset[i].desc.s->socketdes;
  +            }
  +
  +            if (aprset[i].reqevents & APR_POLLPRI) {
  +                pollset[pos_except++] = aprset[i].desc.s->socketdes;
  +            }
   
  +            aprset[i].rtnevents = 0;
  +        }
  +    }
   
  -APR_DECLARE(apr_status_t) apr_poll_socket_add(apr_pollfd_t *aprset, 
  -			                                  apr_socket_t *sock, apr_int16_t events)
  -{
  -    int i;
  -    
  -    if (events & APR_POLLIN) {
  -        for (i=aprset->num_total; i>aprset->num_read; i--)
  -            aprset->socket_list[i] = aprset->socket_list[i-1];
  -        aprset->socket_list[i] = sock->socketdes;
  -        aprset->num_read++;
  -        aprset->num_total++;
  -    }
  -            
  -    if (events & APR_POLLOUT) {
  -        for (i=aprset->num_total; i>aprset->num_read + aprset->num_write; i--)
  -            aprset->socket_list[i] = aprset->socket_list[i-1];
  -        aprset->socket_list[i] = sock->socketdes;
  -        aprset->num_write++;
  -        aprset->num_total++;
  -    }            
  -        
  -    if (events &APR_POLLPRI) {
  -        aprset->socket_list[aprset->num_total] = sock->socketdes;
  -        aprset->num_except++;
  -        aprset->num_total++;
  +    if (timeout > 0) {
  +        timeout /= 1000; /* convert microseconds to milliseconds */
       }
  -    return APR_SUCCESS;
  -}
   
  +    i = select(pollset, num_read, num_write, num_except, timeout);
  +    (*nsds) = i;
   
  +    if ((*nsds) < 0) {
  +        return APR_FROM_OS_ERROR(sock_errno());
  +    }
   
  -APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *pollfdset, int num,
  -                                   apr_int32_t *nsds, 
  -                                   apr_interval_time_t timeout)
  -{
  -    int i;
  -    int rv = 0;
  -    int num_read = 0, num_write = 0, num_except = 0;
  -    int *socket_list;
  -    
  -    for (i = 0; i < num; i++) {
  -        int events = pollfdset[i].events;
  -        int fd;
  +    if ((*nsds) == 0) {
  +        return APR_TIMEUP;
  +    }
   
  -        if (pollfdset[i].desc_type == APR_POLL_SOCKET) {
  -            fd = pollfdset[i].desc.s->socketdes;
  -        }
  -        else if (pollfdset[i].desc_type == APR_POLL_FILE) {
  -            fd = pollfdset[i].desc.f->filedes;
  -        }
  +    pos_read = 0;
  +    pos_write = num_read;
  +    pos_except = pos_write + num_write;
   
  -        if (events & APR_POLLIN) {
  -            socket_list[num_read] = fd;
  -            num_read++;
  -        }
  -            
  -        if (events & APR_POLLOUT) {
  -            socket_list[num_write] = fd;
  -            num_write++;
  -        }            
  -        
  -        if (events &APR_POLLPRI) {
  -            socket_list[num_except] = fd;
  -            num_except++;
  +    for (i = 0; i < num; i++) {
  +        if (aprset[i].desc_type == APR_POLL_SOCKET) {
  +            if (aprset[i].reqevents & APR_POLLIN) {
  +                if (pollset[pos_read++] > 0) {
  +                    aprset[i].rtnevents |= APR_POLLIN;
  +                }
  +            }
  +
  +            if (aprset[i].reqevents & APR_POLLOUT) {
  +                if (pollset[pos_write++] > 0) {
  +                    aprset[i].rtnevents |= APR_POLLOUT;
  +                }
  +            }
  +
  +            if (aprset[i].reqevents & APR_POLLPRI) {
  +                if (pollset[pos_except++] > 0) {
  +                    aprset[i].rtnevents |= APR_POLLPRI;
  +                }
  +            }
           }
       }
   
  -    rv = select(socket_list,
  -                num_read,
  -                num_write,
  -                num_except,
  -                timeout >= 0 ? timeout / 1000 : -1);
  -
  -    /* select() doesn't wipe the socket list in the case of a timeout or
  -     * interrupt. This prevents false positives from revents_get
  -     */
  -    if (rv == 0) {
  -        return timeout < 0 ? APR_EINTR : APR_TIMEUP;
  -    }
  -
  -    (*nsds) = rv;
  -    return rv < 0 ? APR_OS2_STATUS(sock_errno()) : APR_SUCCESS;
  +    return APR_SUCCESS;
   }
  
  
  
  1.1                  apr/poll/os2/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  Makefile
  *.lo
  .libs
  .deps
  
  
  

Mime
View raw message