| 65 | } |
| 66 | |
| 67 | int IOChannel::TransMsg(int client_fd, int sqlsvr_fd) { |
| 68 | client_fd_ = client_fd; |
| 69 | sqlsvr_fd_ = sqlsvr_fd; |
| 70 | |
| 71 | int ret = GetPeerName(sqlsvr_fd, connect_dest_, connect_port_); |
| 72 | if (ret != 0) { |
| 73 | LOG_ERR("get dest ip port failed, ret %d sqlsvr_fd %d", ret, sqlsvr_fd); |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | // get client_ip_ for FakeClientIPInAuthBuf, forward compatibility |
| 78 | int t_port; |
| 79 | ret = GetPeerName(client_fd, client_ip_, t_port); |
| 80 | if (ret != 0) { |
| 81 | LOG_ERR("get client ip failed, ret %d client_fd %d", ret, client_fd); |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | int byte_size_tot = 0; |
| 86 | for (;;) { |
| 87 | struct pollfd pf[2]; |
| 88 | memset(pf, 0, sizeof(pf)); |
| 89 | pf[0].fd = client_fd; |
| 90 | pf[0].events = (POLLIN | POLLERR | POLLHUP); |
| 91 | pf[1].fd = sqlsvr_fd; |
| 92 | pf[1].events = (POLLIN | POLLERR | POLLHUP); |
| 93 | |
| 94 | uint64_t begin = GetTimestampMS(); |
| 95 | |
| 96 | int return_fd_count = co_poll(co_get_epoll_ct(), pf, 2, 1000); |
| 97 | if (return_fd_count < 0) { |
| 98 | LOG_ERR("poll fd client_fd %d sqlsvr_fd %d failed,ret %d", client_fd, sqlsvr_fd, return_fd_count); |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | uint64_t cost_in_epoll = GetTimestampMS() - begin; |
| 103 | if (cost_in_epoll < 1000 && cost_in_epoll > 30) { |
| 104 | LOG_DEBUG("epollcost2 %llu", cost_in_epoll); |
| 105 | } |
| 106 | |
| 107 | int byte_size = TransMsgDirect(client_fd, sqlsvr_fd, pf, 2); |
| 108 | if (byte_size < 0) { |
| 109 | break; |
| 110 | } |
| 111 | byte_size_tot += byte_size; |
| 112 | ByteFromMysqlClient(byte_size); |
| 113 | |
| 114 | int byte_size2 = TransMsgDirect(sqlsvr_fd, client_fd, pf, 2); |
| 115 | if (byte_size2 < 0) { |
| 116 | break; |
| 117 | } |
| 118 | byte_size_tot += byte_size2; |
| 119 | ByteFromConnectDestSvr(byte_size2); |
| 120 | |
| 121 | if (byte_size || byte_size2) { |
| 122 | MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->Epocost(GetTimestampMS() - begin); |
| 123 | } |
| 124 | } |
no test coverage detected