apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: apr/network_io/os2 os2calls.c sendrecv_udp.c sockets.c
Date Tue, 24 Jul 2001 16:05:24 GMT
bjh         01/07/24 09:05:24

  Modified:    include/arch/os2 networkio.h os2calls.h
               network_io/os2 os2calls.c sendrecv_udp.c sockets.c
  Log:
  OS/2: Add support for datagram sockets.
  Mostly adapted from the unix code.
  
  Revision  Changes    Path
  1.22      +1 -0      apr/include/arch/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/networkio.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- networkio.h	2001/07/16 20:37:00	1.21
  +++ networkio.h	2001/07/24 16:05:24	1.22
  @@ -66,6 +66,7 @@
   struct apr_socket_t {
       apr_pool_t *cntxt;
       int socketdes;
  +    int type;
       apr_sockaddr_t *local_addr;
       apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout;
  
  
  
  1.7       +4 -0      apr/include/arch/os2/os2calls.h
  
  Index: os2calls.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/os2calls.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- os2calls.h	2001/02/16 04:15:50	1.6
  +++ os2calls.h	2001/07/24 16:05:24	1.7
  @@ -73,6 +73,8 @@
   extern int (*apr_os2_shutdown)(int, int);
   extern int (*apr_os2_soclose)(int);
   extern int (*apr_os2_writev)(int, struct iovec *, int);
  +extern int (*apr_os2_sendto)(int, const char *, int, int, const struct sockaddr *, int);
  +extern int (*apr_os2_recvfrom)(int, char *, int, int, struct sockaddr *, int *);
   
   #define socket apr_os2_socket
   #define select apr_os2_select
  @@ -91,3 +93,5 @@
   #define shutdown apr_os2_shutdown
   #define soclose apr_os2_soclose
   #define writev apr_os2_writev
  +#define sendto apr_os2_sendto
  +#define recvfrom apr_os2_recvfrom
  
  
  
  1.7       +8 -0      apr/network_io/os2/os2calls.c
  
  Index: os2calls.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/os2calls.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- os2calls.c	2001/02/16 04:16:00	1.6
  +++ os2calls.c	2001/07/24 16:05:24	1.7
  @@ -77,6 +77,8 @@
   int (*apr_os2_shutdown)(int, int) = NULL;
   int (*apr_os2_soclose)(int) = NULL;
   int (*apr_os2_writev)(int, struct iovec *, int) = NULL;
  +int (*apr_os2_sendto)(int, const char *, int, int, const struct sockaddr *, int);
  +int (*apr_os2_recvfrom)(int, char *, int, int, struct sockaddr *, int *);
   
   static HMODULE hSO32DLL;
   
  @@ -142,6 +144,12 @@
   
           if (!rc)
               rc = DosQueryProcAddr(hSO32DLL, 0, "WRITEV", &apr_os2_writev);
  +
  +        if (!rc)
  +            rc = DosQueryProcAddr(hSO32DLL, 0, "SENDTO", &apr_os2_sendto);
  +
  +        if (!rc)
  +            rc = DosQueryProcAddr(hSO32DLL, 0, "RECVFROM", &apr_os2_recvfrom);
   
           if (rc)
               return APR_OS2_STATUS(rc);
  
  
  
  1.2       +88 -2     apr/network_io/os2/sendrecv_udp.c
  
  Index: sendrecv_udp.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sendrecv_udp.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sendrecv_udp.c	2001/03/19 12:35:14	1.1
  +++ sendrecv_udp.c	2001/07/24 16:05:24	1.2
  @@ -59,15 +59,101 @@
   #include "apr_lib.h"
   #include <sys/time.h>
   
  +apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read)
  +{
  +    int waitsock = sock->socketdes;
  +    int srv;
  +
  +    do {
  +      waitsock = sock->socketdes;
  +      srv = select(&waitsock, for_read > 0, !for_read, 0, sock->timeout / 1000);
  +    } while (srv < 0 && sock_errno() == SOCEINTR);
  +  
  +    if (srv == 0) {
  +        return APR_TIMEUP;
  +    }
  +    else if (srv < 0) {
  +        return APR_FROM_OS_ERROR(sock_errno());
  +    }
  +
  +    return APR_SUCCESS;
  +}
  +
  +
  +
   apr_status_t apr_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
                           apr_int32_t flags, const char *buf, apr_size_t *len)
   {
  -    return APR_ENOTIMPL;
  +    ssize_t rv;
  +    int serrno;
  +
  +    do {
  +        rv = sendto(sock->socketdes, buf, (*len), flags, 
  +                    (struct sockaddr*)&where->sa,
  +                    where->salen);
  +    } while (rv == -1 && (serrno = sock_errno()) == EINTR);
  +
  +    if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0)
{
  +        apr_status_t arv = apr_wait_for_io_or_timeout(sock, 0);
  +
  +        if (arv != APR_SUCCESS) {
  +            *len = 0;
  +            return arv;
  +        } else {
  +            do {
  +                rv = sendto(sock->socketdes, buf, *len, flags,
  +                            (const struct sockaddr*)&where->sa,
  +                            where->salen);
  +            } while (rv == -1 && (serrno = sock_errno()) == SOCEINTR);
  +        }
  +    }
  +
  +    if (rv == -1) {
  +        *len = 0;
  +        return APR_FROM_OS_ERROR(serrno);
  +    }
  +
  +    *len = rv;
  +    return APR_SUCCESS;
   }
   
  +
  +
   apr_status_t apr_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
                             apr_int32_t flags, char *buf, 
                             apr_size_t *len)
   {
  -    return APR_ENOTIMPL;
  +    ssize_t rv;
  +    int serrno;
  +
  +    do {
  +        rv = recvfrom(sock->socketdes, buf, (*len), flags, 
  +                      (struct sockaddr*)&from->sa, &from->salen);
  +    } while (rv == -1 && (serrno = sock_errno()) == EINTR);
  +
  +    if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0)
{
  +        apr_status_t arv = apr_wait_for_io_or_timeout(sock, 1);
  +
  +        if (arv != APR_SUCCESS) {
  +            *len = 0;
  +            return arv;
  +        } else {
  +            do {
  +                rv = recvfrom(sock->socketdes, buf, *len, flags,
  +                              (struct sockaddr*)&from->sa, &from->salen);
  +                } while (rv == -1 && (serrno = sock_errno()) == EINTR);
  +        }
  +    }
  +
  +    if (rv == -1) {
  +        (*len) = 0;
  +        return APR_FROM_OS_ERROR(serrno);
  +    }
  +
  +    (*len) = rv;
  +
  +    if (rv == 0 && sock->type == SOCK_STREAM)
  +        return APR_EOF;
  +
  +    return APR_SUCCESS;
   }
  
  
  
  1.46      +7 -6      apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sockets.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- sockets.c	2001/07/24 12:41:37	1.45
  +++ sockets.c	2001/07/24 16:05:24	1.46
  @@ -84,8 +84,9 @@
       }
   }
   
  -static void set_socket_vars(apr_socket_t *sock, int family)
  +static void set_socket_vars(apr_socket_t *sock, int family, int type)
   {
  +    sock->type = type;
       sock->local_addr->family = family;
       sock->local_addr->sa.sin.sin_family = family;
       sock->remote_addr->family = family;
  @@ -151,7 +152,7 @@
           return APR_ENOMEM;
       }
    
  -    (*new)->socketdes = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  +    (*new)->socketdes = socket(AF_INET, type, 0);
   #if APR_HAVE_IPV6
       if ((*new)->socketdes < 0 && ofamily == AF_UNSPEC) {
           family = AF_INET;
  @@ -162,7 +163,7 @@
       if ((*new)->socketdes < 0) {
           return APR_OS2_STATUS(sock_errno());
       }
  -    set_socket_vars(*new, family);
  +    set_socket_vars(*new, family, type);
   
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
  @@ -213,7 +214,7 @@
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
       alloc_socket(new, connection_context);
  -    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
   
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
  @@ -274,7 +275,7 @@
                                 apr_pool_t *cont)
   {
       alloc_socket(apr_sock, cont);
  -    set_socket_vars(*apr_sock, os_sock_info->family);
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type);
       (*apr_sock)->timeout = -1;
       (*apr_sock)->socketdes = *os_sock_info->os_sock;
       if (os_sock_info->local) {
  @@ -304,7 +305,7 @@
       }
       if ((*sock) == NULL) {
           alloc_socket(sock, cont);
  -        set_socket_vars(*sock, AF_INET);
  +        set_socket_vars(*sock, AF_INET, SOCK_STREAM);
       }
       (*sock)->socketdes = *thesock;
       return APR_SUCCESS;
  
  
  

Mime
View raw message