Пример #1
0
void file_cache_free(FILE_CACHE *cache)
{
    BUFFER *buffer;

    acl_htable_delete(__cache_table, cache->path, NULL);

    while (1) {
        buffer = (BUFFER*) acl_fifo_pop(cache->fifo);
        if (buffer == NULL)
            break;
        acl_myfree(buffer->buf);
        acl_myfree(buffer);
    }

    acl_fifo_free(cache->fifo, NULL);
    acl_myfree(cache);
}
Пример #2
0
int acl_xml_node_delete(ACL_XML_NODE *node)
{
    ACL_RING *next;
    ACL_XML_NODE *node_next;
    int   n = 1;

    while ((next = acl_ring_pop_head(&node->children)) != NULL) {
        node_next = acl_ring_to_appl(next, ACL_XML_NODE, node);
        n += acl_xml_node_delete(node_next);
    }

    node->xml->node_cnt--;
    if (node->id != NULL)
        acl_htable_delete(node->xml->id_table, STR(node->id), NULL);
    if (node->xml->node_cache &&
            acl_array_size(node->xml->node_cache) < node->xml->max_cache)
    {
        node->xml->node_cache->push_back(node->xml->node_cache, node);
        acl_ring_detach(&node->node);
    } else
        acl_xml_node_free(node);
    return (n);
}
Пример #3
0
void service_ctx_free(SERVICE_CTX *ctx)
{
	acl_htable_delete(ctx->service->table, ctx->key, NULL);
	acl_myfree(ctx);
}
Пример #4
0
/* DNS查询结果之后的回调函数 */
static void thrpool_nslookup_complete(const DNS_CTX *dns_ctx)
{
	const char *myname = "thrpool_nslookup_complte";
	SERVICE *service = (SERVICE *) dns_ctx->context;
	DNS_RING *list;
	ACL_RING *ring_ptr;
	CLIENT_ENTRY *entry;
	time_t inter, now;

	list = (DNS_RING *) acl_htable_find(service->dns_table,
				dns_ctx->domain_key);
	if (list == NULL) {
		acl_msg_warn(NULL, "%s: domain(%s) not found maybe handled",
			myname, dns_ctx->domain_key);
		return;
	}

	time(&now);
	inter = now - dns_ctx->begin;

	/* 如果查询时间过长,则给出警告信息 */
	if (inter >= 5)
		acl_msg_warn("%s(%d): dns search time=%d, domain(%s)",
			myname, __LINE__, time(NULL) - dns_ctx->begin,
			dns_ctx->domain_key);

	while (1) {
		ring_ptr = acl_ring_pop_head(&list->ring);
		if (ring_ptr == NULL)
			break;

		list->nrefer--;

		entry = ACL_RING_TO_APPL(ring_ptr, CLIENT_ENTRY, dns_entry);

		entry->tm.dns_lookup = now - entry->tm.stamp;
		entry->tm.stamp = now;

		if (dns_ctx->ip_cnt <= 0) {
			acl_msg_error("%s(%d): dns not found domain(%s)",
				myname, __LINE__, dns_ctx->domain_key);
			if (entry->client == NULL)
				acl_msg_fatal("%s(%d): client null",
					__FILE__, __LINE__);

			if (entry->dns_errmsg) {
				/* XXX: 因为此处可能会有两处关闭 client 流的地方:
				 * acl_aio_writen 及 forward_complete,为防止重复
				 * 关闭造成的内存访问非法,需要 * 在第一个可能关闭
				 * 的函数(acl_aio_writen)调用前提升 client 流的
				 * 引用值,并且在该函数返回后再恢复引用值
				 */

				acl_aio_refer(entry->client);
				acl_aio_writen(entry->client, entry->dns_errmsg,
					(int) strlen(entry->dns_errmsg));
				/* 恢复refer值 */
				acl_aio_unrefer(entry->client);
			}

			entry->nslookup_notify_fn(entry, NSLOOKUP_ERR);

			continue;
		}

		if (acl_do_debug(20, 2)) {
			int   i;

			for (i = 0; i < dns_ctx->ip_cnt; i++)
				acl_msg_info("%s(%d): domain(%s), ip%d(%s)",
					myname, __LINE__, dns_ctx->domain_key,
					i, dns_ctx->ip[i]);
		}
		
		/* 将查得的所有DNS结果都拷贝至请求对象中 */
		memcpy(&entry->dns_ctx, dns_ctx, sizeof(entry->dns_ctx));

		/* 下面注释部分被打开,便可以测试连接重试功能:)-- zsx, 2008.2.28
		 * strcpy(proxy_entry->dns_ctx.ip[1], proxy_entry->dns_ctx.ip[0]);
		 * strcpy(proxy_entry->dns_ctx.ip[0], "127.0.0.1");
		 * if (proxy_entry->dns_ctx.ip_cnt < 2)
		 *	proxy_entry->dns_ctx.ip_cnt = 2;
		 */
		entry->ip_idx = 0;
		entry->nslookup_notify_fn(entry, NSLOOKUP_OK);
	}

	acl_htable_delete(service->dns_table, dns_ctx->domain_key, NULL);
	if (list->nrefer <= 0)
		acl_myfree(list);
	else
		acl_msg_fatal("%s(%d): list's nrefer=%d",
			myname, __LINE__, list->nrefer);
}