while(1)
{
read_blocked_on_write=0;
const int buff_len = 1024;
char buff[buff_len];
iResult = SSL_read(ssl, buff, buff_len);
int ssl_err = SSL_get_error(ssl, iResult);
if(ssl_err == SSL_ERROR_NONE)
{
if(offset + iResult > recvbuflen - 1)
{
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
MessageBox(hwnd, TEXT("ERROR"), TEXT("Not enough memory!"), MB_OK | MB_ICONERROR);
return 1;
}
memcpy(recvbuf + offset, buff, iResult);
offset += iResult;
if(SSL_pending(ssl))
{
continue;
}
else
{
bFinish = true;
break;
}
}
else if(ssl_err == SSL_ERROR_ZERO_RETURN)
{
bFinish = true;
break;
}
else if(ssl_err == SSL_ERROR_WANT_READ)
{
break;
}
else if(ssl_err == SSL_ERROR_WANT_WRITE)
{
/* We get a WANT_WRITE if we're
trying to rehandshake and we block on
a write during that rehandshake.
We need to wait on the socket to be
writeable but reinitiate the read
when it is */
read_blocked_on_write=1;
break;
}
else
{
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
MessageBox(hwnd, TEXT("ERROR"), TEXT("SSL problem!"), MB_OK | MB_ICONERROR);
return 1;
}
}
答案 0 :(得分:1)
我不是专家,但可能是因为没有什么可读的。您正在读取并移动缓冲区(最多需要几毫秒),然后在该时刻无法读取任何内容时终止。与此同时,您正在处理较低层的网络速度和解密速度。那个时刻没有任何东西可以归还,这一点也不可能。
为什么要检查那里?如果您尝试多路复用或其他什么,不会以非阻塞的方式打开套接字吗?