apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe+gm...@sunstarsys.com>
Subject socket setaside
Date Tue, 24 Aug 2004 14:51:09 GMT

I'd like to be able to transfer an apr_socket_t
from one pool to another, but am having trouble
doing that with the current socket api.  Any
chance of adding something like apr_file_setaside
to the socket api?

I've been trying to coax worker into running a single
thread that multiplexes httpd's lingering close, so I 
knocked up a quick prototype which seems to work for 
that purpose.  It completely ignores local_addr, remote_addr, 
pollset and userdata.  I'm hoping some apr committer might
adopt+fix it, perhaps even using it to create a setaside
function for socket buckets.


APR_DECLARE(apr_status_t) apr_socket_setaside(apr_socket_t **new_sock,
                                              apr_socket_t *old_sock,
                                              apr_pool_t *p)
{
    apr_status_t rv;
    apr_os_sock_t sd;
    apr_os_sock_get(&sd, old_sock);

    alloc_socket(new_sock, p);
    rv = apr_os_sock_put(new_sock, &sd, p);
    (*new_sock)->type     = old_sock->type;
    (*new_sock)->protocol = old_sock->protocol;
    (*new_sock)->timeout  = old_sock->timeout;
    // XXX ignore local_addr, remote_addr,

#ifndef HAVE_POLL
    (*new_sock)->connected = old_sock->connected;
#endif
    (*new_sock)->options = old_sock->options;
    (*new_sock)->inherit = old_sock->inherit;

    old_sock->socketdes = -1;

    apr_pool_cleanup_register((*new_sock)->cntxt, (void *)(*new_sock), 
                              socket_cleanup, socket_cleanup);
    apr_pool_cleanup_kill(old_sock->cntxt, (void *)(old_sock), socket_cleanup);

    return rv;
}


Thanks!
-- 
Joe Schaefer


Mime
View raw message