--- parser3/src/main/pa_sql_driver_manager.C 2001/10/19 12:43:30 1.41 +++ parser3/src/main/pa_sql_driver_manager.C 2001/10/29 08:05:37 1.43 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_sql_driver_manager.C,v 1.41 2001/10/19 12:43:30 parser Exp $ + $Id: pa_sql_driver_manager.C,v 1.43 2001/10/29 08:05:37 paf Exp $ */ #include "pa_sql_driver_manager.h" @@ -13,6 +13,7 @@ #include "pa_exception.h" #include "pa_common.h" #include "pa_threads.h" +#include "pa_stack.h" // globals @@ -31,24 +32,59 @@ public: furl(aurl) { } - /// allocates some bytes on pool - void *malloc(size_t size) { return Pooled::malloc(size); } - /// allocates some bytes clearing them with zeros - void *calloc(size_t size) { return Pooled::calloc(size); } - - /// throw exception - void _throw(const char *comment) { - throw Exception(0, 0, + virtual void *malloc(size_t size) { return Pooled::malloc(size); } + virtual void *calloc(size_t size) { return Pooled::calloc(size); } + + /** + the idea is to #1 jump to C++ some function to main body, where + every function stack frame has exception unwind information + and from there... #2 propagate_exception() + */ + virtual void _throw(const char *comment) { + e=Exception(0, 0, &furl, comment); + + longjmp(mark, 1); + } + virtual void propagate_exception() { + throw e; } private: const String& furl; + Exception e; }; +// helpers + +static void expire_connection(Array::Item *value, void *info) { + SQL_Connection& connection=*static_cast(value); + time_t older_dies=reinterpret_cast(info); + + if(connection.connected() && connection.expired(older_dies)) + connection.disconnect(); +} +static void expire_connections(const Hash::Key& key, Hash::Val *value, void *info) { + Stack& stack=*static_cast(value); + for(int i=0; i<=stack.top_index(); i++) + expire_connection(stack.get(i), info); +} + // SQL_Driver_manager +SQL_Driver_manager::SQL_Driver_manager(Pool& pool) : Pooled(pool), + driver_cache(pool), + connection_cache(pool), + prev_expiration_pass_time(0) { + +} + +SQL_Driver_manager::~SQL_Driver_manager() { + connection_cache.for_each(expire_connections, + reinterpret_cast((time_t)0/*=in past=expire all*/)); +} + /// @param request_url protocol://[driver-dependent] SQL_Connection& SQL_Driver_manager::get_connection(const String& request_url, const String& request_origin, @@ -229,18 +265,6 @@ void SQL_Driver_manager::put_connection_ connections->push(&connection); } -static void expire_connection(Array::Item *value, void *info) { - SQL_Connection& connection=*static_cast(value); - time_t older_dies=reinterpret_cast(info); - - if(connection.connected() && connection.expired(older_dies)) - connection.disconnect(); -} -static void expire_connections(const Hash::Key& key, Hash::Val *value, void *info) { - Stack& stack=*static_cast(value); - for(int i=0; i<=stack.top_index(); i++) - expire_connection(stack.get(i), info); -} void SQL_Driver_manager::maybe_expire_connection_cache() { time_t now=time(0);