18,356
社区成员
发帖
与我相关
我的任务
分享
int GetResult2(LIBSSH2_CHANNEL *channel, char *szBuff, int nLen, int nTimeout=2000)
{
ZeroMemory(szBuff, nLen);
LIBSSH2_POLLFD fds;
ZeroMemory(&fds, sizeof(LIBSSH2_POLLFD));
fds.type = LIBSSH2_POLLFD_CHANNEL;
fds.fd.channel = channel;
fds.events = LIBSSH2_POLLFD_POLLIN | LIBSSH2_POLLFD_POLLOUT;
int nRead = 0;
for(int i=0;i<nTimeout/100;i++)
{
int nResult = libssh2_poll(&fds, 1, 100);
if(nResult < 1)
continue;
if(fds.revents & LIBSSH2_POLLFD_POLLIN)
{
int n;
while((n = libssh2_channel_read(channel, szBuff+nRead, nLen-nRead)) == LIBSSH2_ERROR_EAGAIN)
waitsocket();
nRead += n;
}
if(fds.revents & LIBSSH2_POLLFD_POLLOUT)
{
break;
}
}
return nRead;
}