| 273 | } |
| 274 | |
| 275 | int32_t CNetHandler::WaitConnect(uint64_t timeout) |
| 276 | { |
| 277 | CSockLink* conn = (CSockLink*)this->_conn_ptr; |
| 278 | if (NULL == conn) |
| 279 | { |
| 280 | MTLOG_ERROR("get sock link handle failed"); |
| 281 | return RC_MEM_ERROR; |
| 282 | } |
| 283 | |
| 284 | int32_t fd = conn->CreateSock(); |
| 285 | if (fd < 0) |
| 286 | { |
| 287 | MTLOG_ERROR("create sock failed, ret %d[%m]", fd); |
| 288 | return RC_ERR_SOCKET; |
| 289 | } |
| 290 | |
| 291 | if (conn->Connect()) |
| 292 | { |
| 293 | MTLOG_DEBUG("sock conncet ok"); |
| 294 | return RC_SUCCESS; |
| 295 | } |
| 296 | |
| 297 | this->SwitchToConn(); |
| 298 | |
| 299 | MtFrame* mtframe = MtFrame::Instance(); |
| 300 | mtframe->WaitNotify(timeout); |
| 301 | |
| 302 | this->SwitchToIdle(); |
| 303 | |
| 304 | if (_err_no != 0) |
| 305 | { |
| 306 | MTLOG_ERROR("connect get out errno %d", _err_no); |
| 307 | return _err_no; |
| 308 | } |
| 309 | |
| 310 | if (conn->Connected()) |
| 311 | { |
| 312 | MTLOG_DEBUG("connect ok"); |
| 313 | return 0; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | MTLOG_TRACE("connect not ok, maybe timeout"); |
| 318 | return RC_CONNECT_FAIL; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | int32_t CNetHandler::WaitSend(uint64_t timeout) |
| 323 | { |
no test coverage detected