/** * cpool.c * * Copyright (C) 2003 - 2005 Bojan Smojver, Rexursive * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public Licence as published by the Free * Software Foundation; either version 2 of the Licence, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for * more details. * * You should have received a copy of the GNU General Public Licence along * with this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as two special exceptions, Bojan Smojver, Rexursive, gives * permission to: * * 1. Link, both statically and dynamically, the code of this program with * Apache HTTP Server, Apache Portable Runtime and Apache Portable Runtime * Utility Library from Apache Software Foundation (or with modified versions * of the above, that use the same licence - Apache Software Licence 1.1, 2.0 * or any later version), and distribute linked combinations including the * program and the above software from Apache Software Foundation. You must * obey the GNU General Public Licence in all respects for all of the code * used other than Apache HTTP Server, Apache Portable Runtime and Apache * Portable Runtime Utility Library. * * 2. Dynamically link any shared library with this program at run-time, * through the interface of SpinApplication or LoadModule run-time * configuration directives of Apache HTTP Server, as provided by this program * or Apache HTTP Server itself, regardless of licensing terms of those shared * libraries. You must obey the GNU General Public Licence in all respects for * all of the code used other than that of those shared libraries. * * If you modify this file, you may extend these exceptions to your version of * the file, but you are not obligated to do so. If you do not wish to do so, * delete one or both of these exception statements from your version. * */ #include "private.h" rxv_spin_cpool_t *rxv_spin_cpool_create(apr_pool_t *pool){ rxv_spin_cpool_t *cpool; if((cpool=apr_palloc(pool,sizeof(*cpool))) && (cpool->conns=apr_hash_make(pool))){ cpool->pool=pool; return cpool; } return NULL; } rxv_spin_conn_t *rxv_spin_cpool_get(apr_pool_t *pool,rxv_spin_cpool_t *cpool, const char *conninfo){ char *cinfo; apr_size_t clen; if(!(pool && cpool && conninfo)) return NULL; if(!(cinfo=apr_palloc(pool,(clen=strlen(conninfo))+2))) return NULL; *cinfo=RXV_SPIN_CONN_FOREIGN; apr_cpystrn(cinfo+1,conninfo,clen+1); return apr_hash_get(cpool->conns,cinfo,APR_HASH_KEY_STRING); } rxv_spin_conn_t *rxv_spin_cpool_set(rxv_spin_cpool_t *cpool, const char *conninfo,void *conn, apr_status_t (*cleanup)(void *data)){ rxv_spin_conn_t *cn; if(!(cpool && conninfo && conn && cleanup)) return NULL; if(!((cn=apr_pcalloc(cpool->pool,sizeof(*conn))) && (cn->cinfo=apr_palloc(cpool->pool,strlen(conninfo)+2)))) return NULL; cn->type=(RXV_SPIN_CONN_FOREIGN|RXV_SPIN_CONN_POOLED); *cn->cinfo=RXV_SPIN_CONN_FOREIGN; strcpy(cn->cinfo+1,conninfo); cn->conn=conn; cn->cpool=cpool; cn->cleanup=cleanup; apr_hash_set(cpool->conns,cn->cinfo,APR_HASH_KEY_STRING,conn); apr_pool_cleanup_register(cpool->pool,cn,cleanup,cleanup); return cn; } apr_status_t rxv_spin_conn_close(rxv_spin_conn_t *conn){ if(!conn) return APR_EGENERAL; if(RXV_SPIN_CONN_IS_POOLED(conn)) return apr_pool_cleanup_run(conn->cpool->pool,conn,conn->cleanup); else return apr_pool_cleanup_run(conn->pool,conn,conn->cleanup); return APR_SUCCESS; }