/* ////////////////////////////////////////////////////////////////////////////////////// * main */ tb_int_t tb_demo_asio_aicpc_main(tb_int_t argc, tb_char_t** argv) { // check tb_assert_and_check_return_val(argv[1], 0); // init tb_aicp_ref_t aicp = tb_null; tb_demo_context_t context = {0}; do { // init aicp aicp = tb_aicp_init(2); tb_assert_and_check_break(aicp); // init data context.data = tb_malloc_bytes(TB_DEMO_SOCK_RECV_MAXN); tb_assert_and_check_break(context.data); // init sock aico context.sock = tb_aico_init(aicp); tb_assert_and_check_break(context.sock); // init addr tb_ipaddr_t addr; if (!tb_ipaddr_set(&addr, "127.0.0.1", 9090, TB_IPADDR_FAMILY_NONE)) break; // open sock aico if (!tb_aico_open_sock_from_type(context.sock, TB_SOCKET_TYPE_TCP, tb_ipaddr_family(&addr))) break; // init file aico context.file = tb_aico_init(aicp); tb_assert_and_check_break(context.file); // open file aico if (!tb_aico_open_file_from_path(context.file, argv[1], TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_BINARY | TB_FILE_MODE_TRUNC)) break; // init conn timeout tb_aico_timeout_set(context.sock, TB_AICO_TIMEOUT_CONN, 10000); // post conn tb_trace_i("conn: .."); if (!tb_aico_conn(context.sock, &addr, tb_demo_sock_conn_func, &context)) break; // loop aicp tb_aicp_loop(aicp); // trace if (tb_mclock() > context.base) tb_trace_i("size: %llu, sped: %llu KB/s", context.size, context.size / (tb_mclock() - context.base)); } while (0); // trace tb_trace_i("end"); // exit aicp if (aicp) tb_aicp_exit(aicp); return 0; }
/* ////////////////////////////////////////////////////////////////////////////////////// * main */ tb_int_t tb_demo_asio_dns_main(tb_int_t argc, tb_char_t** argv) { // check tb_assert_and_check_return_val(argv[1], 0); // done tb_aicp_ref_t aicp = tb_null; tb_aicp_dns_ref_t dns = tb_null; do { // init aicp aicp = tb_aicp_init(2); tb_assert_and_check_break(aicp); // init dns dns = tb_aicp_dns_init(aicp); tb_assert_and_check_break(dns); // sort server tb_dns_server_sort(); // init time tb_hong_t time = tb_mclock(); // trace tb_trace_i("dns: %s: ..", argv[1]); // done dns tb_aicp_dns_done(dns, argv[1], -1, tb_demo_sock_dns_done_func, tb_null); // loop aicp tb_aicp_loop(aicp); // exit time time = tb_mclock() - time; // trace tb_trace_i("dns: %s: time: %lld ms", argv[1], time); } while (0); // trace tb_trace_i("end"); // exit aicp if (aicp) tb_aicp_exit(aicp); return 0; }
/* ////////////////////////////////////////////////////////////////////////////////////// * instance implementation */ static tb_int_t tb_aicp_instance_loop(tb_cpointer_t priv) { // aicp tb_aicp_ref_t aicp = (tb_aicp_ref_t)priv; // trace tb_trace_d("loop: init"); // loop aicp if (aicp) tb_aicp_loop(aicp); // trace tb_trace_d("loop: exit"); // exit return 0; }
/* ////////////////////////////////////////////////////////////////////////////////////// * instance implementation */ static tb_pointer_t tb_aicp_instance_loop(tb_cpointer_t priv) { // aicp tb_aicp_ref_t aicp = (tb_aicp_ref_t)priv; // trace tb_trace_d("loop: init"); // loop aicp if (aicp) tb_aicp_loop(aicp); // trace tb_trace_d("loop: exit"); // exit tb_thread_return(tb_null); return tb_null; }
static tb_int_t tb_demo_loop(tb_cpointer_t priv) { // aicp tb_aicp_ref_t aicp = (tb_aicp_ref_t)priv; tb_size_t self = tb_thread_self(); // trace tb_trace_i("[loop: %lu]: init", self); // loop aicp if (aicp) tb_aicp_loop(aicp); // trace tb_trace_i("[loop: %lu]: exit", self); // exit return 0; }