bjh         99/10/29 07:37:33

  Modified:    src/os/os2 iol_socket.h iol_socket.c
               src/modules/mpm/spmt_os2 spmt_os2.c
  Log:
  OS/2: APRize iol_socket
  
  Revision  Changes    Path
  1.2       +3 -1      apache-2.0/src/os/os2/iol_socket.h
  
  Index: iol_socket.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/os2/iol_socket.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- iol_socket.h      1999/07/11 14:49:07     1.1
  +++ iol_socket.h      1999/10/29 14:37:27     1.2
  @@ -58,6 +58,8 @@
   #ifndef OS_UNIX_IOL_SOCKET_H
   #define OS_UNIX_IOL_SOCKET_H
   
  -ap_iol *os2_attach_socket(int fd);
  +#include <apr_network_io.h>
  +
  +ap_iol *os2_attach_socket(ap_socket_t *sock);
   
   #endif
  
  
  
  1.4       +34 -50    apache-2.0/src/os/os2/iol_socket.c
  
  Index: iol_socket.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/os2/iol_socket.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- iol_socket.c      1999/10/21 09:03:09     1.3
  +++ iol_socket.c      1999/10/29 14:37:28     1.4
  @@ -59,6 +59,8 @@
   #include "httpd.h"
   #include "ap_iol.h"
   #include "iol_socket.h"
  +#include <apr_network_io.h>
  +#include <apr_file_io.h>
   
   #include <errno.h>
   #include <sys/types.h>
  @@ -68,19 +70,15 @@
   
   typedef struct {
       ap_iol iol;
  -    int fd;
  -    int flags;
  -    int timeout;
  +    ap_socket_t *sock;
   } iol_socket;
   
   static ap_status_t os2_setopt(ap_iol *viol, ap_iol_option opt,
                                  const void *value)
   {
  -    iol_socket *iol = (iol_socket *)viol;
  -
       switch (opt) {
       case AP_IOL_TIMEOUT:
  -     iol->timeout = *(const int *)value;
  +        ap_setsocketopt(((iol_socket *)viol)->sock, APR_SO_TIMEOUT, *(const 
int *)value);
        break;
       default:
        return APR_EINVAL;
  @@ -90,42 +88,15 @@
   
   static ap_status_t os2_getopt(ap_iol *viol, ap_iol_option opt, void *value)
   {
  -    iol_socket *iol = (iol_socket *)viol;
  -
       switch (opt) {
       case AP_IOL_TIMEOUT:
  -     *(int *)value = iol->timeout;
  -     break;
  +    /* There's no APR getopt yet but nothing uses this option anyway */
       default:
        return APR_EINVAL;
       }
       return APR_SUCCESS;
   }
   
  -static ap_status_t set_nonblock(int fd)
  -{
  -    int fd_flags;
  -    int rv;
  -
  -    fd_flags = fcntl(fd, F_GETFL, 0);
  -#if defined(O_NONBLOCK)
  -    fd_flags |= O_NONBLOCK;
  -    rv = fcntl(fd, F_SETFL, fd_flags);
  -#elif defined(O_NDELAY)
  -    fd_flags |= O_NDELAY;
  -    rv = fcntl(fd, F_SETFL, fd_flags);
  -#elif defined(FNDELAY)
  -    fd_flags |= O_FNDELAY;
  -    rv = fcntl(fd, F_SETFL, fd_flags);
  -#else
  -#error "your unix lacks non-blocking i/o, you lose"
  -#endif
  -    if (rv == 0) {
  -        return APR_SUCCESS;
  -    }
  -    return errno;
  -}
  -
   /* the timeout code is a separate routine because it requires
       a stack frame... and we don't want to pay that setup cost
       on every call */
  @@ -148,6 +119,7 @@
            rv = ap_select(iol->fd + 1, selread, selwrite, NULL, iol->timeout < 
0 ? NULL : &tv); \
        } while (rv == -1 && errno == EINTR); \
        if (!FD_ISSET(iol->fd, &fdset)) { \
  +            *nbytes = 0; \
            return APR_ETIMEDOUT; \
        } \
        do { \
  @@ -157,6 +129,7 @@
               *nbytes = rv; \
               return APR_SUCCESS; \
           } \
  +        *nbytes = 0; \
        return errno; \
        \
       } \
  @@ -166,7 +139,7 @@
        iol_socket *iol = (iol_socket *)viol; \
        int rv; \
    \
  -        /* Present to zero until some bytes are actually written */ \
  +        /* Preset to zero until some bytes are actually written */ \
           *nbytes = 0; \
        if (!(iol->flags & FD_NONBLOCKING_SET)) { \
            if (iol->timeout < 0) { \
  @@ -189,27 +162,44 @@
        do { \
            rv = syscall(iol->fd, arg1, arg2); \
        } while (rv == -1 && errno == EINTR); \
  -     if ((errno == EWOULDBLOCK || errno == EAGAIN) && iol->timeout != 0) { \
  -         return os2_##name##_timeout(viol, arg1, arg2, nbytes); \
  -     } \
        if (rv >= 0) { \
            *nbytes = rv; \
               return APR_SUCCESS; \
        } \
  +     if ((errno == EWOULDBLOCK || errno == EAGAIN) && iol->timeout != 0) { \
  +         return os2_##name##_timeout(viol, arg1, arg2, nbytes); \
  +     } \
        return errno; \
       }
  +
  +// method(write, (ap_iol *viol, const char *arg1, ap_size_t arg2, ap_ssize_t 
*nbytes), write, NULL, &fdset)
  +ap_status_t os2_write(ap_iol *viol, const char *buf, ap_size_t size, 
ap_ssize_t *nbytes)
  +{
  +    *nbytes = size;
  +    return ap_send(((iol_socket *)viol)->sock, buf, nbytes);
  +}
   
  -method(write, (ap_iol *viol, const char *arg1, ap_size_t arg2, ap_ssize_t 
*nbytes), write, NULL, &fdset)
  -method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2, ap_ssize_t 
*nbytes), writev, NULL, &fdset)
  -method(read, (ap_iol *viol, char *arg1, ap_size_t arg2, ap_ssize_t *nbytes), 
read, &fdset, NULL)
  +// method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2, 
ap_ssize_t *nbytes), writev, NULL, &fdset)
  +ap_status_t os2_writev(ap_iol *viol, const struct iovec *vec, int size, 
ap_ssize_t *nbytes)
  +{
  +    *nbytes = size;
  +    return ap_sendv(((iol_socket *)viol)->sock, vec, size, nbytes);
  +}
   
  +// method(read, (ap_iol *viol, char *arg1, ap_size_t arg2, ap_ssize_t 
*nbytes), read, &fdset, NULL)
  +ap_status_t os2_read(ap_iol *viol, char *buf, ap_size_t size, ap_ssize_t 
*nbytes)
  +{
  +    *nbytes = size;
  +    return ap_recv(((iol_socket *)viol)->sock, buf, nbytes);
  +}
  +
   static ap_status_t os2_close(ap_iol *viol)
   {
       iol_socket *iol = (iol_socket *)viol;
       int rv;
       int saved_errno;
   
  -    rv = close(iol->fd);
  +    rv = ap_close_socket(iol->sock);
       saved_errno = errno;
       free(iol);
       if (rv == 0) {
  @@ -227,18 +217,12 @@
       os2_getopt
   };
   
  -ap_iol *os2_attach_socket(int fd)
  +ap_iol *os2_attach_socket(ap_socket_t *sock)
   {
       iol_socket *iol;
   
  -    if (fd >= FD_SETSIZE) {
  -     errno = EBADF;
  -     return NULL;
  -    }
       iol = malloc(sizeof(iol_socket));
       iol->iol.methods = &socket_methods;
  -    iol->fd = fd;
  -    iol->timeout = -1;
  -    iol->flags = 0;
  +    iol->sock = sock;
       return (ap_iol *)iol;
   }
  
  
  
  1.19      +10 -29    apache-2.0/src/modules/mpm/spmt_os2/spmt_os2.c
  
  Index: spmt_os2.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/spmt_os2/spmt_os2.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- spmt_os2.c        1999/10/24 13:08:30     1.18
  +++ spmt_os2.c        1999/10/29 14:37:31     1.19
  @@ -100,7 +100,6 @@
   /* *Non*-shared http_main globals... */
   
   static server_rec *server_conf;
  -static int listenmaxfd;
   
   /* one_process --- debugging mode variable; can be set from the command line
    * with the -X flag.  If set, this gets you the child_main loop running
  @@ -834,7 +833,7 @@
   }
   
   #if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
  -static void sock_disable_nagle(int s)
  +static void sock_disable_nagle(ap_socket_t *s)
   {
       /* The Nagle algorithm says that we should delay sending partial
        * packets in hopes of getting more data.  We don't want to do
  @@ -846,10 +845,11 @@
        * In spite of these problems, failure here is not a shooting offense.
        */
       int just_say_no = 1;
  +    ap_status_t status;
   
  -    if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &just_say_no,
  -                sizeof(int)) < 0) {
  -     ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf,
  +    status = ap_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) 
&just_say_no, sizeof(int));
  +    if (status != APR_SUCCESS) {
  +     ap_log_error(APLOG_MARK, APLOG_WARNING, status, server_conf,
                    "setsockopt: (TCP_NODELAY)");
       }
   }
  @@ -901,9 +901,6 @@
   
   static void child_main(void *child_num_arg)
   {
  -    NET_SIZE_T clen;
  -    struct sockaddr sa_server;
  -    struct sockaddr sa_client;
       ap_listen_rec *lr = NULL;
       ap_listen_rec *first_lr = NULL;
       ap_context_t *ptrans;
  @@ -914,7 +911,7 @@
       int requests_this_child = 0;
       ap_pollfd_t *listen_poll;
       ap_socket_t *csd = NULL;
  -    int nsds, rv, sockdes;
  +    int nsds, rv;
   
       /* Disable the restart signal handlers and enable the just_die stuff.
        * Note that since restart() just notes that a restart has been
  @@ -1133,29 +1130,13 @@
         * socket options, file descriptors, and read/write buffers.
         */
   
  -        ap_get_os_sock(&sockdes, csd);
  -     clen = sizeof(sa_server);
  -     if (getsockname(sockdes, &sa_server, &clen) < 0) {
  -         ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf, 
"getsockname");
  -         ap_close_socket(csd);
  -         continue;
  -     }
  -
  -     sock_disable_nagle(sockdes);
  +     sock_disable_nagle(csd);
   
  -        iol = os2_attach_socket(sockdes);
  +        iol = os2_attach_socket(csd);
   
        if (iol == NULL) {
  -         if (errno == EBADF) {
  -             ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
  -                 "filedescriptor (%u) larger than FD_SETSIZE (%u) "
  -                 "found, you probably need to rebuild Apache with a "
  -                 "larger FD_SETSIZE", sockdes, FD_SETSIZE);
  -         }
  -         else {
  -             ap_log_error(APLOG_MARK, APLOG_WARNING, errno, NULL,
  -                 "error attaching to socket");
  -         }
  +          ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, NULL,
  +                       "error attaching to socket");
            ap_close_socket(csd);
            continue;
           }
  
  
  

Reply via email to