+
+ return NULL;
+}
+
+static inline STATUS http_persistent_handle_do_acquire(http_persistent_handle_provider *provider, void **handle_ptr TSRMLS_DC)
+{
+ ulong index;
+ http_persistent_handle *handle;
+ http_persistent_handle_list *list;
+
+ if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
+ zend_hash_internal_pointer_end(&list->free);
+ if (HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&list->free, NULL, &index, 0) && SUCCESS == zend_hash_get_current_data(&list->free, (void *) &handle)) {
+ *handle_ptr = handle->ptr;
+ zend_hash_index_del(&list->free, index);
+ } else {
+ *handle_ptr = provider->ctor();
+ }
+
+ if (*handle_ptr) {
+ ++provider->list.used;
+ ++list->used;
+ return SUCCESS;
+ }
+ }
+
+ return FAILURE;
+}
+
+static inline STATUS http_persistent_handle_do_release(http_persistent_handle_provider *provider, void **handle_ptr TSRMLS_DC)
+{
+ http_persistent_handle_list *list;
+
+ if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
+ if (provider->list.used >= HTTP_G->persistent.handles.limit) {
+ provider->dtor(*handle_ptr);
+ } else {
+ http_persistent_handle handle = {*handle_ptr};
+
+ if (SUCCESS != zend_hash_next_index_insert(&list->free, (void *) &handle, sizeof(http_persistent_handle), NULL)) {
+ return FAILURE;
+ }
+ }
+
+ *handle_ptr = NULL;
+ --provider->list.used;
+ --list->used;
+ return SUCCESS;
+ }
+
+ return FAILURE;
+}
+
+static inline STATUS http_persistent_handle_do_accrete(http_persistent_handle_provider *provider, void *old_handle, void **new_handle TSRMLS_DC)
+{
+ http_persistent_handle_list *list;
+
+ if (provider->copy && (*new_handle = provider->copy(old_handle))) {
+ if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
+ ++list->used;
+ }
+ ++provider->list.used;
+ return SUCCESS;
+ }
+ return FAILURE;
+}
+
+static void http_persistent_handles_hash_dtor(void *p)
+{
+ http_persistent_handle_provider *provider = (http_persistent_handle_provider *) p;
+ http_persistent_handle_list **list;
+ HashPosition pos;
+
+ FOREACH_HASH_VAL(pos, &provider->list.free, list) {
+ http_persistent_handle_list_free(list, provider->dtor);
+ }
+
+ zend_hash_destroy(&provider->list.free);