You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by dr...@apache.org on 2001/03/08 20:58:41 UTC

cvs commit: apr/network_io/unix sendrecv.c

dreid       01/03/08 11:58:41

  Modified:    include  apr_network_io.h
               network_io/unix sendrecv.c
  Log:
  OK, so this commit adds basic UDP support for Unix.  I've had this on
  my To Do list for a while now and I've been feeling guilty which is why
  I'm only posting the Unix code.  I'm pretty sure the code is general enough
  that the other platforms will have no problem in using it, but I can't test
  on those platforms.  I'll do BeOS when I get a spare 5 minutes.
  
  The network code could probably do with a review for common code anyways.
  
  Tested and working with both IPv4 and IPv6 on FreeBSD.
  
  Revision  Changes    Path
  1.99      +21 -0     apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_network_io.h,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- apr_network_io.h	2001/02/16 04:15:46	1.98
  +++ apr_network_io.h	2001/03/08 19:58:35	1.99
  @@ -436,6 +436,27 @@
                                       const struct iovec *vec,
                                       apr_int32_t nvec, apr_size_t *len);
   
  +/**
  + * @param sock The socket to send from
  + * @param where The apr_sockaddr_t describing where to send the data
  + * @param data The data to send
  + * @param len  The length of the data to send
  + */
  +APR_DECLARE(apr_status_t) apr_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
  +                                     apr_int32_t flags, const char *buf, 
  +                                     apr_size_t *len);
  +
  +/**
  + * @param from The apr_sockaddr_t to fill in the recipient info
  + * @param sock The socket to use
  + * @param buf  The buffer to use
  + * @param len  The length of the available buffer
  + */
  +
  +APR_DECLARE(apr_status_t) apr_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
  +                                       apr_int32_t flags, char *buf, 
  +                                       apr_size_t *len);
  + 
   #if APR_HAS_SENDFILE
   
   /**
  
  
  
  1.62      +76 -0     apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- sendrecv.c	2001/02/26 12:41:51	1.61
  +++ sendrecv.c	2001/03/08 19:58:39	1.62
  @@ -162,6 +162,82 @@
       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)
  +{
  +    ssize_t rv;
  +
  +    do {
  +        rv = sendto(sock->socketdes, buf, (*len), flags, 
  +                    (const struct sockaddr*)&where->sa, 
  +                    where->salen);
  +    } while (rv == -1 && errno == EINTR);
  +
  +    if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)
  +        && sock->timeout != 0) {
  +        apr_status_t arv = 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 && errno == EINTR);
  +        }
  +    }
  +    if (rv == -1) {
  +        *len = 0;
  +        return errno;
  +    }
  +    *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)
  +{
  +    ssize_t rv;
  +
  +    if (from == NULL){
  +        return APR_ENOMEM;
  +        /* Not sure if this is correct.  Maybe we should just allocate
  +           the memory??
  +         */
  +    }
  +
  +    do {
  +        rv = recvfrom(sock->socketdes, buf, (*len), flags, 
  +                      (struct sockaddr*)&from->sa, &from->salen);
  +    } while (rv == -1 && errno == EINTR);
  +
  +    if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
  +        sock->timeout != 0) {
  +        apr_status_t arv = 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 && errno == EINTR);
  +        }
  +    }
  +    if (rv == -1) {
  +        (*len) = 0;
  +        return errno;
  +    }
  +
  +    (*len) = rv;
  +    if (rv == 0)
  +        return APR_EOF;
  +
  +    return APR_SUCCESS;
  +}
  +
   #ifdef HAVE_WRITEV
   apr_status_t apr_sendv(apr_socket_t * sock, const struct iovec *vec,
                        apr_int32_t nvec, apr_size_t *len)