Ejemplo n.º 1
0
int main(int argc,char **argv){
	signal(SIGPIPE,SIG_IGN);
	e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]));
	uint32_t size = atoi(argv[3]);
	uint32_t i = 0;
	for( ; i < size; ++i){
		int32_t fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
		easy_noblock(fd,1);
		int32_t ret;
		if(0 == (ret = easy_connect(fd,&server,NULL)))
			on_connected(fd,0,e);
		else if(ret == -EINPROGRESS){
			connector *c = connector_new(fd,e,2000);
			engine_associate(e,c,on_connected);			
		}else{
			close(fd);
			printf("connect to %s %d error\n",argv[1],atoi(argv[2]));
		}
	}
	//engine_regtimer(e,1000,timer_callback,NULL);
	engine_run(e);
	return 0;
}
Ejemplo n.º 2
0
int main(int argc,char **argv){
	test_parse("*2\r");
	test_parse("\n$53\r\nfasdfasdffasdfasdfasdfasdfasdfasfasdffasfsdffasdfadfs\r\n$36\r\nfasfsadfasdfsdafasdfasdfasdfsdafsadf\r\n");

	test_parse("$5\r");
	test_parse("\nhello\r");
	test_parse("\n");

	test_parse(":");
	test_parse("10\r");
	test_parse("\n");

	test_parse("");
	test_parse("+ok haha\r");
	test_parse("\n");				

	char  input[65535];
	char *ptr;

	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,"127.0.0.1",6379);
	redis_client = redis_connect(e,&server,on_disconnect);
	if(!redis_client){
		printf("connect to redis server %s:%u error\n",argv[1],atoi(argv[2]));
		return 0;
	}

	redis_execute(redis_client,"set kenny h\r\nha",cmd_callback,NULL);

	do{
	    ptr = input;	
	    while((*ptr = getchar()) != '\n')
	    	++ptr;
	    *ptr = 0;
	    flag = 1;
	    redis_execute(redis_client,input,cmd_callback,NULL);
	    while(flag && redis_client){
	    	engine_runonce(e,10);
	    };
		if(!redis_client)
			return 0;
	}while(1);
	return 0;
}
Ejemplo n.º 3
0
int main(int argc,char **argv){
	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	if(0 != easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]))){
		printf("invaild address:%s\n",argv[1]);
	}
	int32_t fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
	easy_addr_reuse(fd,1);
	if(0 == easy_bind(fd,&server)){
		dgram_socket_ *udpserver = new_datagram_socket(fd); 
		engine_associate(e,udpserver,datagram_callback);
		datagram_socket_recv(udpserver,(iorequest*)new_request(),IO_POST,NULL);
		engine_regtimer(e,1000,timer_callback,NULL);
		engine_run(e);
	}
	return 0;
}
Ejemplo n.º 4
0
chk_acceptor *chk_listen_tcp_ip4(chk_event_loop *loop,const char *ip,int16_t port,chk_acceptor_cb cb,void *ud) {
	chk_sockaddr  server;
	int32_t       fd,ret;
	chk_acceptor *a = NULL;
	do {
		if(chk_error_ok != easy_sockaddr_ip4(&server,ip,port)) 
			break;
		if(0 > (fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))){
		    CHK_SYSLOG(LOG_ERROR,"socket() failed errno:%d",errno); 			
			break;
		}
		easy_addr_reuse(fd,1);
		if(chk_error_ok == (ret = easy_listen(fd,&server))){
			a = chk_acceptor_new(fd,ud);
			chk_loop_add_handle(loop,(chk_handle*)a,cb);
		}else close(fd);
	}while(0);	
	return a;
}
Ejemplo n.º 5
0
int main(int argc,char **argv) {
	signal(SIGPIPE,SIG_IGN);
	loop = chk_loop_new();
	chk_sockaddr server;
	if(0 != easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]))) {
		printf("invaild address:%s\n",argv[1]);
	}
	int32_t fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	easy_addr_reuse(fd,1);
	if(0 == easy_listen(fd,&server)){
		chk_acceptor *a = chk_acceptor_new(fd,NULL);
		assert(0 == chk_loop_add_handle(loop,(chk_handle*)a,(chk_event_callback)accept_cb));
		chk_loop_addtimer(loop,1000,on_timeout_cb,NULL);
		chk_loop_run(loop);
	}else{
		close(fd);
		printf("server start error\n");
	}	
	return 0;
}
Ejemplo n.º 6
0
int main(int argc,char **argv){

	if(argc < 2){
		printf("useage redis_streass set/get\n");
		exit(0);
	}

	int i;
	int testset = 0;
	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,"127.0.0.1",6379);
	redis_conn *redis_client = redis_connect(e,&server,on_disconnect);
	if(!redis_client){
		printf("connect to redis server %s:%u error\n","127.0.0.1",6379);
		return 0;
	}

	if(argc >= 2 && strcmp(argv[1],"set") == 0)
		testset = 1;
	for(i = 0; i < 1000; ++i){		
		char buff[1024];
		if(!testset){
			//snprintf(buff,1024,"hmget chaid:%d chainfo skills",i + 1);
			int tmp = i + 1;
			redis_execute(redis_client,"hmget chaid:1 chainfo skills",cmd_callback,(void*)tmp);
		}else{
			snprintf(buff,1024,"hmset chaid:%d chainfo %s skills %s",
					 i + 1,"fasfsafasfsaf\rasfasfasdfsadfasdfasdfasfdfasdfasfdasdfasdf",
					 "fasdfasfasdfdsafdsafs\nadfsafa\r\nsdfsadfsadfasdfsadfsdafsdafsadfsdf" 
					);
			redis_execute(redis_client,buff,NULL,NULL);
		}
	}
	engine_regtimer(e,1000,timer_callback,NULL);
	last = systick64();
	engine_run(e);

	return 0;
}