Beispiel #1
0
static void per_thread_destroy(struct per_thread_struct **pts)
{
	LINK_LIST_DESTROY(&(*pts)->local_push_q);
	LINK_LIST_DESTROY(&(*pts)->local_pop_q);
	condition_destroy(&(*pts)->cond);
	free(*pts);
	*pts = NULL;
}
Beispiel #2
0
void sche_destroy(sche_t *s)
{
	struct double_link_node *dlnode = NULL;
	while(dlnode = double_link_pop(&(*s)->coros))
	{
		coro_t co = (coro_t)dlnode+sizeof(struct list_node);
		coro_destroy(&co);
	}
	
	LINK_LIST_DESTROY(&((*s)->active_list_1));
	LINK_LIST_DESTROY(&((*s)->active_list_2));
	minheap_destroy(&((*s)->_minheap));
	coro_destroy(&(*s)->co);
	free(*s);
	*s = NULL;
}
Beispiel #3
0
void destroy_mq(mq_t *m)
{
	mutex_destroy(&(*m)->mtx);
	destroy_q_item((*m)->share_list,(*m)->_item_destroyer);//销毁share_list中所有元素
	LINK_LIST_DESTROY(&(*m)->share_list);
	list_node *l = link_list_head((*m)->local_lists);
	while(l)
	{
		struct per_thread_struct *pts = (struct per_thread_struct*)l;
		destroy_q_item(pts->local_push_q,(*m)->_item_destroyer);
		destroy_q_item(pts->local_pop_q,(*m)->_item_destroyer);
		l = l->next;
		per_thread_destroy(&pts);
	}	
	LINK_LIST_DESTROY(&(*m)->local_lists);
	free(*m);
	*m = NULL;		
}
Beispiel #4
0
void destroy_acceptor(acceptor_t *a)
{
	close((*a)->poller_fd);
	list_node *_st = link_list_head((*a)->st_listens);
	while(_st)
	{
		struct st_listen *tmp = (struct st_listen *)_st;
		_st = _st->next;
		ReleaseSocket(tmp->sock);
		free(tmp);
	}
	LINK_LIST_DESTROY(&((*a)->st_listens));		
	free(*a);
	*a = NULL;
}
Beispiel #5
0
int connection_destroy(struct connection** c)
{
	if(!(*c)->recv_overlap.isUsed && !(*c)->send_overlap.isUsed)
	{ 
		wpacket_t w;
		while(w = LINK_LIST_POP(wpacket_t,(*c)->send_list))
			wpacket_destroy(&w);
		LINK_LIST_DESTROY(&(*c)->send_list);
		buffer_release(&(*c)->unpack_buf);
		buffer_release(&(*c)->next_recv_buf);
		free(*c);
		*c = 0;
		return 0;
	}
	return -1;
}
Beispiel #6
0
int connection_destroy(struct connection** c)
{
	if(!(*c)->recv_overlap.isUsed && !(*c)->send_overlap.isUsed)
	{ 
		wpacket_t w;
		while((w = LINK_LIST_POP(wpacket_t,(*c)->send_list))!=NULL)
			wpacket_destroy(&w);
		LINK_LIST_DESTROY(&(*c)->send_list);
		buffer_release(&(*c)->unpack_buf);
		buffer_release(&(*c)->next_recv_buf);
		if((*c)->wheelitem)
			DestroyWheelItem(&((*c)->wheelitem));
		free(*c);
		*c = NULL;
		printf("connection_destroy\n");
		return 0;
	}
	return -1;
}
Beispiel #7
0
void connector_run(connector_t c,uint32_t ms)
{
	int32_t i = 0;
	uint32_t tick,_timeout,_ms;
	int32_t size;
	int32_t total;
	struct pending_connect *pc;
	struct timeval timeout;
	tick = GetSystemMs();
	_timeout = tick + ms;
	
	struct link_list *_l = LINK_LIST_CREATE();
	mutex_lock(c->lock);
	link_list_swap(_l,c->extern_pending_connect);
	mutex_unlock(c->lock);
	while(pc = LINK_LIST_POP(struct pending_connect*,_l))
	{
		if(c->fd_seisize >= FD_SETSIZE)
		{
			pc->call_back(-1,pc->ip,pc->port,pc->ud);
			free(pc);
		}
		else
		{
			FD_SET(pc->real_fd,&c->Set);
			LINK_LIST_PUSH_BACK(c->_pending_connect,pc);
			++c->fd_seisize;
		}
	}
	LINK_LIST_DESTROY(&_l);
	
	do{
		_ms = _timeout - tick;
		timeout.tv_sec = 0;
		timeout.tv_usec = 1000*_ms;
		size = list_size(c->_pending_connect);
		if(size == 0)
			return;
		if((total = select(1024,0,&c->Set,0, &timeout)) >0 )
		{
			for(; i < size; ++i)
			{
				pc = LINK_LIST_POP(struct pending_connect*,c->_pending_connect);
				if(pc)
				{
					if(FD_ISSET(pc->real_fd, &c->Set))
					{
						pc->call_back(pc->sock,pc->ip,pc->port,pc->ud);
						free(pc);
						--c->fd_seisize;
					}
					else
						LINK_LIST_PUSH_BACK(c->_pending_connect,pc);
				}
			}
		}
		FD_ZERO(&c->Set);
		tick = GetSystemMs();
		size = list_size(c->_pending_connect);
		i = 0;
		for(; i < (int32_t)size; ++i)
		{
			pc = LINK_LIST_POP(struct pending_connect*,c->_pending_connect);
			if(tick >= pc->timeout)
			{
				pc->call_back(-1,pc->ip,pc->port,pc->ud);
				free(pc);
				--c->fd_seisize;
			}
			else
			{
				LINK_LIST_PUSH_BACK(c->_pending_connect,pc);
				FD_SET(pc->real_fd,&c->Set);
			}
		}
		tick = GetSystemMs();
	}while(tick < _timeout);
}