| 148 | } |
| 149 | |
| 150 | int PhxSQLClientBase::Connect() { |
| 151 | if (!m_poMySQLProp->bConnected) { |
| 152 | int iConnTimeout = GetConfig()->GetConnTimeout(); |
| 153 | int iReadTimeout = GetConfig()->GetReadTimeout(); |
| 154 | SetOption(MYSQL_OPT_CONNECT_TIMEOUT, (const char *) &iConnTimeout); |
| 155 | SetOption(MYSQL_OPT_READ_TIMEOUT, (const char *) &iReadTimeout); |
| 156 | |
| 157 | char *dbname = NULL; |
| 158 | if (m_poMySQLProp->pcDB[0] != '\0') { |
| 159 | dbname = m_poMySQLProp->pcDB; |
| 160 | } |
| 161 | |
| 162 | MySQLEndPoint_t tEndPoint, tPreviousEndPoint; |
| 163 | tEndPoint.m_iPort = 0; |
| 164 | tPreviousEndPoint.m_iPort = 0; |
| 165 | for (int32_t i = 0; i < 3; ++i) { |
| 166 | int ret = m_poDisasterStrategy->GetEndPoint(m_poConfig->GetEndPoints(), tPreviousEndPoint, tEndPoint); |
| 167 | tPreviousEndPoint = tEndPoint; |
| 168 | if (ret != phxsql::OK || tEndPoint.m_sMySQLIP == "" || tEndPoint.m_iPort == 0) { |
| 169 | //do log and monitor here |
| 170 | return phxsql::GET_END_POINT_FAIL; |
| 171 | } |
| 172 | |
| 173 | if (mysql_real_connect(&m_poMySQLProp->connection, tEndPoint.m_sMySQLIP.c_str(), m_poMySQLProp->pcUser, |
| 174 | m_poMySQLProp->pcPass, dbname, tEndPoint.m_iPort, NULL, m_poMySQLProp->iClientFlag) |
| 175 | == NULL) { |
| 176 | m_poDisasterStrategy->ReportEndPoint(tEndPoint, -1, 0); |
| 177 | //do log and monitor here |
| 178 | continue; |
| 179 | } |
| 180 | m_poMySQLProp->tEndPoint = tEndPoint; |
| 181 | m_poMySQLProp->bConnected = true; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | //do log and monitor here |
| 186 | return phxsql::OK; |
| 187 | } |
| 188 | |
| 189 | int PhxSQLClientBase::SetOption(mysql_option option, const char *arg) { |
| 190 | return mysql_options(&m_poMySQLProp->connection, option, arg); |
nothing calls this directly
no test coverage detected