MCPcopy Create free account
hub / github.com/Tencent/phxsql / run

Method run

phxsqlproxy/test/testsqlproxy.cpp:42–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 }
41
42 int run() {
43 co_enable_hook_sys();
44
45 MYSQL my;
46 memset(&my, 0, sizeof(my));
47 MYSQL * mysql_connection = mysql_init(&my);
48
49 const int conn_timeout = 200;
50 const int read_timeout = 200;
51 const int write_timeout = read_timeout;
52
53 //mysql_options( mysql_connection, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&conn_timeout );
54 //mysql_options( mysql_connection, MYSQL_OPT_READ_TIMEOUT, (const char *)&read_timeout );
55 //mysql_options( mysql_connection, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&write_timeout );
56
57 //uint64_t s = gt();
58 printf("connect %s:%d\n", config_->GetListeip(), config_->GetListenPort());
59 mysql_connection = mysql_real_connect(mysql_connection, config_->GetListeip(), "root", "", "abc",
60 config_->GetListenPort(), NULL, 0ul);
61 //uint64_t e = gt();
62 //printf("end connect used %llu ms (%s)\n",e - s,strerror( errno ) );
63 printf("conn ret %p\n", mysql_connection);
64
65 if (!mysql_connection) {
66 printf("conn failed\n");
67 yield();
68 }
69 int query_count = 0;
70 while (true) {
71 query_count++;
72 int ret = mysql_ping(mysql_connection);
73 if (ret != 0) {
74 printf("ping %d failed, ret %d\n", query_count, ret);
75 break;
76 }
77 if (query_count % 100 == 0) {
78 printf("ping %d\n", query_count);
79 }
80 poll(0, 0, 1000);
81 }
82 mysql_close(mysql_connection);
83 yield();
84 //for( int i = 0; i < query_count; ++i )
85 //{
86 // //std::string sql_string = "/* phxsql_no_master_required */select * from t1;";
87 // std::string sql_string = "/* */select * from t1;";
88 // //s = gt();
89 // int ret = mysql_real_query( mysql_connection, sql_string.c_str(), sql_string.size() );
90 // //e = gt();
91 // if ( ret == 0 )
92 // {
93 // MYSQL_RES * res = mysql_store_result( mysql_connection );
94
95 // int rows = -1;
96 // if( res )
97 // {
98 // rows = mysql_num_rows( res );
99 // mysql_free_result( res );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected