Esempio n. 1
0
static inline void on_write_finish(log_t l,int32_t bytestransfer)
{
	wpacket_t w;
	uint32_t size;
	while(bytestransfer)
	{
		w = LINK_LIST_POP(wpacket_t,l->pending_log);
		assert(w);
		if((uint32_t)bytestransfer >= w->data_size)
		{
			//一个wpacket写完了
			bytestransfer -= w->data_size;
			++log_count;
			wpacket_destroy(&w);
		}
		else
		{
			while(bytestransfer)
			{
				size = w->buf->size - w->begin_pos;
				size = size > (uint32_t)bytestransfer ? (uint32_t)bytestransfer:size;
				bytestransfer -= size;
				w->begin_pos += size;
				w->data_size -= size;
				if(w->begin_pos >= w->buf->size)
				{
					w->begin_pos = 0;
					w->buf = buffer_acquire(w->buf,w->buf->next);
				}
			}
			LINK_LIST_PUSH_FRONT(l->pending_log,w);
		}
	}
}
Esempio n. 2
0
static void  destroy_log(log_t *l)
{
	mutex_lock((*l)->mtx);
	while(!link_list_is_empty((*l)->log_queue))
	{
		wpacket_t w = LINK_LIST_POP(wpacket_t,(*l)->log_queue);
		wpacket_destroy(&w);
	}
	mutex_unlock((*l)->mtx);
	close((*l)->file_descriptor);
	mutex_destroy(&(*l)->mtx);
	destroy_link_list(&(*l)->log_queue);
	destroy_link_list(&(*l)->pending_log);
	free(*l);
	*l = 0;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
static inline void update_send_list(struct connection *c,int32_t bytestransfer)
{
	wpacket_t w;
	uint32_t size;
	while(bytestransfer)
	{
		w = LINK_LIST_POP(wpacket_t,c->send_list);
		assert(w);
		if((uint32_t)bytestransfer >= w->data_size)
		{
			//一个包发完
			bytestransfer -= w->data_size;
			if(w->_packet_send_finish)
				w->_packet_send_finish(c,w);
			else	
				wpacket_destroy(&w);
			++packet_send;
		}
		else
		{
			while(bytestransfer)
			{
				size = w->buf->size - w->begin_pos;
				size = size > (uint32_t)bytestransfer ? (uint32_t)bytestransfer:size;
				bytestransfer -= size;
				w->begin_pos += size;
				w->data_size -= size;
				if(w->begin_pos >= w->buf->size)
				{
					w->begin_pos = 0;
					w->buf = buffer_acquire(w->buf,w->buf->next);
				}
			}
			LINK_LIST_PUSH_FRONT(c->send_list,w);
		}
	}
}