httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@hyperreal.org
Subject cvs commit: apache-2.0/src/lib/apr/network_io/os2 os2calls.c os2calls.h Makefile.in networkio.h poll.c sendrecv.c sockets.c sockopt.c
Date Fri, 29 Oct 1999 14:21:04 GMT
bjh         99/10/29 07:21:04

  Modified:    src/lib/apr/file_io/os2 maperrorcode.c
               src/lib/apr/network_io/os2 Makefile.in networkio.h poll.c
                        sendrecv.c sockets.c sockopt.c
  Added:       src/lib/apr/network_io/os2 os2calls.c os2calls.h
  Log:
  OS/2: Bypass EMX library's socket code and go straight to the OS/2 TCP/IP
  stack. This should be more efficient and prevents handle collisions when using
  native file API calls. This also means that file I/O calls (read()/write()
  etc) can no longer be used on sockets.
  
  Revision  Changes    Path
  1.3       +35 -1     apache-2.0/src/lib/apr/file_io/os2/maperrorcode.c
  
  Index: maperrorcode.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/maperrorcode.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- maperrorcode.c	1999/10/18 10:23:21	1.2
  +++ maperrorcode.c	1999/10/29 14:20:59	1.3
  @@ -59,6 +59,7 @@
   #include <errno.h>
   #include <string.h>
   #include <os2.h>
  +#include "../../network_io/os2/os2calls.h"
   
   
   int errormap[][2] = {
  @@ -74,7 +75,40 @@
       { ERROR_FILENAME_EXCED_RANGE, APR_ENAMETOOLONG },
       { ERROR_INVALID_FUNCTION,     APR_EINVAL       },
       { ERROR_INVALID_HANDLE,       APR_EBADF        },
  -    { ERROR_NEGATIVE_SEEK,        APR_ESPIPE       }
  +    { ERROR_NEGATIVE_SEEK,        APR_ESPIPE       },
  +    { SOCEWOULDBLOCK,           EWOULDBLOCK     },
  +    { SOCEINPROGRESS,           EINPROGRESS     },
  +    { SOCEALREADY,              EALREADY        },
  +    { SOCENOTSOCK,              ENOTSOCK        },
  +    { SOCEDESTADDRREQ,          EDESTADDRREQ    },
  +    { SOCEMSGSIZE,              EMSGSIZE        },
  +    { SOCEPROTOTYPE,            EPROTOTYPE      },
  +    { SOCENOPROTOOPT,           ENOPROTOOPT     },
  +    { SOCEPROTONOSUPPORT,       EPROTONOSUPPORT },
  +    { SOCESOCKTNOSUPPORT,       ESOCKTNOSUPPORT },
  +    { SOCEOPNOTSUPP,            EOPNOTSUPP      },
  +    { SOCEPFNOSUPPORT,          EPFNOSUPPORT    },
  +    { SOCEAFNOSUPPORT,          EAFNOSUPPORT    },
  +    { SOCEADDRINUSE,            EADDRINUSE      },
  +    { SOCEADDRNOTAVAIL,         EADDRNOTAVAIL   },
  +    { SOCENETDOWN,              ENETDOWN        },
  +    { SOCENETUNREACH,           ENETUNREACH     },
  +    { SOCENETRESET,             ENETRESET       },
  +    { SOCECONNABORTED,          ECONNABORTED    },
  +    { SOCECONNRESET,            ECONNRESET      },
  +    { SOCENOBUFS,               ENOBUFS         },
  +    { SOCEISCONN,               EISCONN         },
  +    { SOCENOTCONN,              ENOTCONN        },
  +    { SOCESHUTDOWN,             ESHUTDOWN       },
  +    { SOCETOOMANYREFS,          ETOOMANYREFS    },
  +    { SOCETIMEDOUT,             ETIMEDOUT       },
  +    { SOCECONNREFUSED,          ECONNREFUSED    },
  +    { SOCELOOP,                 ELOOP           },
  +    { SOCENAMETOOLONG,          ENAMETOOLONG    },
  +    { SOCEHOSTDOWN,             EHOSTDOWN       },
  +    { SOCEHOSTUNREACH,          EHOSTUNREACH    },
  +    { SOCENOTEMPTY,             ENOTEMPTY       },
  +    { SOCEPIPE,                 EPIPE           }
   };
   
   #define MAPSIZE (sizeof(errormap)/sizeof(errormap[0]))
  
  
  
  1.6       +2 -1      apache-2.0/src/lib/apr/network_io/os2/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/Makefile.in,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Makefile.in	1999/10/24 05:59:13	1.5
  +++ Makefile.in	1999/10/29 14:21:00	1.6
  @@ -18,7 +18,8 @@
   	sendrecv.o \
   	sockets.o \
   	sockopt.o \
  -	sockaddr.o
  +	sockaddr.o \
  +	os2calls.o
   
   .c.o:
   	$(CC) $(CFLAGS) -c $(INCLUDES) $<
  
  
  
  1.5       +3 -4      apache-2.0/src/lib/apr/network_io/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/networkio.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- networkio.h	1999/10/24 05:59:13	1.4
  +++ networkio.h	1999/10/29 14:21:00	1.5
  @@ -58,7 +58,10 @@
   
   #include "apr_network_io.h"
   #include "apr_general.h"
  +#include "os2calls.h"
   
  +int os2errno( unsigned long oserror );
  +
   struct socket_t {
       ap_context_t *cntxt;
       int socketdes;
  @@ -77,10 +80,6 @@
       int num_except;
       int num_total;
   };
  -
  -/* Pointers to dynamically linked API functions */
  -extern int (*os2_select)(int *, int, int, int, long);
  -extern int (*os2_sock_errno)();
   
   /* Error codes returned from sock_errno() */
   #define SOCBASEERR              10000
  
  
  
  1.7       +9 -67     apache-2.0/src/lib/apr/network_io/os2/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/poll.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- poll.c	1999/10/18 14:53:24	1.6
  +++ poll.c	1999/10/29 14:21:01	1.7
  @@ -66,13 +66,6 @@
   
   /*  OS/2 doesn't have a poll function, implement using OS/2 style select */
    
  -static int os2_select_init( int *s, int noreads, int nowrites, int noexcepts, long timeout
);
  -static int os2_sock_errno_init();
  -
  -int (*os2_select)(int *, int, int, int, long) = os2_select_init;
  -int (*os2_sock_errno)() = os2_sock_errno_init;
  -static HMODULE hSO32DLL;
  -
   ap_status_t ap_setup_poll(struct pollfd_t **new, ap_int32_t num, ap_context_t *cont)
   {
       *new = (struct pollfd_t *)ap_palloc(cont, sizeof(struct pollfd_t));
  @@ -148,16 +141,16 @@
   
       do {
           for (i=0; i<pollfdset->num_total; i++) {
  -            pollfdset->r_socket_list[i] = _getsockhandle(pollfdset->socket_list[i]);
  +            pollfdset->r_socket_list[i] = pollfdset->socket_list[i];
           }
           
  -        rv = os2_select(pollfdset->r_socket_list, 
  -                        pollfdset->num_read, 
  -                        pollfdset->num_write, 
  -                        pollfdset->num_except, 
  -                        timeout > 0 ? timeout * 1000 : -1);
  +        rv = select(pollfdset->r_socket_list, 
  +                    pollfdset->num_read, 
  +                    pollfdset->num_write, 
  +                    pollfdset->num_except, 
  +                    timeout >= 0 ? timeout * 1000 : -1);
   
  -        if (rv < 0 && os2_sock_errno() == SOCEINTR && timeout >=
0 ) {
  +        if (rv < 0 && sock_errno() == SOCEINTR && timeout >= 0 )
{
               time_t elapsed = time(NULL) - starttime;
   
               if (timeout <= elapsed)
  @@ -165,10 +158,10 @@
   
               timeout -= elapsed;
           }
  -    } while ( rv < 0 && os2_sock_errno() == SOCEINTR );
  +    } while ( rv < 0 && sock_errno() == SOCEINTR );
   
       (*nsds) = rv;
  -    return rv < 0 ? os2errno(os2_sock_errno()) : APR_SUCCESS;
  +    return rv < 0 ? os2errno(sock_errno()) : APR_SUCCESS;
   }
   
   
  @@ -231,55 +224,4 @@
       }
   
       return APR_SUCCESS;
  -}
  -
  -
  -
  -static int os2_fn_link()
  -{
  -    if (os2_select == os2_select_init || os2_select == NULL) {
  -        DosEnterCritSec(); /* Stop two threads doing this at the same time */
  -
  -        if (os2_select == os2_select_init || os2_select == NULL) {
  -            ULONG rc;
  -            char errorstr[200];
  -            
  -            rc = DosLoadModule(errorstr, sizeof(errorstr), "SO32DLL", &hSO32DLL);
  -            
  -            if (rc)
  -                return os2errno(rc);
  -
  -            rc = DosQueryProcAddr(hSO32DLL, 0, "SELECT", &os2_select);
  -            
  -            if (rc)
  -                return os2errno(rc);
  -
  -            rc = DosQueryProcAddr(hSO32DLL, 0, "SOCK_ERRNO", &os2_sock_errno);
  -            
  -            if (rc)
  -                return os2errno(rc);
  -        }
  -        DosExitCritSec();
  -    }
  -    return APR_SUCCESS;
  -}   
  -
  -
  -
  -static int os2_select_init(int *s, int noreads, int nowrites, int noexcepts, long timeout)
  -{
  -    int rc = os2_fn_link();
  -    if (rc == APR_SUCCESS)
  -        return os2_select(s, noreads, nowrites, noexcepts, timeout);
  -    return rc;
  -}
  -
  -
  -
  -static int os2_sock_errno_init()
  -{
  -    int rc = os2_fn_link();
  -    if (rc == APR_SUCCESS)
  -        return os2_sock_errno();
  -    return rc;
   }
  
  
  
  1.5       +18 -18    apache-2.0/src/lib/apr/network_io/os2/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sendrecv.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sendrecv.c	1999/10/29 14:00:03	1.4
  +++ sendrecv.c	1999/10/29 14:21:01	1.5
  @@ -67,17 +67,17 @@
       ssize_t rv;
       
       do {
  -        rv = write(sock->socketdes, buf, (*len));
  -    } while (rv == -1 && errno == EINTR);
  +        rv = send(sock->socketdes, buf, (*len), 0);
  +    } while (rv == -1 && sock_errno() == SOCEINTR);
   
  -    if (rv == -1 && errno == EAGAIN && sock->timeout > 0) {
  +    if (rv == -1 && sock_errno() == SOCEWOULDBLOCK && sock->timeout
!= 0) {
           int fds;
           int srv;
   
           do {
               fds = sock->socketdes;
  -            srv = os2_select(&fds, 0, 1, 0, sock->timeout);
  -        } while (srv == -1 && errno == EINTR);
  +            srv = select(&fds, 0, 1, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
  +        } while (srv == -1 && sock_errno() == SOCEINTR);
   
           if (srv == 0) {
               (*len) = -1;
  @@ -85,18 +85,18 @@
           }
           else if (srv < 0) {
               (*len) = -1;
  -            return errno;
  +            return os2errno(sock_errno());
           }
           else {
               do {
  -                rv = write(sock->socketdes, buf, (*len));
  -            } while (rv == -1 && errno == EINTR);
  +                rv = send(sock->socketdes, buf, (*len), 0);
  +            } while (rv == -1 && sock_errno() == SOCEINTR);
           }
       }
   
       if (rv < 0) {
           *len = 0;
  -        return errno;
  +        return os2errno(sock_errno());
       }
   
       (*len) = rv;
  @@ -110,17 +110,17 @@
       ssize_t rv;
       
       do {
  -        rv = read(sock->socketdes, buf, (*len));
  -    } while (rv == -1 && errno == EINTR);
  +        rv = recv(sock->socketdes, buf, (*len), 0);
  +    } while (rv == -1 && sock_errno() == SOCEINTR);
   
  -    if (rv == -1 && errno == EAGAIN && sock->timeout > 0) {
  +    if (rv == -1 && sock_errno() == SOCEWOULDBLOCK && sock->timeout
!= 0) {
           int fds;
           int srv;
   
           do {
               fds = sock->socketdes;
  -            srv = os2_select(&fds, 1, 0, 0, sock->timeout);
  -        } while (srv == -1 && errno == EINTR);
  +            srv = select(&fds, 1, 0, 0, sock->timeout >= 0 ? sock->timeout*1000
: -1);
  +        } while (srv == -1 && sock_errno() == SOCEINTR);
   
           if (srv == 0) {
               (*len) = -1;
  @@ -128,18 +128,18 @@
           }
           else if (srv < 0) {
               (*len) = -1;
  -            return errno;
  +            return os2errno(sock_errno());
           }
           else {
               do {
  -                rv = read(sock->socketdes, buf, (*len));
  -            } while (rv == -1 && errno == EINTR);
  +                rv = recv(sock->socketdes, buf, (*len), 0);
  +            } while (rv == -1 && sock_errno() == SOCEINTR);
           }
       }
   
       if (rv < 0) {
           *len = 0;
  -        return errno;
  +        return os2errno(sock_errno());
       }
   
       (*len) = rv;
  
  
  
  1.7       +12 -11    apache-2.0/src/lib/apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- sockets.c	1999/10/24 13:08:25	1.6
  +++ sockets.c	1999/10/29 14:21:01	1.7
  @@ -65,16 +65,17 @@
   #include <netinet/in.h>
   #include <arpa/inet.h>
   #include <netdb.h>
  +#include "os2calls.h"
   
   ap_status_t socket_cleanup(void *sock)
   {
       struct socket_t *thesocket = sock;
  -    if (close(thesocket->socketdes) == 0) {
  +    if (soclose(thesocket->socketdes) == 0) {
           thesocket->socketdes = -1;
           return APR_SUCCESS;
       }
       else {
  -        return errno;
  +        return os2errno(sock_errno());
       }
   }
   
  @@ -95,7 +96,7 @@
           return APR_ENOMEM;
       }
    
  -    (*new)->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
  +    (*new)->socketdes = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   
       (*new)->local_addr->sin_family = AF_INET;
       (*new)->remote_addr->sin_family = AF_INET;
  @@ -103,7 +104,7 @@
       (*new)->addr_len = sizeof(*(*new)->local_addr);
       
       if ((*new)->socketdes < 0) {
  -        return errno;
  +        return os2errno(sock_errno());
       }
       (*new)->timeout = -1;
       ap_register_cleanup((*new)->cntxt, (void *)(*new), 
  @@ -117,7 +118,7 @@
           return APR_SUCCESS;
       }
       else {
  -        return errno;
  +        return os2errno(sock_errno());
       }
   }
   
  @@ -134,7 +135,7 @@
   {
       sock->local_addr->sin_addr.s_addr = INADDR_ANY;
       if (bind(sock->socketdes, (struct sockaddr *)sock->local_addr, sock->addr_len)
== -1)
  -        return errno;
  +        return os2errno(sock_errno());
       else
           return APR_SUCCESS;
   }
  @@ -142,7 +143,7 @@
   ap_status_t ap_listen(struct socket_t *sock, ap_int32_t backlog)
   {
       if (listen(sock->socketdes, backlog) == -1)
  -        return errno;
  +        return os2errno(sock_errno());
       else
           return APR_SUCCESS;
   }
  @@ -162,7 +163,7 @@
                           &(*new)->addr_len);
   
       if ((*new)->socketdes < 0) {
  -        return errno;
  +        return os2errno(sock_errno());
       }
   
       ap_register_cleanup((*new)->cntxt, (void *)(*new), 
  @@ -191,9 +192,9 @@
           sock->addr_len = sizeof(*sock->remote_addr);
       }
   
  -    if ((connect(sock->socketdes, (const struct sockaddr *)sock->remote_addr, sock->addr_len)
< 0) &&
  -        (errno != EINPROGRESS)) {
  -        return errno;
  +    if ((connect(sock->socketdes, (struct sockaddr *)sock->remote_addr, sock->addr_len)
< 0) &&
  +        (sock_errno() != SOCEINPROGRESS)) {
  +        return os2errno(sock_errno());
       }
       else {
           int namelen = sizeof(*sock->local_addr);
  
  
  
  1.6       +93 -1     apache-2.0/src/lib/apr/network_io/os2/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockopt.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sockopt.c	1999/10/18 11:32:13	1.5
  +++ sockopt.c	1999/10/29 14:21:02	1.6
  @@ -53,4 +53,96 @@
    *
    */
   
  -#include "../unix/sockopt.c"
  +#include "networkio.h"
  +#include "apr_network_io.h"
  +#include "apr_general.h"
  +#include "apr_lib.h"
  +#include <errno.h>
  +#include <string.h>
  +#include <sys/socket.h>
  +#include <netinet/tcp.h>
  +#include <netinet/in.h>
  +#include <unistd.h>
  +#include <netdb.h>
  +#include <sys/so_ioctl.h>
  +
  +
  +ap_status_t ap_setsocketopt(struct socket_t *sock, ap_int32_t opt, ap_int32_t on)
  +{
  +    int one;
  +    struct linger li;
  +
  +    if (on)
  +        one = 1;
  +    else
  +        one = 0;
  +
  +    if (opt & APR_SO_KEEPALIVE) {
  +        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_KEEPALIVE, (void *)&one,
sizeof(int)) == -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_DEBUG) {
  +        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int))
== -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_REUSEADDR) {
  +        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
sizeof(int)) == -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_SNDBUF) {
  +        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_SNDBUF, (void *)&on, sizeof(int))
== -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_NONBLOCK) {
  +        if (ioctl(sock->socketdes, FIONBIO, (caddr_t)&on, sizeof(on)) == -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_LINGER) {
  +        li.l_onoff = on;
  +        li.l_linger = MAX_SECS_TO_LINGER;
  +        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct
linger)) == -1) {
  +            return os2errno(sock_errno());
  +        }
  +    }
  +    if (opt & APR_SO_TIMEOUT) {
  +        sock->timeout = on;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +
  +
  +ap_status_t ap_gethostname(char *buf, ap_int32_t len, ap_context_t *cont)
  +{
  +    if (gethostname(buf, len) == -1)
  +        return os2errno(sock_errno());
  +    else
  +        return APR_SUCCESS;
  +}
  +
  +
  +
  +ap_status_t ap_get_remote_hostname(char **name, struct socket_t *sock)
  +{
  +    struct hostent *hptr;
  +
  +    hptr = gethostbyaddr((char *)&(sock->remote_addr->sin_addr),
  +                         sizeof(struct in_addr), AF_INET);
  +    if (hptr != NULL) {
  +        *name = ap_pstrdup(sock->cntxt, hptr->h_name);
  +        if (*name) {
  +            return APR_SUCCESS;
  +        }
  +        return APR_ENOMEM;
  +    }
  +
  +    /* XXX - Is this threadsafe? */
  +    return h_errno;
  +}
  +
  +
  
  
  
  1.1                  apache-2.0/src/lib/apr/network_io/os2/os2calls.c
  
  Index: os2calls.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  
  #include "networkio.h"
  #include "apr_network_io.h"
  #include "apr_portable.h"
  #include "apr_general.h"
  #include "apr_lib.h"
  #define INCL_DOS
  #include <os2.h>
  
  static int os2_socket_init(int, int ,int);
  
  int (*apr_os2_socket)(int, int, int) = os2_socket_init;
  int (*apr_os2_select)(int *, int, int, int, long) = NULL;
  int (*apr_os2_sock_errno)() = NULL;
  int (*apr_os2_accept)(int, struct sockaddr *, int *) = NULL;
  int (*apr_os2_bind)(int, struct sockaddr *, int) = NULL;
  int (*apr_os2_connect)(int, struct sockaddr *, int) = NULL;
  int (*apr_os2_getpeername)(int, struct sockaddr *, int *) = NULL;
  int (*apr_os2_getsockname)(int, struct sockaddr *, int *) = NULL;
  int (*apr_os2_getsockopt)(int, int, int, char *, int *) = NULL;
  int (*apr_os2_ioctl)(int, int, caddr_t, int) = NULL;
  int (*apr_os2_listen)(int, int) = NULL;
  int (*apr_os2_recv)(int, char *, int, int) = NULL;
  int (*apr_os2_send)(int, const char *, int, int) = NULL;
  int (*apr_os2_setsockopt)(int, int, int, char *, int) = NULL;
  int (*apr_os2_shutdown)(int, int) = NULL;
  int (*apr_os2_soclose)(int) = NULL;
  int (*apr_os2_writev)(int, struct iovec *, int) = NULL;
  
  static HMODULE hSO32DLL;
  
  static int os2_fn_link()
  {
      DosEnterCritSec(); /* Stop two threads doing this at the same time */
  
      if (apr_os2_socket == os2_socket_init) {
          ULONG rc;
          char errorstr[200];
  
          rc = DosLoadModule(errorstr, sizeof(errorstr), "SO32DLL", &hSO32DLL);
  
          if (rc)
              return os2errno(rc);
  
          rc = DosQueryProcAddr(hSO32DLL, 0, "SOCKET", &apr_os2_socket);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SELECT", &apr_os2_select);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SOCK_ERRNO", &apr_os2_sock_errno);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "ACCEPT", &apr_os2_accept);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "BIND", &apr_os2_bind);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "CONNECT", &apr_os2_connect);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "GETPEERNAME", &apr_os2_getpeername);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKNAME", &apr_os2_getsockname);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKOPT", &apr_os2_getsockopt);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "IOCTL", &apr_os2_ioctl);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "LISTEN", &apr_os2_listen);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "RECV", &apr_os2_recv);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SEND", &apr_os2_send);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SETSOCKOPT", &apr_os2_setsockopt);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SHUTDOWN", &apr_os2_shutdown);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "SOCLOSE", &apr_os2_soclose);
  
          if (!rc)
              rc = DosQueryProcAddr(hSO32DLL, 0, "WRITEV", &apr_os2_writev);
  
          if (rc)
              return os2errno(rc);
      }
  
      DosExitCritSec();
      return APR_SUCCESS;
  }
  
  
  
  static int os2_socket_init(int domain, int type, int protocol)
  {
      int rc = os2_fn_link();
      if (rc == APR_SUCCESS)
          return apr_os2_socket(domain, type, protocol);
      return rc;
  }
  
  
  
  1.1                  apache-2.0/src/lib/apr/network_io/os2/os2calls.h
  
  Index: os2calls.h
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include <sys/types.h>
  #include <sys/socket.h>
  
  extern int (*apr_os2_socket)(int, int, int);
  extern int (*apr_os2_select)(int *, int, int, int, long);
  extern int (*apr_os2_sock_errno)();
  extern int (*apr_os2_accept)(int, struct sockaddr *, int *);
  extern int (*apr_os2_bind)(int, struct sockaddr *, int);
  extern int (*apr_os2_connect)(int, struct sockaddr *, int);
  extern int (*apr_os2_getpeername)(int, struct sockaddr *, int *);
  extern int (*apr_os2_getsockname)(int, struct sockaddr *, int *);
  extern int (*apr_os2_getsockopt)(int, int, int, char *, int *);
  extern int (*apr_os2_ioctl)(int, int, caddr_t, int);
  extern int (*apr_os2_listen)(int, int);
  extern int (*apr_os2_recv)(int, char *, int, int);
  extern int (*apr_os2_send)(int, const char *, int, int);
  extern int (*apr_os2_setsockopt)(int, int, int, char *, int);
  extern int (*apr_os2_shutdown)(int, int);
  extern int (*apr_os2_soclose)(int);
  extern int (*apr_os2_writev)(int, struct iovec *, int);
  
  #define socket apr_os2_socket
  #define select apr_os2_select
  #define sock_errno apr_os2_sock_errno
  #define accept apr_os2_accept
  #define bind apr_os2_bind
  #define connect apr_os2_connect
  #define getpeername apr_os2_getpeername
  #define getsockname apr_os2_getsockname
  #define getsockopt apr_os2_getsockopt
  #define ioctl apr_os2_ioctl
  #define listen apr_os2_listen
  #define recv apr_os2_recv
  #define send apr_os2_send
  #define setsockopt apr_os2_setsockopt
  #define shutdown apr_os2_shutdown
  #define soclose apr_os2_soclose
  #define writev apr_os2_writev
  
  
  /* Error codes returned by above calls */
  #define SOCBASEERR              10000
  
  #define SOCEPERM                (SOCBASEERR+1)             /* Not owner */
  #define SOCESRCH                (SOCBASEERR+3)             /* No such process */
  #define SOCEINTR                (SOCBASEERR+4)             /* Interrupted system call */
  #define SOCENXIO                (SOCBASEERR+6)             /* No such device or address
*/
  #define SOCEBADF                (SOCBASEERR+9)             /* Bad file number */
  #define SOCEACCES               (SOCBASEERR+13)            /* Permission denied */
  #define SOCEFAULT               (SOCBASEERR+14)            /* Bad address */
  #define SOCEINVAL               (SOCBASEERR+22)            /* Invalid argument */
  #define SOCEMFILE               (SOCBASEERR+24)            /* Too many open files */
  #define SOCEPIPE                (SOCBASEERR+32)            /* Broken pipe */
  #define SOCEOS2ERR              (SOCBASEERR+100)           /* OS/2 Error */
  #define SOCEWOULDBLOCK          (SOCBASEERR+35)            /* Operation would block */
  #define SOCEINPROGRESS          (SOCBASEERR+36)            /* Operation now in progress
*/
  #define SOCEALREADY             (SOCBASEERR+37)            /* Operation already in progress
*/
  #define SOCENOTSOCK             (SOCBASEERR+38)            /* Socket operation on non-socket
*/
  #define SOCEDESTADDRREQ         (SOCBASEERR+39)            /* Destination address required
*/
  #define SOCEMSGSIZE             (SOCBASEERR+40)            /* Message too long */
  #define SOCEPROTOTYPE           (SOCBASEERR+41)            /* Protocol wrong type for socket
*/
  #define SOCENOPROTOOPT          (SOCBASEERR+42)            /* Protocol not available */
  #define SOCEPROTONOSUPPORT      (SOCBASEERR+43)            /* Protocol not supported */
  #define SOCESOCKTNOSUPPORT      (SOCBASEERR+44)            /* Socket type not supported
*/
  #define SOCEOPNOTSUPP           (SOCBASEERR+45)            /* Operation not supported on
socket */
  #define SOCEPFNOSUPPORT         (SOCBASEERR+46)            /* Protocol family not supported
*/
  #define SOCEAFNOSUPPORT         (SOCBASEERR+47)            /* Address family not supported
by protocol family */
  #define SOCEADDRINUSE           (SOCBASEERR+48)            /* Address already in use */
  #define SOCEADDRNOTAVAIL        (SOCBASEERR+49)            /* Can't assign requested address
*/
  #define SOCENETDOWN             (SOCBASEERR+50)            /* Network is down */
  #define SOCENETUNREACH          (SOCBASEERR+51)            /* Network is unreachable */
  #define SOCENETRESET            (SOCBASEERR+52)            /* Network dropped connection
on reset */
  #define SOCECONNABORTED         (SOCBASEERR+53)            /* Software caused connection
abort */
  #define SOCECONNRESET           (SOCBASEERR+54)            /* Connection reset by peer */
  #define SOCENOBUFS              (SOCBASEERR+55)            /* No buffer space available
*/
  #define SOCEISCONN              (SOCBASEERR+56)            /* Socket is already connected
*/
  #define SOCENOTCONN             (SOCBASEERR+57)            /* Socket is not connected */
  #define SOCESHUTDOWN            (SOCBASEERR+58)            /* Can't send after socket shutdown
*/
  #define SOCETOOMANYREFS         (SOCBASEERR+59)            /* Too many references: can't
splice */
  #define SOCETIMEDOUT            (SOCBASEERR+60)            /* Connection timed out */
  #define SOCECONNREFUSED         (SOCBASEERR+61)            /* Connection refused */
  #define SOCELOOP                (SOCBASEERR+62)            /* Too many levels of symbolic
links */
  #define SOCENAMETOOLONG         (SOCBASEERR+63)            /* File name too long */
  #define SOCEHOSTDOWN            (SOCBASEERR+64)            /* Host is down */
  #define SOCEHOSTUNREACH         (SOCBASEERR+65)            /* No route to host */
  #define SOCENOTEMPTY            (SOCBASEERR+66)            /* Directory not empty */
  
  
  

Mime
View raw message