! * \return * \li >= 0: continue, Interval call time (msec) * \li = -1: stop * \li < -1: error */
| 139 | * \li < -1: error |
| 140 | */ |
| 141 | int CChannelSSHTunnel::Process() |
| 142 | { |
| 143 | int nRet = 0; |
| 144 | |
| 145 | if(!m_Channel || !ssh_channel_is_open(m_Channel) |
| 146 | || ssh_channel_is_eof(m_Channel)) { |
| 147 | QString szErr = "The channel is not open"; |
| 148 | qCritical(log) << szErr; |
| 149 | setErrorString(szErr); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | struct timeval timeout = {0, DEFAULT_TIMEOUT}; |
| 154 | ssh_channel channels[2], channel_out[2]; |
| 155 | channels[0] = m_Channel; |
| 156 | channels[1] = nullptr; |
| 157 | |
| 158 | fd_set set; |
| 159 | FD_ZERO(&set); |
| 160 | socket_t fd = SSH_INVALID_SOCKET; |
| 161 | if(m_pEvent) |
| 162 | fd = m_pEvent->GetFd(); |
| 163 | if(SSH_INVALID_SOCKET != fd) |
| 164 | FD_SET(fd, &set); |
| 165 | |
| 166 | //qDebug(log) << "ssh_select:" << fd; |
| 167 | nRet = ssh_select(channels, channel_out, fd + 1, &set, &timeout); |
| 168 | //qDebug(log) << "ssh_select end:" << nRet; |
| 169 | if(EINTR == nRet) |
| 170 | return 0; |
| 171 | |
| 172 | if(SSH_OK != nRet) { |
| 173 | QString szErr; |
| 174 | szErr = "ssh_channel_select failed: " + QString::number(nRet); |
| 175 | szErr += ssh_get_error(m_Session); |
| 176 | qCritical(log) << szErr; |
| 177 | setErrorString(szErr); |
| 178 | return -3; |
| 179 | } |
| 180 | |
| 181 | if(SSH_INVALID_SOCKET != fd && FD_ISSET(fd, &set)) { |
| 182 | //qDebug(log) << "fires event"; |
| 183 | if(m_pEvent) { |
| 184 | nRet = m_pEvent->Reset(); |
| 185 | if(nRet) return -4; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if(!channel_out[0]) { |
| 190 | //qDebug(log) << "The channel is not select"; |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | if(ssh_channel_is_eof(m_Channel)) { |
| 195 | qWarning(log) << "Channel is eof"; |
| 196 | setErrorString(tr("The channel is eof")); |
| 197 | // Stop |
| 198 | return -1; |