예제 #1
0
int main(int argc, char* argv[])
{
	(void) argc; (void) argv;
	acl::acl_cpp_init();

	int   n = 100;
	if (argc >= 2)
		n = atoi(argv[1]);
	if (n <= 0)
		n = 100;
	ACL_METER_TIME("---------- begin ----------");
	for (int i = 0; i < 0; i++)
		test0(i);
	ACL_METER_TIME("---------- end ----------");

	test1();

	ACL_METER_TIME("---------- begin ----------");
	for (int i = 0; i < 1; i++)
	{
		printf(">>>i: %d\n", i);
		test2();
	}
	ACL_METER_TIME("---------- end ----------");

	printf("Over, enter any key to exit!\n");
	getchar();
	return (0);
}
예제 #2
0
int main(int argc, char* argv[])
{
	(void) argc; (void) argv;
	acl::acl_cpp_init();

	int   n = 1;
	if (argc >= 2)
		n = atoi(argv[1]);
	if (n <= 0)
		n = 100;
	ACL_METER_TIME("---------- begin ----------");
	for (int i = 0; i < 0; i++)
		test0(i);
	ACL_METER_TIME("---------- end ----------");

	// 126 的 SSL 传输时当 HTTP 请求头中的 Host 值为 mail.126.com:443 时其 nginx
	// 会报错,只能是:Host: mail.126.com,土鳖

	test1("mail.126.com", 443, false, true);
	test2("mail.126.com", 443, false, true);
	test2("mail.qq.com", 443, false, true);
	test2("mail.sohu.com", 443, false, true);
	test2("mail.sina.com.cn", 443, false, true);

	printf("Over, enter any key to exit!\n");
	getchar();
	return (0);
}
예제 #3
0
파일: main.c 프로젝트: 1514louluo/acl
static void get_url(const char *url, const char *dump)
{
	ACL_METER_TIME("---begin----");
	if (dump && *dump)
		http_util_dump_url(url, dump);
	else
		http_util_dump_url_to_stream(url, ACL_VSTREAM_OUT);
	ACL_METER_TIME("----end----");
}
예제 #4
0
파일: main.cpp 프로젝트: aaronshang/acl
static void test4(void)
{
	ACL_METER_TIME(">> begin acl::string");
	for (int i = 0; i < 100000; i++)
	{
		test41();
	}
	ACL_METER_TIME(">> end acl::string");
}
예제 #5
0
파일: main.cpp 프로젝트: aaronshang/acl
static void test6(void)
{
	ACL_METER_TIME(">> begin ACL_VSTRING");
	for (int i = 0; i < 100000; i++)
	{
		test61();
	}
	ACL_METER_TIME(">> end ACL_VSTRING");
}
예제 #6
0
파일: main.cpp 프로젝트: aaronshang/acl
static void test7(void)
{
	ACL_METER_TIME(">> begin ACL_VSTRING: acl_vstring_sprintf");
	for (int i = 0; i < 100000; i++)
	{
		test71();
	}
	ACL_METER_TIME(">> end ACL_VSTRING: acl_vstring_sprintf");
}
예제 #7
0
파일: main.cpp 프로젝트: aaronshang/acl
static void test5(void)
{
	ACL_METER_TIME(">> begin std::string");
	for (int i = 0; i < 100000; i++)
	{
		test51();
	}
	ACL_METER_TIME(">> end std::string");
}
예제 #8
0
파일: main.c 프로젝트: 1514louluo/acl
static void test(void)
{
	int   i, n = 0;

	ACL_METER_TIME("---begin---");
	for (i = 0; i < 10000; i++) {
		if (i % 100 == 0)
			n++;
	}
	ACL_METER_TIME("---end---");

	exit (0);
}
예제 #9
0
파일: main.cpp 프로젝트: 1514louluo/acl
static void test_mem(int max)
{
	size_t max_len = 1024 * 1024 * 500, init_len = 4096;
	acl::string buf(init_len);
	buf.set_max(max_len);

	ACL_METER_TIME(">> begin acl::string");

	for (int i = 0; i < max; i++)
	{
		test(buf);
	}

	ACL_METER_TIME(">> end acl::string");
}
예제 #10
0
파일: main.cpp 프로젝트: DayBreakZhang/acl
static void test_json_benchmark(int max)
{
	ACL_JSON *json = acl_json_alloc();

	ACL_METER_TIME("-------------bat begin--------------");

	for (int i = 0; i < max; i++)
	{
		const char* ptr = default_data;
		acl_json_update(json, ptr);
		acl_json_reset(json);
	}

	ACL_METER_TIME("-------------bat end--------------");
	acl_json_free(json);
}
예제 #11
0
파일: main.cpp 프로젝트: jhomble/redis
static void set(const char* addr, int id, int num)
{
    acl::mem_cache client(addr);
    acl::string buf, key;
    int   i;

    client.set_prefix(__key);

    for (i = 0; i < num; i++)
    {
        key.format("key:%d:%d", id, i);
        buf.format("dat:%d, sp( ), tab(\t), eq(=);", i);
        if (client.set(key.c_str(), buf, buf.length(), __timeout) == false)
        {
            printf("SET error: %s\n", client.last_serror());
            break;
        }
        if (i <= 100)
            printf("SET: %s\n", key.c_str());
        if (i % 10000 == 0)
        {
            char tmp[256];
            snprintf(tmp, sizeof(tmp), "SET, i: %d, num: %d, timeout: %d",
                     i, num, (int) __timeout);
            ACL_METER_TIME(tmp);
        }
    }
    client.property_list();
    printf("OVER: total: %d, timeout: %d\n", i, (int) __timeout);
}
예제 #12
0
파일: main.cpp 프로젝트: 1514louluo/acl
static void test_mmap(int max)
{
	const char* filename = "local.map";
	acl::fstream fp;
	if (fp.open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600) == false)
	{
		printf("open %s error %s\r\n", filename, acl::last_serror());
		return;
	}

	size_t max_len = 1024 * 1024 * 500, init_len = 4096;
	acl::string buf(fp.file_handle(), max_len, init_len);

	ACL_METER_TIME(">> begin acl::string");

	for (int i = 0; i < max; i++)
	{
		test(buf);
	}

	ACL_METER_TIME(">> end acl::string");
}
예제 #13
0
파일: main.cpp 프로젝트: 10jschen/acl
static void handle_connection(acl::socket_stream& conn)
{
	acl::string wbuf(__len + 1);
	char* buf = (char*) malloc(__len + 1);

	int   i;

	for (i = 0; i < __len; i++)
		wbuf += 'X';

	struct timeval begin;
	gettimeofday(&begin, NULL);

	for (i = 0; i < __max; i++)
	{
		if (conn.write(wbuf) == -1)
		{
			printf("write to server error\r\n");
			break;
		}

		if (conn.read(buf, __len, true) == -1)
		{
			printf("readline from server error\r\n");
			break;
		}

		if (i <= 1)
		{
			buf[__len] = 0;
			printf("buf: %s\r\n", buf);
		}

		if (i % 1000 == 0)
		{
			char tmp[64];
			snprintf(tmp, sizeof(tmp), "total: %d, curr: %d, len: %d",
				__max, i, __len);
			ACL_METER_TIME(tmp);
		}
	}

	free(buf);

	struct timeval end;
	gettimeofday(&end, NULL);

	double n = util::stamp_sub(&end, &begin);
	printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n",
		__max, n, (i * 1000) /(n > 0 ? n : 1));
}
예제 #14
0
파일: ssl_client.cpp 프로젝트: iYefeng/acl
static bool test(const char* addr, int k, int nloop)
{
	acl::socket_stream client;
	if (client.open(addr, 60, 60) == false)
	{
		std::cout << "connect " << addr << " error!" << std::endl;
		return false;
	}

	acl::polarssl_io* ssl = new acl::polarssl_io(*__ssl_conf, false);
	if (client.setup_hook(ssl) == ssl)
	{
		std::cout << "open ssl " << addr << " error!" << std::endl;
		ssl->destroy();
		return false;
	}

	std::cout << "ssl handshake ok, k: " << k << std::endl;

	for (int i = 0 ; i < nloop; i++)
	{
		char line[1024];
		memset(line, 'x', sizeof(line));
		line[1023] = 0;
		line[1022] = '\n';
		if (client.write(line, strlen(line)) == -1)
		{
			std::cout << "write to " << addr << " error!" << std::endl;
			return false;
		}

		size_t n = sizeof(line);
		if (client.gets(line, &n) == false)
		{
			std::cout << "gets from " << addr << " error!"
				<< acl_last_serror() << std::endl;
			return false;
		}
		if (i < 1 && k < 10)
			std::cout << ">>gets(" << n << "): " << line << std::endl;
		if (i > 0 && i % 1000 == 0)
		{
			char  buf[256];
			snprintf(buf, sizeof(buf), "write count: %d", i);
			ACL_METER_TIME(buf);
		}
	}

	return true;
}
예제 #15
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hspool_update(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx;
	const char* flds = "user_name,user_email";
	const char* bufs[2], *bufs_to[2];
	char  buf[256], buf_to1[256], buf_to2[256];
	const char* addr_rd = "192.168.1.232:9998";
	acl::hspool pool(addr, addr_rd, enable_cache);
	acl::hsclient* client;

	idx = "PRIMARY";
	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "%d", i);

		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}

		snprintf(buf, sizeof(buf), "%d", i);
		bufs[0] = buf;

		snprintf(buf_to1, sizeof(buf_to1), "zsxxsz_%d", i);
		snprintf(buf_to2, sizeof(buf_to2), "*****@*****.**", i);
		bufs_to[0] = buf_to1;
		bufs_to[1] = buf_to2;

		if (client->mod(bufs, 1, bufs_to, 2) == false)
		{
			printf("update error: %s(%d)\n",
				client->get_last_serror(), client->get_error());
			break;
		}

		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "update, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i <= 10)
			printf(">>update, num: %d, hs_id: %d, key: %s\n",
				i, client->get_id(), buf);
		pool.put(client);
	}
}
예제 #16
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hs_update(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx = "PRIMARY";
	const char* flds = "user_name,user_email";
	const char* bufs[2], *bufs_to[2];
	char  buf[256], buf_to1[256], buf_to2[256];
	acl::hsclient client(addr, enable_cache);

	if (client.open_tbl(dbn, tbl, idx, flds) == false)
	{
		printf("connect %s error: %s(%d)\n",
			addr, client.get_last_serror(), client.get_error());
		return;
	}

	printf(">>dbn: %s, tbl: %s, idx: %s, flds: %s\n", dbn, tbl, idx, flds);

	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "%d", i);
		bufs[0] = buf;

		snprintf(buf_to1, sizeof(buf_to1), "zsxxsz_%d", i);
		snprintf(buf_to2, sizeof(buf_to2), "*****@*****.**", i);
		bufs_to[0] = buf_to1;
		bufs_to[1] = buf_to2;

		if (client.mod(bufs, 1, bufs_to, 2) == false)
		{
			printf("update error: %s(%d)\n",
				client.get_last_serror(), client.get_error());
			break;
		}

		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "update, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i > 100)
			continue;
		printf(">> update num: %d ok\n", i);
	}
}
예제 #17
0
파일: main.cpp 프로젝트: aaronshang/acl
static void my_find(const char* db_addr, int num)
{
	const char* db_name = "test", *db_user = "******", *db_pass = "";
	int   db_max = 10, db_ping = 100, db_timeout = 1000;

	dbconn_init(db_addr, db_name, db_user, db_pass, db_max, db_ping, db_timeout);

	ACL_DB_HANDLE* db_handle = dbconn_get();
	ACL_SQL_RES *sql_res;
	ACL_ITER iter;
	char  sql[1024];
	int   error;

	for (int i = 0; i < num; i++)
	{
		snprintf(sql, sizeof(sql), "select user_id, user_name, user_email from user where user_id=%d", i);
		sql_res = acl_dbsql_select(db_handle, sql, &error);
		if (sql_res == NULL)
		{
			printf("over now, i: %d, num: %d\n", i, num);
			break;
		}
		if (i > 10)
		{
			acl_dbsql_free_result(db_handle, sql_res);
			if (i % 10000 == 0)
			{
				snprintf(sql, sizeof(sql), "find, num: %d\n", i);
				ACL_METER_TIME(sql);
			}
			continue;
		}
		printf(">>results:\n");
		acl_foreach(iter, sql_res)
		{
			const char **my_row = (const char**) iter.data;
			printf("\t%s\t%s\t%s\n", my_row[0], my_row[1], my_row[2]);
		}
		acl_dbsql_free_result(db_handle, sql_res);
	}

	dbconn_put(db_handle);
}
예제 #18
0
파일: main.c 프로젝트: 1514louluo/acl
static void run(const char *addr, int n, int keep_alive, int cmd_num)
{
	ACL_VSTREAM *client = NULL;
	int   i, ret, out;
	time_t begin, end;

	time(&begin);

	for (i = 0; i < n; i++) {
		if (client == NULL) {
			client = acl_vstream_connect(addr, ACL_BLOCKING, 0, 0, 0);
			if (client == NULL) {
				printf("connect to %s error %s\n",
					addr, acl_last_serror());
				break;
			}
			acl_tcp_so_linger(ACL_VSTREAM_SOCK(client), 1, 0);
		}
		if ((i > 0 && i % 10000 == 0) || n <= 20)
			out = 1;
		else
			out = 0;
		ret = request(client, cmd_num, out);
		if (ret < 0)
			break;

		if (!keep_alive) {
			acl_vstream_close(client);
			client = NULL;
		}

		if (out) {
			printf(">>>i: %d\n", i);
			ACL_METER_TIME("----------");
		}
	}

	time(&end);
	printf("ok, total: %d, time spent: %ld\n", i, end - begin);
	if (client)
		acl_vstream_close(client);
}
예제 #19
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hs_find(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx = "user_name";
	const char* flds = "user_id,user_name,user_email";
	const char* bufs[2];
	char  buf[256];
	acl::hsclient client(addr, enable_cache);

	if (client.open_tbl(dbn, tbl, idx, flds) == false)
	{
		printf("connect %s error\n", addr);
		return;
	}

	printf(">>dbn: %s, tbl: %s, idx: %s, flds: %s\n", dbn, tbl, idx, flds);

	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "zsxxsz%d", i);
		bufs[0] = buf;

		const std::vector<acl::hsrow*>& rows =
			client.get(bufs, 1, "=", 1, 0);
		if (rows.empty())
		{
			printf("find(%s) error:%s(%d)\n",
				buf, client.get_last_serror(), client.get_error());
			break;
		}

		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "find, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i > 1000)
			continue;
		hs_dump(rows);
	}
}
예제 #20
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hs_find2(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx = "PRIMARY";
	const char* flds = "user_id,user_name,user_email";
	char  buf[256];
	acl::hsclient client(addr, enable_cache);

	if (client.open_tbl(dbn, tbl, idx, flds) == false)
	{
		printf("open %s error: %s\n", addr, client.get_last_serror());
		return;
	}

	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "%d", i);

		const std::vector<acl::hsrow*>& rows =
			client.get(buf, NULL);
		if (rows.empty())
		{
			printf("find(%s) error\n", buf);
			break;
		}


		if (i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "find, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i > 1000)
			continue;

		hs_dump(rows);
	}
}
예제 #21
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hs_insert(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx = "PRIMARY";
	const char* flds = "user_id,user_name,user_email";
	const char* bufs[3];
	char  buf1[256], buf2[256], buf3[256];
	acl::hsclient client(addr, enable_cache);

	if (client.open_tbl(dbn, tbl, idx, flds) == false)
	{
		printf("connect %s error\n", addr);
		return;
	}

	for (int i = 0; i < num; i++)
	{
		snprintf(buf1, sizeof(buf1), "%d", i);
		snprintf(buf2, sizeof(buf2), "zsxxsz%d", i);
		snprintf(buf3, sizeof(buf3), "*****@*****.**", i);
		bufs[0] = buf1;
		bufs[1] = buf2;
		bufs[2] = buf3;
		if (client.add(bufs, 3) == false)
		{
			printf(">>insert error: %d, %s\n", client.get_error(),
				client.get_last_serror());
			break;
		}
		if (i < 10)
			printf(">>insert %s,%s,%s ok\n", buf1, buf2, buf3);
		if (i % 10000 == 0)
		{
			snprintf(buf1, sizeof(buf1), "insert num: %d\n", i);
			ACL_METER_TIME(buf1);
		}
	}
}
예제 #22
0
파일: main.cpp 프로젝트: jhomble/redis
static void del(const char* addr, int id, int num)
{
    acl::mem_cache client(addr);
    acl::string key;
    int   i;

    client.set_prefix(__key);

    for (i = 0; i < num; i++)
    {
        key.format("key:%d:%d", id, i);
        if (client.del(key.c_str()) == false)
            break;
        if (i <= 100)
            printf("DEL: %s\n", key.c_str());
        if (i % 10000 == 0)
        {
            char tmp[256];
            snprintf(tmp, sizeof(tmp), "DEL, i: %d, num: %d", i, num);
            ACL_METER_TIME(tmp);
        }
    }
    printf("OVER: total: %d\n", i);
}
예제 #23
0
void* thread_client::run()
{
	acl::socket_stream conn;

	// 连接远程服务器
	if (conn.open(server_addr_, 10, 10) == false)
	{
		printf("connect %s error %s\r\n", server_addr_.c_str(),
			acl::last_serror());
		return NULL;
	}

	char* data = (char*) acl_mymalloc(length_);
	memset(data, 'X', length_);
	data[length_ - 1] = '\n';

	acl::string buf;

	struct timeval begin;
	gettimeofday(&begin, NULL);

	int   i = 0;
	for (; i < count_; i++)
	{
		// 向服务器写一行数据
		if (conn.write(data, length_) == -1)
		{
			printf("write to %s error %s\r\n",
				server_addr_.c_str(), acl::last_serror());
			break;
		}

		// 从服务器读一行数据
		if (conn.gets(buf) == false)
		{
			printf("gets from %s error %s\r\n",
				server_addr_.c_str(), acl::last_serror());
			break;
		}

		if (i % 1000 == 0)
		{
			buf.format("total: %d, curr: %d", count_, i);
			ACL_METER_TIME(buf.c_str());
		}

		if (keep_alive_)
			continue;

		// 如果采用短连接,则先关闭连接再打开连接
		conn.close();
		if (conn.open(server_addr_.c_str(), 10, 10) == false)
		{
			printf("connect %s error %s\r\n", server_addr_.c_str(),
				acl::last_serror());
			break;
		}
	}

	struct timeval end;
	gettimeofday(&end, NULL);
	double spent = util::stamp_sub(&end, &begin);
	printf("total: %d, curr: %d, spent: %.2f, speed: %.2f\r\n",
		count_, i, spent, (i * 1000) / (spent > 1 ? spent : 1));

	acl_myfree(data);
	return NULL;
}
예제 #24
0
파일: main.cpp 프로젝트: 10jschen/acl
int main(int argc, char *argv[])
{
	ACL_VSTREAM *client;
	const char *addr;
	char  buf[1024];
	int   ret, i = 0;

	if (argc != 2) {
		printf("usage: %s addr\n", argv[0]);
		return (0);
	}

	addr = argv[1];

	while (1) {
		i++;
		client = acl_vstream_connect(addr, ACL_BLOCKING, 0, 0, 4096);
		if (client == NULL) {
			printf("connect %s error(%s)\n", addr, acl_last_serror());
			return (1);
		}

		// get welcome banner
		ACL_METER_TIME("---begin get banner---");
		ret = acl_vstream_gets_nonl(client, buf, sizeof(buf));
		if (ret > 0) {
			printf("gets from %s: %s\n", addr, buf);
		} else {
			printf("gets welcome error\n");
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end get banner---");

		ACL_METER_TIME("---begin helo---");
		if (echo_cmd(client, "helo 126.com") < 0) {
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end helo ---");

		ACL_METER_TIME("---begin mail from---");
		if (echo_cmd(client, "mail from: <*****@*****.**>") < 0) {
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end mail from---");

		ACL_METER_TIME("---begin rcpt to---");
		//if (echo_cmd(client, "rcpt to: <*****@*****.**>") < 0) {
		if (echo_cmd(client, "rcpt to: <*****@*****.**>") < 0) {
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end rcpt to---");
		printf(">>>>----------------- i: %d----------------<<<\n", i);

#if 0
		ACL_METER_TIME("---begin data---");
		if (echo_cmd(client, "data") < 0) {
			acl_vstream_close(client);
			break;
		}

		ACL_METER_TIME("---end data---");

		ACL_METER_TIME("---begin .---");
		if (echo_cmd(client, ".") < 0) {
			acl_vstream_close(client);
			break;
		}

		ACL_METER_TIME("---end .---");

#elif 1
		ACL_METER_TIME("---begin rset---");
		if (echo_cmd(client, "rset") < 0) {
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end rset---");
#else
		ACL_METER_TIME("---begin quit---");
		if (echo_cmd(client, "quit") < 0) {
			acl_vstream_close(client);
			break;
		}
		ACL_METER_TIME("---end quit---");
#endif

		acl_vstream_close(client);
	}

	return (0);
}
예제 #25
0
파일: main.c 프로젝트: LazyPlanet/acl
static void run(const char *local_addr, const char *peer_addr,
	int count, int dlen, int inter, int need_read, int quit)
{
	double spent;
	int   ret, i;
	char  buf[4096], data[4096];
	struct timeval begin, end;
	ACL_VSTREAM *stream = acl_vstream_bind(local_addr, 2);  /* 绑定 UDP 套接口 */

	if (stream == NULL) {
		printf("acl_vstream_bind %s error %s\r\n",
			local_addr, acl_last_serror());
		return;
	}

	if (dlen > (int) sizeof(data) - 1)
		dlen = (int) sizeof(data) - 1;
	for (i = 0; i < dlen; i++)
		data[i] = 'X';
	data[dlen] = 0;

	gettimeofday(&begin, NULL);
	acl_vstream_set_peer(stream, peer_addr);
	ACL_VSTREAM_SET_RWTIMO(stream, 1);

	for (i = 0; i < count; i++) {
		/* 如果服务端的地址是变化的,则应该在写每次前都需要调用
		 * acl_vstream_set_peer
		 */
		ret = acl_vstream_write(stream, data, dlen);
		if (ret == ACL_VSTREAM_EOF) {
			printf("acl_vtream_write error %s\r\n",
				acl_last_serror());
			break;
		}

		if (need_read) {
			ret = acl_vstream_read(stream, buf, sizeof(buf) - 1);
			if (ret == ACL_VSTREAM_EOF) {
				if (errno == ETIMEDOUT) {
					printf("timeout read\r\n");
					continue;
				}
				printf("acl_vstream_read error %s\r\n",
						acl_last_serror());
				break;
			} else
				buf[ret] = 0;
			if (i % inter == 0)
				printf("result: %s\r\n", buf);
		}

		if (i % inter == 0) {
			snprintf(buf, sizeof(buf), "total: %d, curr: %d",
				count, i);
			ACL_METER_TIME(buf);
		}
	}

	gettimeofday(&end, NULL);
	spent = stamp_sub(&end, &begin);

	printf("thread: %lu, total: %d, curr: %d, spent: %.2f, speed: %.2f\r\n",
		(unsigned long) acl_pthread_self(), count, i, spent,
		(i * 1000) / (spent > 1 ? spent : 1));

	printf("thread: %lu, local addr: %s, peer addr: %s\r\n",
		(unsigned long) acl_pthread_self(), ACL_VSTREAM_LOCAL(stream),
		ACL_VSTREAM_PEER(stream));

	if (quit)
		acl_vstream_write(stream, "quit", 4);
	acl_vstream_close(stream);
}
예제 #26
0
파일: main.cpp 프로젝트: aaronshang/acl
static void hspool_find(const char* addr, int num, bool enable_cache)
{
	const char* dbn = "test", *tbl = "user", *idx;
	const char* flds = "user_id,user_name,user_email";
	char  buf[256];
	const char* addr_rd = "192.168.1.232:9998";
	acl::hspool pool(addr, addr_rd, enable_cache);
	acl::hsclient* client;

	idx = "PRIMARY";
	for (int i = 0; i < 10; i++)
	{
		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}
		printf(">>read addr: %s\n", client->get_addr());
		pool.put(client);
	}

	printf("========================================================\n");

	for (int i = 0; i < 10; i++)
	{
		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}
		printf(">>read/write addr: %s\n", client->get_addr());
		pool.put(client);
	}

	//////////////////////////////////////////////////////////////////////

	printf("========================================================\n");
	idx = "PRIMARY";
	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "%d", i);

		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}

		const std::vector<acl::hsrow*>& rows =
			client->get(buf, NULL);
		if (rows.empty())
		{
			printf("find(%s) error\n", buf);
			pool.put(client);
			break;
		}


		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "find, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i <= 10)
		{
			printf(">>hs_id: %d, key: %s ", client->get_id(), buf);
			hs_dump(rows);
		}
		pool.put(client);
	}

	//////////////////////////////////////////////////////////////////////

	printf("========================================================\n");
	idx = "user_name";
	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "zsxxsz%d", i);

		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}

		const std::vector<acl::hsrow*>& rows =
			client->get(buf, NULL);
		if (rows.empty())
		{
			printf("find(%s) error\n", buf);
			pool.put(client);
			break;
		}


		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "find, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i <= 10)
		{
			printf(">>hs_id: %d, key: %s ", client->get_id(), buf);
			hs_dump(rows);
		}
		pool.put(client);
	}

	//////////////////////////////////////////////////////////////////////

	printf("========================================================\n");
	idx = "PRIMARY";
	for (int i = 0; i < num; i++)
	{
		snprintf(buf, sizeof(buf), "%d", i);

		client = pool.peek(dbn, tbl, idx, flds);
		if (client == NULL)
		{
			printf("peek error\n");
			break;
		}

		const std::vector<acl::hsrow*>& rows =
			client->get(buf, NULL);
		if (rows.empty())
		{
			printf("find(%s) error\n", buf);
			pool.put(client);
			break;
		}


		if (i > 0 && i % 10000 == 0)
		{
			snprintf(buf, sizeof(buf), "find, num: %d\n", i);
			ACL_METER_TIME(buf);
		}
		if (i <= 10)
		{
			printf(">>hs_id: %d, key: %s ", client->get_id(), buf);
			hs_dump(rows);
		}
		pool.put(client);
	}
}
예제 #27
0
bool CMsnContactManager::GetAddresses(const CMsnTicket& ticket,
	acl::http_client& client)
{
	acl::string request_body;
	if (BuildGetAddressRequest(ticket, request_body) == false)
		return (false);

	///////////////////////////////////////////////////////////////////////
	// 向 MSN CONTACT 服务器发送请求数据

	// 创建 HTTP 请求头

	acl::http_header header;
	header.set_method(acl::HTTP_METHOD_POST);
	header.set_url(MSN_ADDRESS_BOOK_POST_URL);
	header.set_content_type("text/xml; charset=utf-8");
	header.set_host(MSN_CONTACT_SERVER);
	header.set_content_length(request_body.length());
	header.set_keep_alive(false);
	header.add_entry("SOAPAction", MSN_GET_ADDRESS_SOAP_ACTION);
	header.add_entry("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
	header.add_entry("Accept", "*/*");
	header.add_entry("Cache-Control", "no-cache");
	header.accept_gzip(true);

	// 发送 HTTP 请求头

	acl::string header_buf;
	header.build_request(header_buf);

	// 记录发送头
	logger_format("send header: %s\r\n", header_buf.c_str());

	if (client.get_ostream().write(header_buf) == -1)
	{
		logger_error("write http header error");
		return (false);
	}

	// 发送 HTTP 请求体

	// 记录发送体
	logger_format("send body: %s\r\n", request_body.c_str());

	if (client.get_ostream().write(request_body) == -1)
	{
		logger_error("write http body error");
		return (false);
	}

	///////////////////////////////////////////////////////////////////////
	// 从 MSN CONTACT 服务器读取响应数据

	if (client.read_head() == false)
	{
		logger_error("read http respond head error");
		return (false);
	}

	const HTTP_HDR_RES* hdr_res = client.get_respond_head(NULL);

	if (debug_fpout_)
		http_hdr_fprint(debug_fpout_, &hdr_res->hdr, "GetAddresses read header: ");

	if (hdr_res->hdr.content_length == 0
		|| (hdr_res->hdr.content_length == -1
		&& !hdr_res->hdr.chunked
		&& hdr_res->reply_status > 300
		&& hdr_res->reply_status < 400))
	{
		logger_error("http respond no body");
		http_hdr_print(&hdr_res->hdr, "error");
		return (false);
	}

	/* 读书 HTTP 响应体 */

	acl::string buf;

	ACL_SLICE_POOL* slice = acl_slice_pool_create(16, 50,
					ACL_SLICE_FLAG_GC2 |
					ACL_SLICE_FLAG_RTGC_OFF |
					ACL_SLICE_FLAG_LP64_ALIGN);
	ACL_XML* body = acl_xml_alloc1(slice);
	int   ret;
	while(true)
	{
		ret = client.read_body(buf);
		if (ret < 0)
			break;
		else if (client.body_finish())
			break;
		acl_xml_update(body, buf.c_str());
		logger_format("read body: %s\r\n", buf.c_str());
	}

	//acl_xml_dump(body, ACL_VSTREAM_OUT);
	ParseAddresses(body);

	///////////////////////////////////////////////////////////////////////

	double j = ACL_METER_TIME("---begin---");
	//acl_xml_free(body);
	acl_slice_pool_destroy(slice);
	double k = ACL_METER_TIME("---end---");
	return (true);
}
예제 #28
0
파일: main.c 프로젝트: 10jschen/acl
int main(int argc, char* argv[])
{
	char  buf[8192], filepath[256];
	int   ret, n;
	ACL_VSTREAM* fp;
	ACL_XML* xml;
	struct timeval begin, end;
	double spent;
	int   ch, use_slice = 0, cache_count = 1000;

	filepath[0] = 0;
	while ((ch = getopt(argc, argv, "hmc:f:")) > 0)
	{
		switch (ch)
		{
		case 'h':
			usage(argv[0]);
			return 0;
		case 'm':
			use_slice = 1;
			break;
		case 'c':
			cache_count = atoi(optarg);
			if (cache_count <= 0)
				cache_count = 1000;
			break;
		case 'f':
			snprintf(filepath, sizeof(filepath), "%s", optarg);
			break;
		default:
			break;
		}
	}

	if (use_slice)
		acl_mem_slice_init(8, 1024, 100000,
			ACL_SLICE_FLAG_GC2 |
			ACL_SLICE_FLAG_RTGC_OFF |
			ACL_SLICE_FLAG_LP64_ALIGN);

	if (filepath[0] == 0)
	{
		usage(argv[0]);
		return 1;
	}

	xml = acl_xml_alloc();
	if (cache_count > 0)
		acl_xml_cache(xml, cache_count);

	fp = acl_vstream_fopen(filepath, O_RDONLY, 0600, 8192);
	if (fp == NULL)
	{
		printf("open file %s error %s\r\n",
			filepath, acl_last_serror());
		acl_xml_free(xml);
		return 1;
	}

	gettimeofday(&begin, NULL);
	n = 0;
	ACL_METER_TIME("------begin------");
	while (1)
	{
		ret = acl_vstream_fgets(fp, buf, sizeof(buf) - 1);
		if (ret == ACL_VSTREAM_EOF)
			break;
		buf[ret] = 0;
		acl_xml_parse(xml, buf);
		if (++n % 10000 == 0)
		{
			printf("line: %d\r\n", n);
			ACL_METER_TIME("-------ok------");
		}
		if (n % cache_count == 0)
		{
			printf("reset xml, line: %d\r\n", n);
			acl_xml_reset(xml);
		}
	}

	gettimeofday(&end, NULL);
	spent = stamp_sub(&end, &begin);
	printf("\r\ntotal spent: %0.2f ms\r\n", spent);

	acl_xml_free(xml);
	acl_vstream_fclose(fp);
	return 0;
}
예제 #29
0
파일: main.c 프로젝트: DayBreakZhang/acl
int   main(int argc, char *argv[])
{
	ACL_VSTREAM *client;
	char  addr[64], *buf = NULL, line[128];
	int   n, i, len = 4096, count = 10, inter = 1000;

	snprintf(addr, sizeof(addr), "127.0.0.1:8888");

	while ((n = getopt(argc, argv, "hs:l:n:i:")) > 0) {
		switch (n) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			snprintf(addr, sizeof(addr), "%s", optarg);
			break;
		case 'l':
			len = atoi(optarg);
			break;
		case 'n':
			count = atoi(optarg);
			break;
		case 'i':
			inter = atoi(optarg);
			break;
		default:
			break;
		}
	}

	if (len <= 0) {
		printf("invalid len: %d <= 0\r\n", len);
		return 1;
	}

	/* 连接服务器 */
	client = acl_vstream_connect(addr, ACL_BLOCKING, 10, 10, 4096);
	if (client == NULL) {
		printf("connect %s error %s\r\n", addr, acl_last_serror());
		return 1;
	}
	printf("connect %s ok ...\r\n", addr);

	buf = (char*) acl_mymalloc(len);
	snprintf(buf, len, "%d\r\n", len);

	/* 发送一行数据通知服务端每次数据体的长度 */
	if (acl_vstream_writen(client, buf, strlen(buf)) == ACL_VSTREAM_EOF)
	if (n == ACL_VSTREAM_EOF)
		goto END;

	memset(buf, 'X', len);

	for (i = 0; i < count; i++) {
		n = acl_vstream_writen(client, buf, len);
		if (n == ACL_VSTREAM_EOF) {
			printf("write error %s\r\n", acl_last_serror());
			break;
		}
		if (i % inter == 0) {
			snprintf(line, sizeof(line), "curr: %d, total: %d", i, count);
			ACL_METER_TIME(line);
		}
	}

END:

	if (buf)
		acl_myfree(buf);
	acl_vstream_close(client);

	return 0;
}
예제 #30
0
int https_client::http_request(int count)
{
	acl::http_client* client = new acl::http_client;

	if (connect_server(*client) == false)
	{
		delete client;
		return 0;
	}

	acl::http_header header;
	header.set_url("/")
		.accept_gzip(true)
		.add_entry("Accept-Languge", "zh-cn,en;q=0.5")
		.set_host(domain_.c_str())
		.set_keep_alive(keep_alive_);

	char  buf[8192];
	int   i = 0;

	for (; i < count; i++)
	{
		if (client->write_head(header) == false)
		{
			logger_error("write header error");
			delete client;
			return i;
		}
		if (client->read_head() == false)
		{
			logger_error("read header error");
			delete client;
			return i;
		}

		while (true)
		{
			int ret = client->read_body(buf, sizeof(buf) - 1);
			if (ret < 0)
			{
				logger_error("read body error");
				delete client;
				return i;
			}
			else if (ret == 0)
				break;
#if 0
			buf[ret] = 0;
			printf("%s", buf);
			fflush(stdout);
#endif
		}

		if (!keep_alive_)
		{
			delete client;
			client = new acl::http_client;
			if (connect_server(*client) == false)
			{
				delete client;
				return i;
			}
		}
		else
			client->reset();

		if (i % 1000 == 0)
		{
			acl::string tmp;
			tmp.format("total: %d, curr: %d", count, i);
			ACL_METER_TIME(tmp.c_str());
		}
	}

	delete client;

	return i;
}