apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Stoddard" <b...@wstoddard.com>
Subject Re: [PATCH] APR Socket IOL
Date Thu, 08 Nov 2001 15:37:18 GMT
Forget a new file...

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000-2001 The Apache Software Foundation.  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. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" 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 name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``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 SOFTWARE FOUNDATION 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 Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

#include "networkio.h"
#include "apr_network_io.h"
#include "apr_portable.h"
#include "inherit.h"

/*
 * This file contains the common entry point, on all OSes, into APR for 
 * each apr_socket_* call
 */

/* Forward declarations for the native APR socket API. */
apr_status_t socket_create(apr_socket_t **sock, int family, int type,
                           apr_pool_t *p);
apr_status_t socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how);
apr_status_t socket_close(apr_socket_t *sock);
apr_status_t socket_bind(apr_socket_t *sock, apr_sockaddr_t *sa);
apr_status_t socket_listen(apr_socket_t *sock, apr_int32_t backlog);
apr_status_t socket_accept(apr_socket_t **new_sock, apr_socket_t *sock, apr_pool_t *p);
apr_status_t socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa);
apr_status_t socket_data_get(void **data, const char *key,
                             apr_socket_t *sock);
apr_status_t socket_data_set(apr_socket_t *sock, void *data,
                             const char *key,
                             apr_status_t (*cleanup)(void*));
apr_status_t socket_send(apr_socket_t *sock, const char *buf, apr_size_t *len);
apr_status_t socket_sendv(apr_socket_t *sock, const struct iovec *vec,
                          apr_int32_t nvec, apr_size_t *len);
apr_status_t socket_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
                           apr_int32_t flags, const char *buf, 
                           apr_size_t *len);
apr_status_t socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
                             apr_int32_t flags, char *buf, 
                             apr_size_t *len);
#if APR_HAS_SENDFILE
apr_status_t socket_sendfile(apr_socket_t *sock, apr_file_t *file,
                             apr_hdtr_t *hdtr, apr_off_t *offset,
                             apr_size_t *len, apr_int32_t flags);
#endif /* APR_HAS_SENDFILE */
apr_status_t socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len);
apr_status_t socket_setsocketopt(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on);
apr_status_t socket_getsocketopt(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on);
apr_status_t socket_addr_get(apr_sockaddr_t **sa, apr_interface_e which,
                             apr_socket_t *sock);
apr_status_t socket_poll_socket_add(apr_pollfd_t *aprset, apr_socket_t *sock,
                                    apr_int16_t event);
apr_status_t socket_poll_socket_mask(apr_pollfd_t *aprset, apr_socket_t *sock,
                                     apr_int16_t events);
apr_status_t socket_poll_socket_remove(apr_pollfd_t *aprset, 
                                       apr_socket_t *sock);
apr_status_t socket_poll_revents_get(apr_int16_t *event, apr_socket_t *sock,
                                     apr_pollfd_t *aprset);
#if APR_FILES_AS_SOCKETS
apr_status_t socket_from_file(apr_socket_t **sock, apr_file_t *file);
#endif /* APR_FILES_AS_SOCKETS */
#if APR_HAS_SO_ACCEPTFILTER
apr_status_t socket_accept_filter(apr_socket_t *sock, char *name, char *args);
#endif
void socket_set_inherit(apr_socket_t *sock);
void socket_unset_inherit(apr_socket_t *sock);

/*
 * APR network API 
 */
APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **sock, 
                                            int family, int type,
                                            apr_socket_iol_t *iol,
                                            apr_pool_t *p)
{
    apr_status_t rv;

    if (!iol) {
        return socket_create(sock, family, type, p);
    }
    rv = iol->iol_socket_create(sock, family, type, p);
    if (rv == APR_SUCCESS) {
        (*sock)->iol = iol;
    }
    return rv;
}

APR_DECLARE(apr_status_t) apr_shutdown(apr_socket_t *sock,
                                       apr_shutdown_how_e how)
{
    if (!sock->iol || !sock->iol->iol_socket_shutdown) {
        return socket_shutdown(sock, how);
    }
    return sock->iol->iol_socket_shutdown(sock, how);
}

APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *sock)
{
    if (!sock->iol || !sock->iol->iol_socket_close) {
        return socket_close(sock);
    }
    return sock->iol->iol_socket_close(sock);
}

APR_DECLARE(apr_status_t) apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
{
    if (!sock->iol || !sock->iol->iol_socket_bind) {
        return socket_bind(sock, sa);
    }
    return sock->iol->iol_socket_bind(sock, sa);
}

APR_DECLARE(apr_status_t) apr_listen(apr_socket_t *sock, apr_int32_t backlog)
{
    if (!sock->iol || !sock->iol->iol_socket_listen) {
        return socket_listen(sock, backlog);
    }
    return sock->iol->iol_socket_listen(sock, backlog);
}

APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new_sock, 
                                     apr_socket_t *sock,
                                     apr_pool_t *p)
{
    if (!sock->iol || !sock->iol->iol_socket_accept) {
        return socket_accept(new_sock, sock, p);
    }
    return sock->iol->iol_socket_accept(new_sock, sock, p);
}
APR_DECLARE(apr_status_t) apr_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
{
    if (!sock->iol || !sock->iol->iol_socket_connect) {
        return socket_connect(sock, sa);
    }
    return sock->iol->iol_socket_connect(sock, sa);
}

APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
                                             apr_socket_t *sock)
{
    if (!sock->iol || !sock->iol->iol_socket_data_get) {
        return socket_data_get(data, key, sock);
    }
    return sock->iol->iol_socket_data_get(data, key, sock);
}

APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
                                             const char *key,
                                             apr_status_t (*cleanup)(void*))
{
    if (!sock->iol || !sock->iol->iol_socket_data_set) {
        return socket_data_set(sock, data, key, cleanup);
    }
    return sock->iol->iol_socket_data_set(sock, data, key, cleanup);
}

APR_DECLARE(apr_status_t) apr_send(apr_socket_t *sock, const char *buf, 
                                   apr_size_t *len)
{
    if (!sock->iol || !sock->iol->iol_socket_send) {
        return socket_send(sock, buf, len);
    }
    return sock->iol->iol_socket_send(sock, buf, len);
}

APR_DECLARE(apr_status_t) apr_sendv(apr_socket_t *sock, 
                                    const struct iovec *vec,
                                    apr_int32_t nvec, apr_size_t *len)
{
    if (!sock->iol || !sock->iol->iol_socket_sendv) {
        return socket_sendv(sock, vec, nvec, len);
    }
    return sock->iol->iol_socket_sendv(sock, vec, nvec, len);
}

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)
{
    if (!sock->iol || !sock->iol->iol_socket_sendto) {
        return socket_sendto(sock, where, flags, buf, len);
    }
    return sock->iol->iol_socket_sendto(sock, where, flags, buf, len);
}
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 (!sock->iol || !sock->iol->iol_socket_recvfrom) {
        return socket_recvfrom(from, sock, flags, buf, len);
    }
    return sock->iol->iol_socket_recvfrom(from, sock, flags, buf, len);
}
 
#if APR_HAS_SENDFILE
APR_DECLARE(apr_status_t) apr_sendfile(apr_socket_t *sock, apr_file_t *file,
                                       apr_hdtr_t *hdtr, apr_off_t *offset,
                                       apr_size_t *len, apr_int32_t flags)
{
    if (!sock->iol || !sock->iol->iol_socket_sendfile) {
        return socket_sendfile(sock, file, hdtr, offset, len, flags);
    }
    return sock->iol->iol_socket_sendfile(sock, file, hdtr, offset, len, flags);
}
#endif /* APR_HAS_SENDFILE */

APR_DECLARE(apr_status_t) apr_recv(apr_socket_t *sock, 
                                   char *buf, apr_size_t *len)
{
    if (!sock->iol || !sock->iol->iol_socket_recv) {
        return socket_recv(sock, buf, len);
    }
    return sock->iol->iol_socket_recv(sock, buf, len);
}

APR_DECLARE(apr_status_t) apr_setsocketopt(apr_socket_t *sock,
                                           apr_int32_t opt, apr_int32_t on)
{
    if (!sock->iol || !sock->iol->iol_socket_setsocketopt) {
        return socket_setsocketopt(sock, opt, on);
    }
    return sock->iol->iol_socket_setsocketopt(sock, opt, on);
}
APR_DECLARE(apr_status_t) apr_getsocketopt(apr_socket_t *sock, 
                                           apr_int32_t opt, apr_int32_t *on)
{
    if (!sock->iol || !sock->iol->iol_socket_getsocketopt) {
        return socket_getsocketopt(sock, opt, on);
    }
    return sock->iol->iol_socket_getsocketopt(sock, opt, on);
}

/* XXX: Do we really need this function to be iol'ized */
APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
                                              apr_interface_e which,
                                              apr_socket_t *sock)
{
    if (!sock->iol || !sock->iol->iol_socket_addr_get) {
        return socket_addr_get(sa, which, sock);
    }
    return sock->iol->iol_socket_addr_get(sa, which, sock);
}
/* XXX: Do we really need this function to be iol'ized */
APR_DECLARE(apr_status_t) apr_poll_socket_add(apr_pollfd_t *aprset, 
                                              apr_socket_t *sock,
                                              apr_int16_t event)
{
    if (!sock->iol || !sock->iol->iol_socket_poll_socket_add) {
        return socket_poll_socket_add(aprset, sock, event);
    }
    return sock->iol->iol_socket_poll_socket_add(aprset, sock, event);
}
/* XXX: Do we really need this function to be iol'ized */
APR_DECLARE(apr_status_t) apr_poll_socket_mask(apr_pollfd_t *aprset,
                                               apr_socket_t *sock,
                                               apr_int16_t events)
{
    if (!sock->iol || !sock->iol->iol_socket_poll_socket_mask) {
        return socket_poll_socket_mask(aprset, sock, events);
    }
    return sock->iol->iol_socket_poll_socket_mask(aprset, sock, events);
}
/* XXX: Do we really need this function to be iol'ized */
APR_DECLARE(apr_status_t) apr_poll_socket_remove(apr_pollfd_t *aprset, 
                                                 apr_socket_t *sock)
{
    if (!sock->iol || !sock->iol->iol_socket_poll_socket_remove) {
        return socket_poll_socket_remove(aprset, sock);
    }
    return sock->iol->iol_socket_poll_socket_remove(aprset, sock);
}
/* XXX: Do we really need this function to be iol'ized */
APR_DECLARE(apr_status_t) apr_poll_revents_get(apr_int16_t *event, 
                                               apr_socket_t *sock,
                                               apr_pollfd_t *aprset)
{
    if (!sock->iol || !sock->iol->iol_socket_poll_revents_get) {
        return socket_poll_revents_get(event, sock, aprset);
    }
    return sock->iol->iol_socket_poll_revents_get(event, sock, aprset);
}


#if APR_FILES_AS_SOCKETS
APR_DECLARE(apr_status_t) apr_socket_from_file(apr_socket_t **sock,
                                               apr_file_t *file)
{
    if (!sock->iol || !sock->iol->iol_socket_from_file) {
        return socket_from_file(sock, file);
    }
    return sock->iol->iol_socket_from_file(sock, file);
}
#endif /* APR_FILES_AS_SOCKETS */


#if APR_HAS_SO_ACCEPTFILTER
APR_DECLARE(apr_status_t) apr_socket_accept_filter(apr_socket_t *sock, char *name,
                                      char *args)
{
    if (!sock->iol || !sock->iol->iol_socket_accept_filter) {
        return socket_accept_filter(sock, name, args);
    }
    return sock->iol->iol_socket_accept_filter(sock, name, args);
}
#endif



Mime
View raw message