| 101 | } |
| 102 | |
| 103 | int CChannelSSHTerminal::OnProcess(int tm) |
| 104 | { |
| 105 | int nRet = 0; |
| 106 | |
| 107 | m_nBytesAvailable = 0; |
| 108 | if(!m_Channel || !ssh_channel_is_open(m_Channel) |
| 109 | || ssh_channel_is_eof(m_Channel)) { |
| 110 | QString szErr = "The channel is not open"; |
| 111 | qCritical(log) << szErr; |
| 112 | setErrorString(szErr); |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | struct timeval timeout = {0, tm}; |
| 117 | ssh_channel channels[2], channel_out[2]; |
| 118 | channels[0] = m_Channel; |
| 119 | channels[1] = nullptr; |
| 120 | |
| 121 | fd_set set; |
| 122 | FD_ZERO(&set); |
| 123 | socket_t fd = SSH_INVALID_SOCKET; |
| 124 | if(m_pEvent) |
| 125 | fd = m_pEvent->GetFd(); |
| 126 | if(SSH_INVALID_SOCKET != fd) |
| 127 | FD_SET(fd, &set); |
| 128 | |
| 129 | //qDebug(log) << "ssh_select:" << fd; |
| 130 | nRet = ssh_select(channels, channel_out, fd + 1, &set, &timeout); |
| 131 | //qDebug(log) << "ssh_select end:" << nRet; |
| 132 | if(EINTR == nRet) |
| 133 | return 0; |
| 134 | |
| 135 | if(SSH_OK != nRet) { |
| 136 | QString szErr; |
| 137 | szErr = "ssh_channel_select failed: " + QString::number(nRet); |
| 138 | szErr += ssh_get_error(m_Session); |
| 139 | qCritical(log) << szErr; |
| 140 | setErrorString(szErr); |
| 141 | return -3; |
| 142 | } |
| 143 | |
| 144 | if(SSH_INVALID_SOCKET != fd && FD_ISSET(fd, &set)) { |
| 145 | //qDebug(log) << "fires event"; |
| 146 | if(m_pEvent) { |
| 147 | nRet = m_pEvent->Reset(); |
| 148 | if(nRet) return -4; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if(!channel_out[0]) { |
| 153 | //qDebug(log) << "The channel is not select"; |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | if(ssh_channel_is_eof(m_Channel)) { |
| 158 | qWarning(log) << "Channel is eof"; |
| 159 | setErrorString(tr("The channel is eof")); |
| 160 | // Stop |