예제 #1
0
파일: acl_xml.c 프로젝트: DavadDi/acl
static ACL_XML_NODE *xml_iter_prev(ACL_ITER *it, ACL_XML *xml)
{
    ACL_RING *ring_ptr;
    struct ACL_XML_NODE *node, *parent;

    node = (struct ACL_XML_NODE*) it->data;

    /* 先遍历当前结点的子结点 */

    ring_ptr = acl_ring_pred(&node->children);
    if (ring_ptr != &node->children) {
        it->i++;
        it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
        it->data = it->ptr;
        return (it->ptr);
    }

    /* 当前结点的子结点遍历完毕,再遍历当前结点的兄弟结点 */

    parent = acl_xml_node_parent(node);
    ring_ptr = acl_ring_pred(&node->node);
    if (ring_ptr != &parent->children) {
        it->i++;
        it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
        it->data = it->ptr;
        return (it->ptr);
    }

    /* 当前结点的兄弟结点遍历完毕,最后遍历当前结点的父结点的兄弟结点 */

    do {
        if (parent == xml->root)
            break;
        ring_ptr = acl_ring_pred(&parent->node);
        parent = acl_xml_node_parent(parent);
        if (parent == NULL)
            acl_msg_fatal("%s(%d): parent null", __FILE__, __LINE__);

        if (ring_ptr != &parent->children) {
            it->i++;
            it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
            it->data = it->ptr;
            return (it->ptr);
        }
    } while (ring_ptr != &xml->root->children);

    /* 遍历完所有结点 */

    it->ptr = it->data = NULL;
    return (NULL);
}
예제 #2
0
파일: acl_xml.c 프로젝트: DavadDi/acl
int acl_xml_is_complete(ACL_XML *xml, const char *tag)
{
    ACL_RING *ring_ptr;
    ACL_XML_NODE *node;

    /* 获得 xml->root 结点的最后一个一级子结点 */
    ring_ptr = acl_ring_succ(&xml->root->children);

    if (ring_ptr == &xml->root->children) {
        /* 说明没有真实子结点 */
        return (0);
    }

    node = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);

    if ((node->flag & ACL_XML_F_SELF_CL)) {
        /* 说明该结点是自闭合结点 */
        return (1);
    }

    if (node->status != ACL_XML_S_RGT) {
        /* 说明最后一个一级子结点还未处理完毕 */
        return (0);
    }

    if (strcasecmp(STR(node->rtag), tag) == 0) {
        return (1);
    }

    /* 说明 xml 中的最后一个结点与所给标签不匹配 */
    return (0);
}
예제 #3
0
파일: acl_xml.c 프로젝트: DavadDi/acl
int acl_xml_is_closure(ACL_XML *xml)
{
    ACL_RING *ring_ptr;
    ACL_XML_NODE *node;

    /* 获得 xml->root 结点的最后一个一级子结点 */
    ring_ptr = acl_ring_succ(&xml->root->children);

    if (ring_ptr == &xml->root->children) {
        /* 说明没有真实子结点 */
        return (0);
    }

    node = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);

    if ((node->flag & ACL_XML_F_SELF_CL)) {
        /* 说明该结点是自闭合结点 */
        return (1);
    }

    if (node->status == ACL_XML_S_RGT) {
        return (1);
    }

    /* 说明最后一个一级子结点还未处理完毕 */
    return (0);
}
예제 #4
0
파일: events_iocp.c 프로젝트: Tim9Liu9/acl
static void event_set_all(ACL_EVENT *eventp)
{
	EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp;
	ACL_EVENT_FDTABLE *fdp;
	int   i;

	/* 优先处理添加读/写监控任务, 这样可以把中间的 ADD 状态转换成正式状态 */

	eventp->fdcnt_ready = 0;

	if (eventp->present - eventp->last_check >= eventp->check_inter) {
		eventp->last_check = eventp->present;
		event_check_fds(eventp);
	}

	/* 处理任务项 */

	while (1) {
		ACL_RING *r = acl_ring_pop_head(&ev->fdp_delay_list);
		if (r == NULL)
			break;
		fdp = acl_ring_to_appl(r, ACL_EVENT_FDTABLE, delay_entry);

		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) {
			enable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_WRITE)) {
			enable_write(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_READ)) {
			disable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_WRITE)) {
			disable_write(ev, fdp);
		}

		fdp->flag &= ~EVENT_FDTABLE_FLAG_DELAY_OPER;
	}

	for (i = 0; i < eventp->fdcnt; i++) {
		fdp = eventp->fdtabs[i];
		if ((fdp->event_type & (ACL_EVENT_XCPT | ACL_EVENT_RW_TIMEOUT)))
			continue;
		if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)
			&& (fdp->event_read == NULL || fdp->event_read->type == 0))
		{
			enable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)
			&& (fdp->event_write == NULL || fdp->event_write->type == 0))
		{
			enable_write(ev, fdp);
		}
	}
}
예제 #5
0
파일: acl_xml.c 프로젝트: DavadDi/acl
ACL_XML_NODE *acl_xml_node_next(ACL_XML_NODE *node)
{
    ACL_RING *ring_ptr = acl_ring_succ(&node->node);
    ACL_XML_NODE *parent;

    if (ring_ptr == &node->node)
        return (NULL);
    parent = node->parent;
    acl_assert(parent != NULL);
    if (ring_ptr == &parent->children)
        return (NULL);
    return (acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node));
}
예제 #6
0
파일: acl_xml.c 프로젝트: DavadDi/acl
static ACL_XML_NODE *node_iter_next(ACL_ITER *it, ACL_XML_NODE *node)
{
    ACL_RING *ring_ptr;
    struct ACL_XML_NODE *child;

    child = (struct ACL_XML_NODE*) it->data;
    if ((ring_ptr = acl_ring_succ(&child->node)) == &node->children) {
        it->ptr = it->data = NULL;
        return (NULL);
    }
    it->i++;
    it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
    it->data = it->ptr;
    return (it->ptr);
}
예제 #7
0
파일: acl_xml.c 프로젝트: DavadDi/acl
static ACL_XML_NODE *node_iter_head(ACL_ITER *it, ACL_XML_NODE *node)
{
    ACL_RING *ring_ptr;

    it->dlen = -1;
    it->key = NULL;
    it->klen = -1;

    it->i = 0;
    it->size = node->children.len;

    if ((ring_ptr = acl_ring_succ(&node->children)) == &node->children) {
        it->ptr = it->data = NULL;
        return (NULL);
    }
    it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
    it->data = it->ptr;
    return (it->ptr);
}
예제 #8
0
파일: acl_xml.c 프로젝트: DavadDi/acl
static ACL_XML_NODE *xml_iter_tail(ACL_ITER *it, ACL_XML *xml)
{
    ACL_RING *ring_ptr;

    it->dlen = -1;
    it->key = NULL;
    it->klen = -1;

    it->i = 0;
    it->size = xml->node_cnt;

    ring_ptr = acl_ring_pred(&xml->root->children);
    if (ring_ptr== &xml->root->children) {
        it->ptr = it->data = NULL;
        return (NULL);
    }
    it->ptr = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
    it->data = it->ptr;
    return (it->ptr);
}
예제 #9
0
파일: events_kernel.c 프로젝트: Geniuze/acl
static void event_set_all(ACL_EVENT *eventp)
{
	EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp;
	ACL_EVENT_FDTABLE *fdp;

	/* 优先处理添加读/写监控任务, 这样可以把 ADD 中间态转换成正式状态 */

	eventp->ready_cnt = 0;

	if (eventp->present - eventp->last_check >= eventp->check_inter
		|| eventp->read_ready > 0)
	{
		eventp->read_ready = 0;
		eventp->last_check = eventp->present;
		event_check_fds(eventp);
	}

	/* 处理任务项 */

	while (1) {
		ACL_RING *r = acl_ring_pop_head(&ev->fdp_delay_list);
		if (r == NULL)
			break;
		fdp = acl_ring_to_appl(r, ACL_EVENT_FDTABLE, delay_entry);

		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) {
			enable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_WRITE)) {
			enable_write(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_READ)) {
			disable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_WRITE)) {
			disable_write(ev, fdp);
		}

		fdp->flag &= ~EVENT_FDTABLE_FLAG_DELAY_OPER;
	}
}
예제 #10
0
파일: acl_xml.c 프로젝트: DavadDi/acl
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);
}
예제 #11
0
파일: acl_xml.c 프로젝트: DavadDi/acl
void acl_xml_reset(ACL_XML *xml)
{
    const char *myname = "acl_xml_reset";
    ACL_RING *next;
    ACL_XML_NODE *node;

    while ((next = acl_ring_pop_head(&xml->root->children)) != NULL) {
        node = acl_ring_to_appl(next, ACL_XML_NODE, node);
        (void) acl_xml_node_delete(node);
    }

    /* 因为根结点是一个虚结点,所以不需要释放,其会在调用
     * acl_xml_free 时被释放
     */
    acl_ring_detach(&xml->root->node);
    acl_xml_node_reset(xml->root);

    if (xml->node_cnt != 1)
        acl_msg_fatal("%s(%d): node_cnt(%d) invalid",
                      myname, __LINE__, xml->node_cnt);

    acl_htable_reset(xml->id_table, NULL);
    xml->curr_node = NULL;
}
예제 #12
0
파일: acl_xml.c 프로젝트: DavadDi/acl
int acl_xml_free(ACL_XML *xml)
{
    ACL_RING *next;
    ACL_XML_NODE *node;
    int   n = 1;

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

    acl_xml_node_free(xml->root);
    xml->node_cnt--;
    acl_assert(xml->node_cnt == 0);
    acl_htable_free(xml->id_table, NULL);
    if (xml->node_cache != NULL)
        acl_array_free(xml->node_cache,
                       (void (*)(void*)) acl_xml_node_free);
    if (xml->slice)
        acl_slice_pool_free(__FILE__, __LINE__, xml);
    else
        acl_myfree(xml);
    return (n);
}
예제 #13
0
static void event_set_all(ACL_EVENT *eventp)
{
	EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp;
	ACL_EVENT_FDTABLE *fdp;
	int   i;

	/* 优先处理添加读/写监控任务, 这样可以把中间的 ADD 状态转换成正式状态 */

	eventp->fdcnt_ready = 0;

	if (eventp->event_present - ev->last_check >= 1000000) {
		ev->last_check = eventp->event_present;
		for (i = 0; i < eventp->fdcnt; i++) {
			fdp = eventp->fdtabs[i];
			if ((fdp->stream->flag & ACL_VSTREAM_FLAG_BAD) != 0) {
				fdp->stream->flag &= ~ACL_VSTREAM_FLAG_BAD;
				fdp->event_type |= ACL_EVENT_XCPT;
				fdp->fdidx_ready = eventp->fdcnt_ready;
				eventp->fdtabs_ready[eventp->fdcnt_ready++] = fdp;
			} else if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) {
				if (ACL_VSTREAM_BFRD_CNT(fdp->stream) > 0) {
					fdp->stream->sys_read_ready = 0;
					fdp->event_type |= ACL_EVENT_READ;
					fdp->fdidx_ready = eventp->fdcnt_ready;
					eventp->fdtabs_ready[eventp->fdcnt_ready++] = fdp;
				} else if (fdp->r_ttl > 0 &&  eventp->event_present > fdp->r_ttl) {
					fdp->event_type |= ACL_EVENT_RW_TIMEOUT;
					fdp->fdidx_ready = eventp->fdcnt_ready;
					eventp->fdtabs_ready[eventp->fdcnt_ready++] = fdp;
				}
			} else if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) {
				if (fdp->w_ttl > 0 && eventp->event_present > fdp->w_ttl) {
					fdp->event_type |= ACL_EVENT_RW_TIMEOUT;
					fdp->fdidx_ready = eventp->fdcnt_ready;
					eventp->fdtabs_ready[eventp->fdcnt_ready++] = fdp;
				}
			}
		}
	}

	/* 处理任务项 */

	while (1) {
		ACL_RING *r = acl_ring_pop_head(&ev->fdp_delay_list);
		if (r == NULL)
			break;
		fdp = acl_ring_to_appl(r, ACL_EVENT_FDTABLE, delay_entry);

		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) {
			enable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_WRITE)) {
			enable_write(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_READ)) {
			disable_read(ev, fdp);
		}
		if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_WRITE)) {
			disable_write(ev, fdp);
		}

		fdp->flag &= ~EVENT_FDTABLE_FLAG_DELAY_OPER;
	}
}