Exemplo n.º 1
0
int main(int argc,char **argv)
{
    mutil_thread = 0;
    setup_signal_handler();
    init_clients();
    InitNetSystem();
    ENGINE engine = CreateEngine();
    int csize = atoi(argv[3]);
    int i = 0;
    for(; i < csize; ++i)
        EConnect(engine,argv[1],atoi(argv[2]),(void*)engine,on_connect,1000);
    uint32_t tick,now;
    tick = now = GetSystemMs();
    while(!stop) {
        EngineRun(engine,50);
        sendpacket();
        now = GetSystemMs();
        if(now - tick > 1000)
        {
            printf("ava_interval:%d\n",ava_interval);
            tick = now;
        }
    }
    CleanNetSystem();
    return 0;
}
Exemplo n.º 2
0
int main(int argc,char **argv)
{

	HANDLE engine;
	uint32_t n;
	
	ip = argv[1];
	port = atoi(argv[2]);
	signal(SIGPIPE,SIG_IGN);
	if(InitNetSystem() != 0)
	{
		printf("Init error\n");
		return 0;
	}
	wpacket_allocator = (allocator_t)create_block_obj_allocator(0,sizeof(struct wpacket));	

	uint32_t i = 0;
	//getchar();
	//init_wpacket_pool(100000);
	//init_rpacket_pool(50000);
	//buffer_init_maxbuffer_size(2000);
	//buffer_init_64(2000);
	init_clients();

	engine = CreateEngine();
	thread_run(_Listen,&engine);
	tick = GetSystemMs();
	while(1)
	{
		EngineRun(engine,15);
		now = GetSystemMs();
		if(now - tick > 1000)
		{
			printf("recv:%u,send:%u,s_req:%u\n",packet_recv,packet_send,send_request);
			tick = now;
			packet_recv = 0;
			packet_send = 0;
			send_request = 0;
			s_p = 0;
			iocp_count = 0;
			recv_count = 0;
		}
		/*if(now - last_send_tick > 50)
		{
			//心跳,每50ms集中发一次包
			last_send_tick = now;
			for(i=0; i < MAX_CLIENT; ++i)
			{
				if(clients[i])
				{
					//++send_request;
					connection_send(clients[i],0,0);
				}
			}
		}*/
		
	}
	return 0;
}
Exemplo n.º 3
0
int main(int argc,char **argv)
{
    //msgque_flush_time = 5;
    setup_signal_handler();
    InitNetSystem();

    //共用网络层,两个线程各运行一个echo服务
    wpacket_allocator = new_obj_allocator(sizeof(struct wpacket),8192);
    rpacket_allocator = new_obj_allocator(sizeof(struct rpacket),8192);
    asynnet_t asynet = asynnet_new(2);
    msgdisp_t  disp1 = new_msgdisp(asynet,5,
                                   CB_CONNECT(asynconnect),
                                   CB_CONNECTED(asynconnected),
                                   CB_DISCNT(asyndisconnected),
                                   CB_PROCESSPACKET(asynprocesspacket),
                                   CB_CONNECTFAILED(asynconnectfailed));

    /*msgdisp_t  disp2 = new_msgdisp(asynet,
                                  asynconnect,
                                  asynconnected,
                                  asyndisconnected,
                                  asynprocesspacket,
                                  asynconnectfailed);
    */
    thread_t service1 = create_thread(THREAD_JOINABLE);
    //thread_t service2 = create_thread(THREAD_JOINABLE);

    ip = argv[1];
    port = atoi(argv[2]);

    thread_start_run(service1,service_main,(void*)disp1);
    //sleepms(1000);
    //thread_start_run(service2,service_main,(void*)disp2);

    uint32_t tick,now;
    tick = now = GetSystemMs();
    while(!stop){
        sleepms(1000);
        now = GetSystemMs();
        //if(now - tick > 1000)
        {
            uint32_t elapse = now-tick;
            recvsize = (recvsize/elapse)/1000;
            printf("client_count:%d,recvsize:%d,recvcount:%d\n",client_count,recvsize,recvcount);
            tick = now;
            packet_send_count = 0;
            recvcount = 0;
            recvsize = 0;
        }
    }

    thread_join(service1);
    //thread_join(service2);

    CleanNetSystem();
    return 0;
}
Exemplo n.º 4
0
int main(int argc,char **argv)
{

	HANDLE engine;
	uint32_t n;
	init_system_time(10);
	ip = argv[1];
	port = atoi(argv[2]);
	signal(SIGPIPE,SIG_IGN);
	if(InitNetSystem() != 0)
	{
		printf("Init error\n");
		return 0;
	}
	wpacket_allocator = (allocator_t)create_block_obj_allocator(SINGLE_THREAD,sizeof(struct wpacket));	

	uint32_t i = 0;
	init_clients();

	engine = CreateEngine();
	thread_run(_Listen,&engine);
	tick = GetSystemMs();
	while(1)
	{
		EngineRun(engine,100);
		now = GetSystemMs();
		if(now - tick > 1000)
		{
			printf("recv:%u,send:%u,s_req:%u,total_recv:%u\n",packet_recv,packet_send,send_request,total_bytes_recv/1024/1024);
			tick = now;
			packet_recv = 0;
			packet_send = 0;
			send_request = 0;
			iocp_count = 0;
			total_bytes_recv = 0;
			//printf("w:%d,r:%d,b:%d\n",wpacket_count,rpacket_count,buf_count);
		}
		/*
		if(now - last_send_tick > 10)
		{
			last_send_tick = now;
			for(i=0; i < MAX_CLIENT; ++i)
			{
				if(clients[i])
				{
					connection_send(clients[i],NULL,NULL);
				}
			}
		}*/
		
	}
	return 0;
}
Exemplo n.º 5
0
int main(int argc,char **argv)
{
	setup_signal_handler();
    InitNetSystem();
    struct netservice *tcpclient = new_service();
    tcpclient->connect(tcpclient,"127.0.0.1",8010,(void*)tcpclient,on_connect,10000);
	while(!stop){
        tcpclient->loop(tcpclient,50);
	}
	destroy_service(&tcpclient);
    CleanNetSystem();
    return 0;
}
Exemplo n.º 6
0
int32_t main()
{
	DWORD dwThread;
	HANDLE iocp;
	uint32_t n;

	uint32_t i = 0;
	//getchar();
	init_wpacket_pool(10000000);
	init_rpacket_pool(500000);
	buffer_init_maxbuffer_size(2000);
	buffer_init_64(2000);
	init_clients();
	InitNetSystem();
	iocp = CreateNetEngine(1);

	CreateThread(NULL,0,Listen,&iocp,0,&dwThread);
	tick = GetTickCount();
	while(1)
	{
		RunEngine(iocp,15);
		/*now = GetTickCount();
		if(now - tick > 1000)
		{
			printf("recv:%u,send:%u,s_req:%u,pool_size:%u,bf:%u,sp:%u,iocp:%u\n",packet_recv,packet_send,send_request,wpacket_pool_size(),bf_count,s_p,iocp_count);
			tick = now;
			packet_recv = 0;
			packet_send = 0;
			send_request = 0;
			s_p = 0;
			iocp_count = 0;
		}
		if(now - last_send_tick > 50)
		{
			//心跳,每50ms集中发一次包
			last_send_tick = now;
			for(i=0; i < MAX_CLIENT; ++i)
			{
				if(clients[i])
				{
					++send_request;
					connection_send(clients[i],0,0);
				}
			}
		}*/
	}
	return 0;
}
Exemplo n.º 7
0
int main(int argc,char **argv)
{
    setup_signal_handler();
    InitNetSystem();

    asynnet_t asynet = asynnet_new(3);//3个poller,1个用于监听,1个用于处理客户端连接,1个用于处理服务器连接

    msgdisp_t  disp_to_server = new_msgdisp(asynet,3,
                                            CB_CONNECT(to_server_connect),
                                            CB_CONNECTED(to_server_connected),
                                            CB_PROCESSPACKET(to_server_process));

    msgdisp_t  disp_to_client = new_msgdisp(asynet,2,
                                            CB_CONNECT(to_client_connect),
                                            CB_ASYNPROCESSPACKET(to_client_process));

    thread_t service1 = create_thread(THREAD_JOINABLE);
    thread_t service2 = create_thread(THREAD_JOINABLE);

    to_client_ip = argv[1];
    to_client_port = atoi(argv[2]);


    to_server_ip = argv[3];
    to_server_port = atoi(argv[4]);

    thread_start_run(service1,service_toserver,(void*)disp_to_server);
    sleepms(1000);
    thread_start_run(service2,service_toclient,(void*)disp_to_client);

    while(!stop){
        sleepms(100);
    }

    thread_join(service1);
    thread_join(service2);

    CleanNetSystem();
    return 0;
}
Exemplo n.º 8
0
int main(int argc,char **argv)
{

	HANDLE engine;
	uint32_t n;
	ip = argv[1];
	port = atoi(argv[2]);
	signal(SIGPIPE,SIG_IGN);
	init_system_time(10);
	if(InitNetSystem() != 0)
	{
		printf("Init error\n");
		return 0;
	}
	wpacket_allocator = (allocator_t)create_block_obj_allocator(SINGLE_THREAD,sizeof(struct wpacket));	
	engine = CreateEngine();
	thread_run(_Listen,&engine);
	while(1)
	{
		EngineRun(engine,100);
	}
	return 0;
}
Exemplo n.º 9
0
int main(int argc,char **argv)
{
    mutil_thread = 0;
	setup_signal_handler();
	init_clients();
    InitNetSystem();
    struct netservice *tcpserver = new_service();
	tcpserver->listen(tcpserver,argv[1],atoi(argv[2]),(void*)tcpserver,accept_client);
	uint32_t tick,now;
    tick = now = GetSystemMs();
	while(!stop){
		tcpserver->loop(tcpserver,50);
        now = GetSystemMs();
		if(now - tick > 1000)
		{
			printf("client_count:%d,send_count:%d\n",client_count,(packet_send_count*1000)/(now-tick));
			tick = now;
			packet_send_count = 0;
		}
	}
	destroy_service(&tcpserver);
    CleanNetSystem();
    return 0;
}
Exemplo n.º 10
0
int main(){

	lua_State *L = luaL_newstate();
	luaL_openlibs(L);
	if (luaL_dofile(L,"gateconfig.lua")) {
		const char * error = lua_tostring(L, -1);
		lua_pop(L,1);
		printf("%s\n",error);
		return 0;
	}
		
	luaObject_t gatecfg = GETGLOBAL_OBJECT(L,"gateserver");
	agentcount = GET_OBJ_FIELD(gatecfg,"agentservice_count",int,lua_tonumber);
	release_luaObj(gatecfg);
	
	luaObject_t toclicfg = GETGLOBAL_OBJECT(L,"toclient");
	string_t cliip = new_string(GET_OBJ_FIELD(toclicfg,"ip",const char *,lua_tostring));
	int      cliport = GET_OBJ_FIELD(toclicfg,"port",int,lua_tonumber);
	release_luaObj(toclicfg);
	
	luaObject_t togamecfg = GETGLOBAL_OBJECT(L,"togame");
	g_gameip = new_string(GET_OBJ_FIELD(togamecfg,"ip",const char *,lua_tostring));
	g_gameport = GET_OBJ_FIELD(togamecfg,"port",int,lua_tonumber);
	release_luaObj(togamecfg);
	
	luaObject_t torediscfg = GETGLOBAL_OBJECT(L,"toredis");
	g_redisip = new_string(GET_OBJ_FIELD(torediscfg,"ip",const char *,lua_tostring));
	g_redisport = GET_OBJ_FIELD(torediscfg,"port",int,lua_tonumber);
	release_luaObj(torediscfg);
	
	lua_close(L);
	
	InitNetSystem();
	
	
	//两个poller,一个用于accept,一个用于数据传输
	asynnet_t asynet = asynnet_new(1);
	
	if(start_verifyservice() != 0){
		SYS_LOG(LOG_ERROR,"start verifyservice failed\n");
		return 0;
	}
	
	/*if(start_togame_service(asynet) != 0){
		SYS_LOG(LOG_ERROR,"start togame service failed\n");
		return 0;
	}*/
		
	uint8_t i;
	for(i = 0; i < agentcount; ++i){
		g_agents[i] = new_agentservice(i,asynet);
	}
	
	msgdisp_t listener = new_msgdisp(asynet,1,CB_CONNECT(agent_connect));
	//开启对客户端的监听	
	int32_t err = 0;
	listener->listen(listener,0,to_cstr(cliip),cliport,&err);
	if(err != 0)
	{
		SYS_LOG(LOG_ERROR,"start listen failed:%d\n",err);
		return 0;
	}
	setup_signal_handler();	    
    while(!stop){
        msg_loop(listener,500);
    }
    
	//stop_togame_service();
	stop_verifyservice();
	
	for(i = 0; i < agentcount; ++i){
		stop_agentservice(g_agents[i]);
	}		

	return 0;
}