コード例 #1
0
ファイル: rawpacket.c プロジェクト: weimingtom/chuck
static packet*
rawpacket_clone(packet *p)
{
	rawpacket *raw = (rawpacket*)CALLOC(g_rawpk_allocator,1,sizeof(*raw));
	((packet*)raw)->type = RAWPACKET;
	((packet*)raw)->head = p->head;
	((packet*)raw)->spos = p->spos;
	refobj_inc((refobj*)p->head);
	((packet*)raw)->len_packet = p->len_packet;
	//buffer_writer_init(&raw->writer,p->head,p->len_packet);
	INIT_CONSTROUCTOR(raw);
	return (packet*)raw;	
}
コード例 #2
0
ファイル: rawpacket.c プロジェクト: weimingtom/chuck
//will add reference count of b
rawpacket*
rawpacket_new_by_buffer(bytebuffer *b,uint32_t spos)
{
	rawpacket *raw = (rawpacket*)CALLOC(g_rawpk_allocator,1,sizeof(*raw));
	((packet*)raw)->type = RAWPACKET;
	((packet*)raw)->head = b;
	((packet*)raw)->spos = spos;
	refobj_inc((refobj*)b);
	((packet*)raw)->len_packet = b->size - spos;
	buffer_writer_init(&raw->writer,b,b->size);
	INIT_CONSTROUCTOR(raw);
	return raw;		
}
コード例 #3
0
ファイル: wpacket.c プロジェクト: weimingtom/chuck
packet*
rpacket_makewrite(packet *p)
{
	if(p->type == RPACKET){
		wpacket *w = (wpacket*)CALLOC(g_wpk_allocator,1,sizeof(*w));	
		((packet*)w)->type = WPACKET;
		((packet*)w)->head = p->head;
		refobj_inc((refobj*)p->head);		
		((packet*)w)->spos = p->spos;
		((packet*)w)->len_packet = p->len_packet;		
		INIT_CONSTROUCTOR(w);		
		return (packet*)w;		
	}else
		return NULL;
}
コード例 #4
0
ファイル: rpacket.c プロジェクト: weimingtom/chuck
packet*
wpacket_makeread(packet *p)
{
	if(p->type == WPACKET){
		rpacket *r = rpacket_new(NULL,0);
		((packet*)r)->head = p->head;
		refobj_inc((refobj*)p->head);
		((packet*)r)->spos = p->spos;
		buffer_reader_init(&r->reader,p->head,p->spos + SIZE_HEAD);
		((packet*)r)->len_packet = p->len_packet;
		r->data_remain = p->len_packet - SIZE_HEAD;
		INIT_CONSTROUCTOR(r);		
		return (packet*)r;		
	}
	return NULL;
}
コード例 #5
0
ファイル: rpacket.c プロジェクト: weimingtom/chuck
rpacket*
rpacket_new(bytebuffer *b,uint32_t start_pos)
{
	rpacket *r = (rpacket*)CALLOC(g_rpk_allocator,1,sizeof(*r));
	((packet*)r)->type = RPACKET;
	if(b){
		((packet*)r)->head = b;
		((packet*)r)->spos = start_pos;
		refobj_inc((refobj*)b);
		buffer_reader_init(&r->reader,b,start_pos);
		buffer_read(&r->reader,&r->data_remain,sizeof(r->data_remain));		
		((packet*)r)->len_packet = r->data_remain + SIZE_HEAD;
	}
	INIT_CONSTROUCTOR(r);
	return r;
}
コード例 #6
0
ファイル: rpacket.c プロジェクト: weimingtom/chuck
static packet*
rpacket_clone(packet *p)
{
	rpacket *ori = (rpacket*)p;
	if(p->type == RPACKET){
		rpacket *r = rpacket_new(NULL,0);
		((packet*)r)->head = p->head;
		refobj_inc((refobj*)p->head);
		((packet*)r)->spos = p->spos;
		buffer_reader_init(&r->reader,ori->reader.cur,ori->reader.pos);
		((packet*)r)->len_packet =  p->len_packet;
		r->data_remain = p->len_packet - SIZE_HEAD;
		INIT_CONSTROUCTOR(r);	
		return (packet*)r;
	}
	return NULL;
}
コード例 #7
0
ファイル: luasocket.c プロジェクト: FlowSea/distri.lua
static int luasocket_establish(lua_State *L){
	luasocket_t luasock = (luasocket_t)lua_touserdata(L,1);
	uint32_t    recvbuf_size = lua_tointeger(L,2);
	decoder*    _decoder = (decoder*)lua_touserdata(L,3);
	recvbuf_size = size_of_pow2(recvbuf_size);
    	if(recvbuf_size < 1024) recvbuf_size = 1024;
	connection_t conn = new_connection(luasock->sock,recvbuf_size,_decoder);
	
	if(_decoder && _decoder->mask == mask_http_decode)
		connection_associate(g_engine,conn,on_http_cb,on_disconnected);
	else
		connection_associate(g_engine,conn,on_packet,on_disconnected);
	refobj_inc((refobj*)conn);
	luasock->type = _STREAM_CONN;
	luasock->streamconn = conn;
	connection_setud(conn,luasock,destroy_luasocket);
	return 0;
}